Skip to content

Commit

Permalink
generate snapshot for expected dir in separate tmp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Jan 28, 2022
1 parent 1d90e1b commit e0ae134
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions pkg/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit e0ae134

Please sign in to comment.