summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-01-28 23:46:32 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-29 00:17:32 +1100
commite0ae134ee42fd244cf57931aa205f3ce23f4b03f (patch)
tree329cfcb48d10bc421de5c446cf28af8876820aac
parent1d90e1b565ad41892a903e757bcee51466eca37d (diff)
generate snapshot for expected dir in separate tmp dir
-rw-r--r--pkg/integration/integration.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/pkg/integration/integration.go b/pkg/integration/integration.go
index 542624a6f..a55d460fe 100644
--- a/pkg/integration/integration.go
+++ b/pkg/integration/integration.go
@@ -414,17 +414,26 @@ func generateSnapshots(actualDir string, expectedDir string) (string, string, er
return "", "", err
}
- defer func() {
- if err := renameGitDirs(expectedDir); err != nil {
- panic(err)
- }
- }()
+ // there are a couple of reasons we're not generating the snapshot in expectedDir directly:
+ // Firstly we don't want to have to revert our .git file back to .git_keep.
+ // Secondly, the act of calling git commands like 'git status' actually changes the index
+ // for some reason, and we don't want to leave your lazygit working tree dirty as a result.
+ expectedDirCopyDir := filepath.Join(filepath.Dir(expectedDir), "expected_dir_test")
+ err = oscommands.CopyDir(expectedDir, expectedDirCopyDir)
+ if err != nil {
+ return "", "", err
+ }
- if err := restoreGitDirs(expectedDir); err != nil {
+ if err := restoreGitDirs(expectedDirCopyDir); err != nil {
return "", "", err
}
- expected, err := generateSnapshot(expectedDir)
+ expected, err := generateSnapshot(expectedDirCopyDir)
+ if err != nil {
+ return "", "", err
+ }
+
+ err = os.RemoveAll(expectedDirCopyDir)
if err != nil {
return "", "", err
}