Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions pkg/commands/git_commands/file_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package git_commands

import (
"fmt"
"path/filepath"
"strconv"
"strings"

Expand Down Expand Up @@ -91,26 +90,6 @@ func (self *FileLoader) GetStatusFiles(opts GetStatusFileOptions) []*models.File

self.setConflictMarkerSizes(files)

// Go through the files to see if any of these files are actually worktrees
// so that we can render them correctly
worktreePaths := linkedWortkreePaths(self.Fs, self.repoPaths.RepoGitDirPath())
for _, file := range files {
for _, worktreePath := range worktreePaths {
absFilePath, err := filepath.Abs(file.Path)
if err != nil {
self.Log.Error(err)
continue
}
if absFilePath == worktreePath {
file.IsWorktree = true
// `git status` renders this worktree as a folder with a trailing slash but we'll represent it as a singular worktree
// If we include the slash, it will be rendered as a folder with a null file inside.
file.Path = strings.TrimSuffix(file.Path, "/")
break
}
}
}

return files
}

Expand Down
40 changes: 0 additions & 40 deletions pkg/commands/git_commands/repo_paths.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package git_commands

import (
ioFs "io/fs"
"os"
"path/filepath"
"strings"
Expand All @@ -10,7 +9,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/env"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/spf13/afero"
)

type RepoPaths struct {
Expand Down Expand Up @@ -302,41 +300,3 @@ func runGitRevParse(gitCmd *oscommands.CmdObj) (string, error) {
}
return strings.TrimSpace(res), nil
}

// Returns the paths of linked worktrees
func linkedWortkreePaths(fs afero.Fs, repoGitDirPath string) []string {
result := []string{}
// For each directory in this path we're going to cat the `gitdir` file and append its contents to our result
// That file points us to the `.git` file in the worktree.
worktreeGitDirsPath := filepath.Join(repoGitDirPath, "worktrees")

// ensure the directory exists
_, err := fs.Stat(worktreeGitDirsPath)
if err != nil {
return result
}

_ = afero.Walk(fs, worktreeGitDirsPath, func(currPath string, info ioFs.FileInfo, err error) error {
if err != nil {
return err
}

if !info.IsDir() {
return nil
}

gitDirPath := filepath.Join(currPath, "gitdir")
gitDirBytes, err := afero.ReadFile(fs, gitDirPath)
if err != nil {
// ignoring error
return nil
}
trimmedGitDir := strings.TrimSpace(string(gitDirBytes))
// removing the .git part
worktreeDir := filepath.Dir(trimmedGitDir)
result = append(result, worktreeDir)
return nil
})

return result
}
25 changes: 25 additions & 0 deletions pkg/gocui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ type Gui struct {
// worker goroutines, so it's atomic.
uiThreadID atomic.Int64

// focused says whether the terminal we're running in has focus, as far as
// its focus reports tell us (see IsFocused). Written by the event loop,
// readable from anywhere, so it's atomic.
focused atomic.Bool

// blockInputCount, when greater than zero, withholds keyboard input from
// the handlers: key events are buffered into bufferedKeyEvents and replayed
// once the count drops back to zero, while mouse clicks and hover are
Expand Down Expand Up @@ -306,6 +311,12 @@ func NewGui(opts NewGuiOpts) (*Gui, error) {
// runs during startup, before we reach MainLoop.
g.uiThreadID.Store(goid.Get())

// Assume we start out focused: a terminal that supports focus reports sends
// one for the state it is already in when we turn reporting on in MainLoop,
// and passing that on as a change would have the app react to a change that
// never happened.
g.focused.Store(true)

return g, nil
}

Expand Down Expand Up @@ -2009,7 +2020,21 @@ func (g *Gui) execKeybinding(v *View, kb *keybinding) error {
return nil
}

// IsFocused reports whether the terminal we're running in has focus. Terminals
// that don't report focus at all leave this true for good.
func (g *Gui) IsFocused() bool {
return g.focused.Load()
}

func (g *Gui) onFocus(ev *GocuiEvent) error {
// Terminals report their focus state when we turn focus reporting on, and
// some report it again when their window is activated, so only pass on the
// reports that actually change it.
if ev.Focused == g.focused.Load() {
return nil
}
g.focused.Store(ev.Focused)

if g.focusHandler != nil {
return g.focusHandler(ev.Focused)
}
Expand Down
Loading
Loading