diff options
22 files changed, 80 insertions, 1 deletions
diff --git a/pkg/commands/git_commands/working_tree.go b/pkg/commands/git_commands/working_tree.go index 8fd1fb177..9c02d4300 100644 --- a/pkg/commands/git_commands/working_tree.go +++ b/pkg/commands/git_commands/working_tree.go @@ -241,7 +241,7 @@ func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain if cached { cachedArg = " --cached" } - if !node.GetIsTracked() && !node.GetHasStagedChanges() && !cached { + if !node.GetIsTracked() && !node.GetHasStagedChanges() && !cached && node.GetIsFile() { trackedArg = "--no-index -- /dev/null" } if plain { diff --git a/pkg/commands/models/file.go b/pkg/commands/models/file.go index eeb540def..dbe015cf1 100644 --- a/pkg/commands/models/file.go +++ b/pkg/commands/models/file.go @@ -29,6 +29,7 @@ type IFile interface { GetIsTracked() bool GetPath() string GetPreviousPath() string + GetIsFile() bool } func (f *File) IsRename() bool { @@ -92,6 +93,10 @@ func (f *File) GetPreviousPath() string { return f.PreviousName } +func (f *File) GetIsFile() bool { + return true +} + type StatusFields struct { HasStagedChanges bool HasUnstagedChanges bool diff --git a/pkg/gui/filetree/file_node.go b/pkg/gui/filetree/file_node.go index 2ff707113..abfdbafe6 100644 --- a/pkg/gui/filetree/file_node.go +++ b/pkg/gui/filetree/file_node.go @@ -42,6 +42,10 @@ func (self *FileNode) GetIsTracked() bool { return self.SomeFile(func(file *models.File) bool { return file.Tracked }) } +func (self *FileNode) GetIsFile() bool { + return self.IsFile() +} + func (self *FileNode) GetPreviousPath() string { if self.File == nil { return "" diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index 1d8182edb..95b601783 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -45,6 +45,15 @@ func (s *Shell) CreateFile(path string, content string) *Shell { return s } +func (s *Shell) CreateDir(path string) *Shell { + fullPath := filepath.Join(s.dir, path) + if err := os.MkdirAll(fullPath, 0o755); err != nil { + panic(fmt.Sprintf("error creating directory: %s\n%s", fullPath, err)) + } + + return s +} + func (s *Shell) UpdateFile(path string, content string) *Shell { fullPath := filepath.Join(s.dir, path) err := os.WriteFile(fullPath, []byte(content), 0o644) diff --git a/pkg/integration/tests/file/dir_with_untracked_file.go b/pkg/integration/tests/file/dir_with_untracked_file.go new file mode 100644 index 000000000..c67745c65 --- /dev/null +++ b/pkg/integration/tests/file/dir_with_untracked_file.go @@ -0,0 +1,32 @@ +package file + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var DirWithUntrackedFile = NewIntegrationTest(NewIntegrationTestArgs{ + // notably, we currently _don't_ actually see the untracked file in the diff. Not sure how to get around that. + Description: "When selecting a directory that contains an untracked file, we should not get an error", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) { + config.UserConfig.Gui.ShowFileTree = true + }, + SetupRepo: func(shell *Shell) { + shell.CreateDir("dir") + shell.CreateFile("dir/file", "foo") + shell.GitAddAll() + shell.Commit("first commit") + shell.CreateFile("dir/untracked", "bar") + shell.UpdateFile("dir/file", "baz") + }, + Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { + assert.CommitCount(1) + + assert.MatchMainViewContent(NotContains("error: Could not access")) + // we show baz because it's a modified file but we don't show bar because it's untracked + // (though it would be cool if we could show that too) + assert.MatchMainViewContent(Contains("baz")) + }, +}) diff --git a/pkg/integration/tests/tests.go b/pkg/integration/tests/tests.go index e26836b59..0765c8600 100644 --- a/pkg/integration/tests/tests.go +++ b/pkg/integration/tests/tests.go @@ -15,6 +15,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/integration/tests/cherry_pick" "github.com/jesseduffield/lazygit/pkg/integration/tests/commit" "github.com/jesseduffield/lazygit/pkg/integration/tests/custom_commands" + "github.com/jesseduffield/lazygit/pkg/integration/tests/file" "github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase" "github.com/jesseduffield/lazygit/pkg/integration/tests/stash" "github.com/jesseduffield/lazygit/pkg/utils" @@ -43,6 +44,7 @@ var tests = []*components.IntegrationTest{ stash.Stash, stash.StashIncludingUntrackedFiles, stash.Rename, + file.DirWithUntrackedFile, } func GetTests() []*components.IntegrationTest { diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/COMMIT_EDITMSG b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/COMMIT_EDITMSG new file mode 100644 index 000000000..5ec586d22 --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/COMMIT_EDITMSG @@ -0,0 +1 @@ +first commit diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/FETCH_HEAD b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/FETCH_HEAD new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/FETCH_HEAD diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/HEAD b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/HEAD new file mode 100644 index 000000000..cb089cd89 --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/config b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/config new file mode 100644 index 000000000..8a748ce32 --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/config @@ -0,0 +1,12 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true + precomposeunicode = true +[user] + email = CI@example.com + name = CI +[commit] + gpgSign = false diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/description b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/description new file mode 100644 index 000000000..498b267a8 --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/index b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/index Binary files differnew file mode 100644 index 000000000..486f8bab9 --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/index diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/info/exclude b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/info/exclude new file mode 100644 index 000000000..8e9f2071f --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/info/exclude @@ -0,0 +1,7 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ +.DS_Store diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/logs/HEAD b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/logs/HEAD new file mode 100644 index 000000000..5a93ac9cc --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/logs/HEAD @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 763788c33660f53eecaecce8dae27c34e647ac57 CI <CI@example.com> 1668129994 +1100 commit (initial): first commit diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/logs/refs/heads/master b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/logs/refs/heads/master new file mode 100644 index 000000000..5a93ac9cc --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/logs/refs/heads/master @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 763788c33660f53eecaecce8dae27c34e647ac57 CI <CI@example.com> 1668129994 +1100 commit (initial): first commit diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/objects/19/102815663d23f8b75a47e7a01965dcdc96468c b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/objects/19/102815663d23f8b75a47e7a01965dcdc96468c Binary files differnew file mode 100644 index 000000000..280a426b7 --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/objects/19/102815663d23f8b75a47e7a01965dcdc96468c diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/objects/76/3788c33660f53eecaecce8dae27c34e647ac57 b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/objects/76/3788c33660f53eecaecce8dae27c34e647ac57 Binary files differnew file mode 100644 index 000000000..e7ef1eb70 --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/objects/76/3788c33660f53eecaecce8dae27c34e647ac57 diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/objects/87/a5800c820f9b267ff243860bceb24b04af76a2 b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/objects/87/a5800c820f9b267ff243860bceb24b04af76a2 Binary files differnew file mode 100644 index 000000000..115dcca46 --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/objects/87/a5800c820f9b267ff243860bceb24b04af76a2 diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/objects/a9/63b9597d0f4f0b9995472e5eff3622b136a4b5 b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/objects/a9/63b9597d0f4f0b9995472e5eff3622b136a4b5 Binary files differnew file mode 100644 index 000000000..ba6b1afcd --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/objects/a9/63b9597d0f4f0b9995472e5eff3622b136a4b5 diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/refs/heads/master b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/refs/heads/master new file mode 100644 index 000000000..65f930952 --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/.git_keep/refs/heads/master @@ -0,0 +1 @@ +763788c33660f53eecaecce8dae27c34e647ac57 diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/dir/file b/test/integration_new/file/dir_with_untracked_file/expected/repo/dir/file new file mode 100644 index 000000000..3f9538666 --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/dir/file @@ -0,0 +1 @@ +baz
\ No newline at end of file diff --git a/test/integration_new/file/dir_with_untracked_file/expected/repo/dir/untracked b/test/integration_new/file/dir_with_untracked_file/expected/repo/dir/untracked new file mode 100644 index 000000000..ba0e162e1 --- /dev/null +++ b/test/integration_new/file/dir_with_untracked_file/expected/repo/dir/untracked @@ -0,0 +1 @@ +bar
\ No newline at end of file |