Skip to content

Commit

Permalink
Fix the "Add to .git/info/exclude" command in submodules or worktrees
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaller committed Mar 28, 2024
1 parent de52a68 commit 93251db
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pkg/commands/git_commands/working_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package git_commands
import (
"fmt"
"os"
"path"

"github.com/go-errors/errors"
"github.com/jesseduffield/lazygit/pkg/commands/models"
Expand Down Expand Up @@ -232,7 +233,8 @@ func (self *WorkingTreeCommands) Ignore(filename string) error {

// Exclude adds a file to the .git/info/exclude for the repo
func (self *WorkingTreeCommands) Exclude(filename string) error {
return self.os.AppendLineToFile(".git/info/exclude", filename)
excludeFile := path.Join(self.repoPaths.repoGitDirPath, "info", "exclude")
return self.os.AppendLineToFile(excludeFile, filename)
}

// WorktreeFileDiff returns the diff of a file
Expand Down
7 changes: 1 addition & 6 deletions pkg/integration/tests/worktree/exclude_file_in_worktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ var ExcludeFileInWorktree = NewIntegrationTest(NewIntegrationTestArgs{
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("Ignore or exclude file")).Select(Contains("Add to .git/info/exclude")).Confirm()
}).
/* EXPECTED:
IsEmpty()

t.FileSystem().FileContent("../repo/.git/info/exclude", Contains("toExclude"))
ACTUAL: */
Tap(func() {
t.ExpectPopup().Alert().Title(Equals("Error")).Content(Contains("open .git/info/exclude: not a directory"))
})
t.FileSystem().FileContent("../repo/.git/info/exclude", Contains("toExclude"))
},
})

0 comments on commit 93251db

Please sign in to comment.