diff options
Diffstat (limited to 'pkg/integration')
-rw-r--r-- | pkg/integration/components/shell.go | 10 | ||||
-rw-r--r-- | pkg/integration/tests/test_list.go | 1 | ||||
-rw-r--r-- | pkg/integration/tests/worktree/bare_repo.go | 61 |
3 files changed, 71 insertions, 1 deletions
diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index 741135e2f..ce98e575a 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -85,7 +85,7 @@ func (self *Shell) CreateFile(path string, content string) *Shell { func (self *Shell) DeleteFile(path string) *Shell { fullPath := filepath.Join(self.dir, path) - err := os.Remove(fullPath) + err := os.RemoveAll(fullPath) if err != nil { self.fail(fmt.Sprintf("error deleting file: %s\n%s", fullPath, err)) } @@ -328,3 +328,11 @@ func (self *Shell) CopyFile(source string, destination string) *Shell { return self } + +// NOTE: this only takes effect before running the test; +// the test will still run in the original directory +func (self *Shell) Chdir(path string) *Shell { + self.dir = filepath.Join(self.dir, path) + + return self +} diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 361fa2064..62a4fae29 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -223,6 +223,7 @@ var tests = []*components.IntegrationTest{ worktree.AddFromBranch, worktree.AddFromBranchDetached, worktree.AddFromCommit, + worktree.BareRepo, worktree.Bisect, worktree.Crud, worktree.CustomCommand, diff --git a/pkg/integration/tests/worktree/bare_repo.go b/pkg/integration/tests/worktree/bare_repo.go new file mode 100644 index 000000000..af0133227 --- /dev/null +++ b/pkg/integration/tests/worktree/bare_repo.go @@ -0,0 +1,61 @@ +package worktree + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var BareRepo = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Open lazygit in the worktree of a bare repo", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + // we're going to have a directory structure like this: + // project + // - .bare + // - repo (a worktree) + // - worktree2 (another worktree) + // + // The first repo is called 'repo' because that's the + // directory that all lazygit tests start in + + shell.NewBranch("mybranch") + shell.CreateFileAndAdd("blah", "blah") + shell.Commit("initial commit") + + shell.RunCommand([]string{"git", "clone", "--bare", ".", "../.bare"}) + + shell.DeleteFile(".git") + + shell.Chdir("..") + + // This is the dir we were just in (and the dir that lazygit starts in when the test runs) + // We're going to replace it with a worktree + shell.DeleteFile("repo") + + shell.RunCommand([]string{"git", "--git-dir", ".bare", "worktree", "add", "-b", "repo", "repo", "mybranch"}) + shell.RunCommand([]string{"git", "--git-dir", ".bare", "worktree", "add", "-b", "worktree2", "worktree2", "mybranch"}) + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Lines( + Contains("repo"), + Contains("mybranch"), + Contains("worktree2 (worktree)"), + ) + + t.Views().Worktrees(). + Focus(). + Lines( + Contains("repo").IsSelected(), + Contains("worktree2"), + ). + NavigateToLine(Contains("worktree2")). + Press(keys.Universal.Select). + Lines( + Contains("worktree2").IsSelected(), + Contains("repo"), + ) + }, +}) |