Fix the "Add to .git/info/exclude" command in submodules or worktrees

This commit is contained in:
Stefan Haller 2024-03-25 14:41:51 +01:00
parent de52a68b53
commit 93251db67e
2 changed files with 4 additions and 7 deletions

View file

@ -3,6 +3,7 @@ package git_commands
import (
"fmt"
"os"
"path"
"github.com/go-errors/errors"
"github.com/jesseduffield/lazygit/pkg/commands/models"
@ -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

View file

@ -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"))
},
})