diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 0aa61b463bf8..0350354c58c4 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -262,6 +262,7 @@ var tests = []*components.IntegrationTest{ worktree.AssociateBranchBisect, worktree.AssociateBranchRebase, worktree.BareRepo, + worktree.BareRepoWorktreeConfig, worktree.Crud, worktree.CustomCommand, worktree.DetachWorktreeFromBranch, diff --git a/pkg/integration/tests/worktree/bare_repo_worktree_config.go b/pkg/integration/tests/worktree/bare_repo_worktree_config.go new file mode 100644 index 000000000000..211c4088780d --- /dev/null +++ b/pkg/integration/tests/worktree/bare_repo_worktree_config.go @@ -0,0 +1,93 @@ +package worktree + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +// This case is identical to dotfile_bare_repo.go, except +// that it invokes lazygit with $GIT_DIR set but not +// $GIT_WORK_TREE. Instead, the repo uses the core.worktree +// config to identify the main worktre. + +var BareRepoWorktreeConfig = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Open lazygit in the worktree of a vcsh-style bare repo and add a file and commit", + ExtraCmdArgs: []string{"--git-dir={{.actualPath}}/.bare"}, + Skip: false, + // passing this because we're explicitly passing --git-dir and --work-tree args + UseCustomPath: true, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + // we're going to have a directory structure like this: + // project + // - .bare + // - . (a worktree at the same path as .bare) + // + // + // 'repo' is the repository/directory that all lazygit tests start in + + shell.CreateFileAndAdd("a/b/c/blah", "blah") + shell.Commit("initial commit") + + shell.CreateFileAndAdd(".gitignore", ".bare/\n") + shell.Commit("add .gitignore") + + shell.Chdir("..") + + // configure this "fake bare"" repo using the vcsh convention + // of core.bare=false and core.worktree set to the actual + // worktree path (a homedir root). This allows $GIT_DIR + // alone to make this repo "self worktree identifying" + shell.RunCommand([]string{"git", "--git-dir=./.bare", "init", "--shared=false"}) + shell.RunCommand([]string{"git", "--git-dir=./.bare", "config", "core.bare", "false"}) + shell.RunCommand([]string{"git", "--git-dir=./.bare", "config", "core.worktree", ".."}) + shell.RunCommand([]string{"git", "--git-dir=./.bare", "remote", "add", "origin", "./repo"}) + shell.RunCommand([]string{"git", "--git-dir=./.bare", "checkout", "-b", "main"}) + shell.RunCommand([]string{"git", "--git-dir=./.bare", "config", "branch.main.remote", "origin"}) + shell.RunCommand([]string{"git", "--git-dir=./.bare", "config", "branch.main.merge", "refs/heads/master"}) + shell.RunCommand([]string{"git", "--git-dir=./.bare", "fetch", "origin", "master"}) + shell.RunCommand([]string{"git", "--git-dir=./.bare", "-c", "merge.ff=true", "merge", "origin/master"}) + + // we no longer need the original repo so remove it + shell.DeleteFile("repo") + + shell.UpdateFile("a/b/c/blah", "updated content\n") + shell.Chdir("a/b/c") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Lines( + Contains("main"), + ) + + t.Views().Commits(). + Lines( + Contains("add .gitignore"), + Contains("initial commit"), + ) + + t.Views().Files(). + IsFocused(). + Lines( + Contains(" a/b/c"), // shows as modified + Contains(" M blah"), // shows as modified + ). + PressPrimaryAction(). + Press(keys.Files.CommitChanges) + + t.ExpectPopup().CommitMessagePanel(). + Title(Equals("Commit summary")). + Type("Add blah"). + Confirm() + + t.Views().Files(). + IsEmpty() + + t.Views().Commits(). + Lines( + Contains("Add blah"), + Contains("add .gitignore"), + Contains("initial commit"), + ) + }, +})