mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-06 22:33:07 +02:00
Add test that demonstrates problem with showing filtered history of file with renames
The test shows that selecting a commit before the rename shows an empty diff, and selecting the rename itself shows an added file rather than a rename.
This commit is contained in:
@ -235,6 +235,10 @@ func (self *Shell) DeleteFileAndAdd(fileName string) *Shell {
|
||||
GitAdd(fileName)
|
||||
}
|
||||
|
||||
func (self *Shell) RenameFileInGit(oldName string, newName string) *Shell {
|
||||
return self.RunCommand([]string{"git", "mv", oldName, newName})
|
||||
}
|
||||
|
||||
// creates commits 01, 02, 03, ..., n with a new file in each
|
||||
// The reason for padding with zeroes is so that it's easier to do string
|
||||
// matches on the commit messages when there are many of them
|
||||
|
@ -0,0 +1,128 @@
|
||||
package filter_by_path
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||
)
|
||||
|
||||
var ShowDiffsForRenamedFile = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Description: "Filter commits by file path for a file that was renamed, and verify that it shows the diffs correctly",
|
||||
ExtraCmdArgs: []string{},
|
||||
Skip: false,
|
||||
SetupConfig: func(config *config.AppConfig) {
|
||||
},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.CreateFileAndAdd("oldFile", "a\nb\nc\n")
|
||||
shell.Commit("add old file")
|
||||
shell.UpdateFileAndAdd("oldFile", "x\nb\nc\n")
|
||||
shell.Commit("update old file")
|
||||
shell.CreateFileAndAdd("unrelatedFile", "content of unrelated file\n")
|
||||
shell.Commit("add unrelated file")
|
||||
shell.RenameFileInGit("oldFile", "newFile")
|
||||
shell.Commit("rename file")
|
||||
shell.UpdateFileAndAdd("newFile", "y\nb\nc\n")
|
||||
shell.UpdateFileAndAdd("unrelatedFile", "updated content of unrelated file\n")
|
||||
shell.Commit("update both files")
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
t.Views().Commits().
|
||||
Focus().
|
||||
Lines(
|
||||
Contains("update both files").IsSelected(),
|
||||
Contains("rename file"),
|
||||
Contains("add unrelated file"),
|
||||
Contains("update old file"),
|
||||
Contains("add old file"),
|
||||
).
|
||||
PressEnter()
|
||||
|
||||
t.Views().CommitFiles().
|
||||
IsFocused().
|
||||
Lines(
|
||||
Equals("▼ /").IsSelected(),
|
||||
Equals(" M newFile"),
|
||||
Equals(" M unrelatedFile"),
|
||||
).
|
||||
SelectNextItem().
|
||||
Press(keys.Universal.FilteringMenu)
|
||||
|
||||
t.ExpectPopup().Menu().Title(Equals("Filtering")).
|
||||
Select(Contains("Filter by 'newFile'")).Confirm()
|
||||
|
||||
t.Views().Commits().
|
||||
IsFocused().
|
||||
Lines(
|
||||
Contains("update both files").IsSelected(),
|
||||
Contains("rename file"),
|
||||
Contains("update old file"),
|
||||
Contains("add old file"),
|
||||
)
|
||||
|
||||
t.Views().Main().ContainsLines(
|
||||
Equals(" update both files"),
|
||||
Equals("---"),
|
||||
Equals(" newFile | 2 +-"),
|
||||
Equals(" 1 file changed, 1 insertion(+), 1 deletion(-)"),
|
||||
Equals(""),
|
||||
Equals("diff --git a/newFile b/newFile"),
|
||||
Contains("index"),
|
||||
Equals("--- a/newFile"),
|
||||
Equals("+++ b/newFile"),
|
||||
Equals("@@ -1,3 +1,3 @@"),
|
||||
Equals("-x"),
|
||||
Equals("+y"),
|
||||
Equals(" b"),
|
||||
Equals(" c"),
|
||||
)
|
||||
|
||||
t.Views().Commits().SelectNextItem()
|
||||
|
||||
t.Views().Main().ContainsLines(
|
||||
Equals(" rename file"),
|
||||
Equals("---"),
|
||||
/* EXPECTED:
|
||||
Equals(" oldFile => newFile | 0"),
|
||||
Equals(" 1 file changed, 0 insertions(+), 0 deletions(-)"),
|
||||
Equals(""),
|
||||
Equals("diff --git a/oldFile b/newFile"),
|
||||
Equals("similarity index 100%"),
|
||||
Equals("rename from oldFile"),
|
||||
Equals("rename to newFile"),
|
||||
ACTUAL: */
|
||||
Equals(" newFile | 3 +++"),
|
||||
Equals(" 1 file changed, 3 insertions(+)"),
|
||||
Equals(""),
|
||||
Equals("diff --git a/newFile b/newFile"),
|
||||
Equals("new file mode 100644"),
|
||||
Contains("index"),
|
||||
Equals("--- /dev/null"),
|
||||
Equals("+++ b/newFile"),
|
||||
Equals("@@ -0,0 +1,3 @@"),
|
||||
Equals("+x"),
|
||||
Equals("+b"),
|
||||
Equals("+c"),
|
||||
)
|
||||
|
||||
t.Views().Commits().SelectNextItem()
|
||||
|
||||
/* EXPECTED:
|
||||
t.Views().Main().ContainsLines(
|
||||
Equals(" update old file"),
|
||||
Equals("---"),
|
||||
Equals(" oldFile | 2 +-"),
|
||||
Equals(" 1 file changed, 1 insertion(+), 1 deletion(-)"),
|
||||
Equals(""),
|
||||
Equals("diff --git a/oldFile b/oldFile"),
|
||||
Contains("index"),
|
||||
Equals("--- a/oldFile"),
|
||||
Equals("+++ b/oldFile"),
|
||||
Equals("@@ -1,3 +1,3 @@"),
|
||||
Equals("-a"),
|
||||
Equals("+x"),
|
||||
Equals(" b"),
|
||||
Equals(" c"),
|
||||
)
|
||||
ACTUAL: */
|
||||
t.Views().Main().IsEmpty()
|
||||
},
|
||||
})
|
@ -235,6 +235,7 @@ var tests = []*components.IntegrationTest{
|
||||
filter_by_path.CliArg,
|
||||
filter_by_path.KeepSameCommitSelectedOnExit,
|
||||
filter_by_path.SelectFile,
|
||||
filter_by_path.ShowDiffsForRenamedFile,
|
||||
filter_by_path.TypeFile,
|
||||
interactive_rebase.AdvancedInteractiveRebase,
|
||||
interactive_rebase.AmendCommitWithConflict,
|
||||
|
Reference in New Issue
Block a user