worktree

package
v0.43.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2024 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddFromBranch = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Add a worktree via the branches view, then switch back to the main worktree via the branches view",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("mybranch"),
			).
			Press(keys.Worktrees.ViewWorktreeOptions).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Worktree")).
					Select(Contains(`Create worktree from mybranch`).DoesNotContain("detached")).
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New worktree path")).
					Type("../linked-worktree").
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New branch name")).
					Type("newbranch").
					Confirm()
			}).
			IsFocused().
			Lines(
				Contains("newbranch").IsSelected(),
				Contains("mybranch (worktree)"),
			).
			NavigateToLine(Contains("mybranch")).
			Press(keys.Universal.Select).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Switch to worktree")).
					Content(Equals("This branch is checked out by worktree repo. Do you want to switch to that worktree?")).
					Confirm()
			}).
			Lines(
				Contains("mybranch").IsSelected(),
				Contains("newbranch (worktree)"),
			).
			Press(keys.Universal.PrevBlock)

		t.Views().Files().
			IsFocused()
	},
})
View Source
var AddFromBranchDetached = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Add a detached worktree via the branches view",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("mybranch"),
			).
			Press(keys.Worktrees.ViewWorktreeOptions).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Worktree")).
					Select(Contains(`Create worktree from mybranch (detached)`)).
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New worktree path")).
					Type("../linked-worktree").
					Confirm()
			}).
			IsFocused().
			Lines(
				Contains("(no branch)").IsSelected(),
				Contains("mybranch (worktree)"),
			)

		t.Views().Status().
			Content(Contains("repo(linked-worktree)"))
	},
})
View Source
var AddFromCommit = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Add a worktree via the commits view",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
		shell.EmptyCommit("commit two")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("commit two").IsSelected(),
				Contains("initial commit"),
			).
			NavigateToLine(Contains("initial commit")).
			Press(keys.Worktrees.ViewWorktreeOptions).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Worktree")).
					Select(MatchesRegexp(`Create worktree from .*`).DoesNotContain("detached")).
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New worktree path")).
					Type("../linked-worktree").
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New branch name")).
					Type("newbranch").
					Confirm()
			}).
			Lines(
				Contains("initial commit"),
			)

		t.Views().Branches().
			IsFocused().
			Lines(
				Contains("newbranch").IsSelected(),
				Contains("mybranch (worktree)"),
			)
	},
})
View Source
var AssociateBranchBisect = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Verify that when you start a bisect in a linked worktree, Lazygit still associates the worktree with the branch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
		shell.EmptyCommit("commit 2")
		shell.EmptyCommit("commit 3")
		shell.AddWorktree("mybranch", "../linked-worktree", "newbranch")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("mybranch").IsSelected(),
				Contains("newbranch (worktree)"),
			)

		t.Views().Commits().
			Focus().
			SelectedLine(Contains("commit 3")).
			Press(keys.Commits.ViewBisectOptions).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Bisect")).
					Select(MatchesRegexp(`Mark .* as bad`)).
					Confirm()

				t.Views().Information().Content(Contains("Bisecting"))
			}).
			NavigateToLine(Contains("initial commit")).
			Press(keys.Commits.ViewBisectOptions).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Bisect")).
					Select(MatchesRegexp(`Mark .* as good`)).
					Confirm()
			})

		t.Views().Branches().
			Focus().
			NavigateToLine(Contains("newbranch")).
			Press(keys.Universal.Select).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Switch to worktree")).
					Content(Equals("This branch is checked out by worktree linked-worktree. Do you want to switch to that worktree?")).
					Confirm()

				t.Views().Information().Content(DoesNotContain("Bisecting"))
			}).
			Lines(
				Contains("newbranch").IsSelected(),
				Contains("mybranch (worktree)"),
			)

		t.Views().Branches().
			Focus().
			NavigateToLine(Contains("mybranch")).
			Press(keys.Universal.Select).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Switch to worktree")).
					Content(Equals("This branch is checked out by worktree repo. Do you want to switch to that worktree?")).
					Confirm()
			})
	},
})
View Source
var AssociateBranchRebase = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Verify that when you start a rebase in a linked or main worktree, Lazygit still associates the worktree with the branch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
		shell.EmptyCommit("commit 2")
		shell.EmptyCommit("commit 3")
		shell.AddWorktree("mybranch", "../linked-worktree", "newbranch")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("mybranch").IsSelected(),
				Contains("newbranch (worktree)"),
			)

		t.Views().Commits().
			Focus().
			NavigateToLine(Contains("commit 2")).
			Press(keys.Universal.Edit)

		t.Views().Information().Content(Contains("Rebasing"))

		t.Views().Branches().
			Focus().
			NavigateToLine(Contains("newbranch")).
			Press(keys.Universal.Select).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Switch to worktree")).
					Content(Equals("This branch is checked out by worktree linked-worktree. Do you want to switch to that worktree?")).
					Confirm()

				t.Views().Information().Content(DoesNotContain("Rebasing"))
			}).
			Lines(
				Contains("newbranch").IsSelected(),
				Contains("mybranch (worktree)"),
			)

		t.Views().Commits().
			Focus().
			NavigateToLine(Contains("commit 2")).
			Press(keys.Universal.Edit)

		t.Views().Information().Content(Contains("Rebasing"))

		t.Views().Branches().
			Focus().
			NavigateToLine(Contains("mybranch")).
			Press(keys.Universal.Select).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Switch to worktree")).
					Content(Equals("This branch is checked out by worktree repo. Do you want to switch to that worktree?")).
					Confirm()
			}).
			Lines(
				Contains("(no branch").IsSelected(),
				Contains("mybranch"),

				Contains("newbranch (worktree)"),
			)
	},
})
View Source
var BareRepo = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Open lazygit in the worktree of a bare repo and do a rebase/bisect",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {

		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("blah", "blah")
		shell.Commit("initial commit")
		shell.EmptyCommit("commit two")
		shell.EmptyCommit("commit three")

		shell.RunCommand([]string{"git", "clone", "--bare", ".", "../.bare"})

		shell.DeleteFile(".git")

		shell.Chdir("..")

		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"})

		shell.Chdir("repo")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Lines(
				Contains("repo"),
				Contains("mybranch"),
				Contains("worktree2 (worktree)"),
			)

		t.Views().Commits().
			Focus().
			Lines(
				Contains("commit three").IsSelected(),
				Contains("commit two"),
				Contains("initial commit"),
			).
			Press(keys.Commits.MoveDownCommit).
			Lines(
				Contains("commit two"),
				Contains("commit three").IsSelected(),
				Contains("initial commit"),
			).
			NavigateToLine(Contains("commit two")).
			Press(keys.Commits.ViewBisectOptions).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Bisect")).
					Select(MatchesRegexp(`Mark .* as bad`)).
					Confirm()

				t.Views().Information().Content(Contains("Bisecting"))
			}).
			NavigateToLine(Contains("initial commit")).
			Press(keys.Commits.ViewBisectOptions).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Bisect")).
					Select(MatchesRegexp(`Mark .* as good`)).
					Confirm()

				t.Views().Information().Content(Contains("Bisecting"))
			})

		t.Views().Worktrees().
			Focus().
			Lines(
				Contains("repo").IsSelected(),
				Contains("worktree2"),
			).
			NavigateToLine(Contains("worktree2")).
			Press(keys.Universal.Select).
			Lines(
				Contains("worktree2").IsSelected(),
				Contains("repo"),
			)
	},
})
View Source
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,
	SetupConfig: func(config *config.AppConfig) {
		config.UserConfig.Gui.ShowFileTree = false
	},
	SetupRepo: func(shell *Shell) {

		shell.CreateFileAndAdd("a/b/c/blah", "blah\n")
		shell.Commit("initial commit")

		shell.CreateFileAndAdd(".gitignore", ".bare/\n/repo\n")
		shell.Commit("add .gitignore")

		shell.Chdir("..")

		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"})

		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(" M a/b/c/blah"),
			).
			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"),
			)
	},
})
View Source
var Crud = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "From the worktrees view, add a work tree, switch to it, switch back, and remove it",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Lines(
				Contains("mybranch"),
			)

		t.Views().Status().
			Lines(
				Contains("repo → mybranch"),
			)

		t.Views().Worktrees().
			Focus().
			Lines(
				Contains("repo (main)"),
			).
			Press(keys.Universal.New).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Worktree")).
					Select(Contains(`Create worktree from ref`).DoesNotContain(("detached"))).
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New worktree base ref")).
					InitialText(Equals("mybranch")).
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New worktree path")).
					Type("../linked-worktree").
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New branch name (leave blank to checkout mybranch)")).
					Type("newbranch").
					Confirm()
			}).
			Lines(
				Contains("linked-worktree").IsSelected(),
				Contains("repo (main)"),
			).
			IsFocused()

		t.Views().Status().
			Lines(
				Contains("repo(linked-worktree) → newbranch"),
			)

		t.Views().Branches().
			Lines(
				Contains("newbranch"),
				Contains("mybranch"),
			)

		t.Views().Worktrees().
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Alert().
					Title(Equals("Error")).
					Content(Equals("You cannot remove the current worktree!")).
					Confirm()
			}).
			NavigateToLine(Contains("repo (main)")).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Alert().
					Title(Equals("Error")).
					Content(Equals("You cannot remove the main worktree!")).
					Confirm()
			}).
			Press(keys.Universal.Select).
			Lines(
				Contains("repo (main)").IsSelected(),
				Contains("linked-worktree"),
			)

		t.Views().Branches().
			Lines(
				Contains("mybranch"),
				Contains("newbranch"),
			)

		t.Views().Worktrees().
			NavigateToLine(Contains("linked-worktree")).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Remove worktree")).
					Content(Contains("Are you sure you want to remove worktree 'linked-worktree'?")).
					Confirm()
			}).
			Lines(
				Contains("repo (main)").IsSelected(),
			)
	},
})
View Source
var CustomCommand = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Verify that custom commands work with worktrees by deleting a worktree via a custom command",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.UserConfig.CustomCommands = []config.CustomCommand{
			{
				Key:     "d",
				Context: "worktrees",
				Command: "git worktree remove {{ .SelectedWorktree.Path | quote }}",
			},
		}
	},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
		shell.AddWorktree("mybranch", "../linked-worktree", "newbranch")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Worktrees().
			Focus().
			Lines(
				Contains("repo (main)"),
				Contains("linked-worktree"),
			).
			NavigateToLine(Contains("linked-worktree")).
			Press("d").
			Lines(
				Contains("repo (main)"),
			)
	},
})
View Source
var DetachWorktreeFromBranch = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Detach a worktree from the branches view",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
		shell.EmptyCommit("commit 2")
		shell.EmptyCommit("commit 3")
		shell.AddWorktree("mybranch", "../linked-worktree", "newbranch")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("mybranch").IsSelected(),
				Contains("newbranch (worktree)"),
			).
			NavigateToLine(Contains("newbranch")).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().
					Menu().
					Title(Equals("Delete branch 'newbranch'?")).
					Select(Contains("Delete local branch")).
					Confirm()
			}).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Branch newbranch is checked out by worktree linked-worktree")).
					Select(Equals("Detach worktree")).
					Confirm()
			}).
			Lines(
				Contains("mybranch"),
				Contains("newbranch").DoesNotContain("(worktree)").IsSelected(),
			)

		t.Views().Worktrees().
			Focus().
			Lines(
				Contains("repo (main)").IsSelected(),
				Contains("linked-worktree"),
			)
	},
})
View Source
var DotfileBareRepo = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Open lazygit in the worktree of a dotfile bare repo and add a file and commit",
	ExtraCmdArgs: []string{"--git-dir={{.actualPath}}/.bare", "--work-tree={{.actualPath}}/repo"},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {

		shell.DeleteFile(".git")

		shell.RunCommand([]string{"git", "init", "--bare", "../.bare"})
		shell.RunCommand([]string{"git", "--git-dir=../.bare", "--work-tree=.", "checkout", "-b", "mybranch"})
		shell.CreateFile("blah", "original content\n")

		shell.RunCommand([]string{"git", "--git-dir=../.bare", "--work-tree=.", "add", "blah"})
		shell.RunCommand([]string{"git", "--git-dir=../.bare", "--work-tree=.", "commit", "-m", "initial commit"})

		shell.UpdateFile("blah", "updated content\n")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Lines(
				Contains("mybranch"),
			)

		t.Views().Commits().
			Lines(
				Contains("initial commit"),
			)

		t.Views().Files().
			IsFocused().
			Lines(
				Contains(" M blah"),
			).
			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("initial commit"),
			)
	},
})
View Source
var DoubleNestedLinkedSubmodule = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Open lazygit in a link to a repo's double nested submodules",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.UserConfig.Gui.ShowFileTree = false
	},
	SetupRepo: func(shell *Shell) {

		shell.CreateFileAndAdd("rootFile", "rootStuff")
		shell.Commit("initial repo commit")

		shell.Chdir("..")
		shell.CreateDir("innerSubmodule")
		shell.Chdir("innerSubmodule")
		shell.Init()
		shell.CreateFileAndAdd("a/b/c/blah", "blah\n")
		shell.Commit("initial inner commit")

		shell.Chdir("..")
		shell.CreateDir("outerSubmodule")
		shell.Chdir("outerSubmodule")
		shell.Init()
		shell.CreateFileAndAdd("foo", "foo")
		shell.Commit("initial outer commit")

		shell.RunCommand([]string{"git", "-c", "protocol.file.allow=always", "submodule", "add", "../innerSubmodule"})
		shell.Commit("add dependency as innerSubmodule")

		shell.Chdir("../repo")
		shell.RunCommand([]string{"git", "-c", "protocol.file.allow=always", "submodule", "add", "../outerSubmodule"})
		shell.Commit("add dependency as outerSubmodule")
		shell.Chdir("outerSubmodule")
		shell.RunCommand([]string{"git", "-c", "protocol.file.allow=always", "submodule", "update", "--init", "--recursive"})

		shell.Chdir("innerSubmodule")
		shell.UpdateFile("a/b/c/blah", "updated content\n")

		shell.Chdir("../../..")
		shell.RunCommand([]string{"ln", "-s", "repo/outerSubmodule/innerSubmodule/a/b/c", "link"})

		shell.Chdir("link")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Lines(
				Contains("HEAD detached"),
				Contains("master"),
			)

		t.Views().Commits().
			Lines(
				Contains("initial inner commit"),
			)

		t.Views().Files().
			IsFocused().
			Lines(
				Contains(" M a/b/c/blah"),
			).
			PressPrimaryAction().
			Press(keys.Files.CommitChanges)

		t.ExpectPopup().CommitMessagePanel().
			Title(Equals("Commit summary")).
			Type("Update blah").
			Confirm()

		t.Views().Files().
			IsEmpty()

		t.Views().Commits().
			Lines(
				Contains("Update blah"),
				Contains("initial inner commit"),
			)
	},
})

Even though this involves submodules, it's a worktree test since it's really exercising lazygit's ability to correctly do pathfinding in a complex use case.

View Source
var ExcludeFileInWorktree = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Add a file to .git/info/exclude in a worktree",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("commit1")
		shell.AddWorktree("HEAD", "../linked-worktree", "mybranch")
		shell.CreateFile("../linked-worktree/toExclude", "")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Worktrees().
			Focus().
			Lines(
				Contains("repo (main)").IsSelected(),
				Contains("linked-worktree"),
			).
			SelectNextItem().
			PressPrimaryAction()

		t.Views().Files().
			Focus().
			Lines(
				Contains("toExclude"),
			).
			Press(keys.Files.IgnoreFile).
			Tap(func() {
				t.ExpectPopup().Menu().Title(Equals("Ignore or exclude file")).Select(Contains("Add to .git/info/exclude")).Confirm()
			}).
			IsEmpty()

		t.FileSystem().FileContent("../repo/.git/info/exclude", Contains("toExclude"))
	},
})
View Source
var FastForwardWorktreeBranch = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Fast-forward a linked worktree branch from another worktree",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {

		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
		shell.EmptyCommit("two")
		shell.EmptyCommit("three")
		shell.NewBranch("newbranch")

		shell.CloneIntoRemote("origin")
		shell.SetBranchUpstream("mybranch", "origin/mybranch")
		shell.SetBranchUpstream("newbranch", "origin/newbranch")

		shell.HardReset("HEAD^")
		shell.Checkout("mybranch")
		shell.HardReset("HEAD^")

		shell.AddWorktreeCheckout("newbranch", "../linked-worktree")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("mybranch").Contains("↓1").IsSelected(),
				Contains("newbranch (worktree)").Contains("↓1"),
			).
			Press(keys.Branches.FastForward).
			Lines(
				Contains("mybranch").Contains("✓").IsSelected(),
				Contains("newbranch (worktree)").Contains("↓1"),
			).
			NavigateToLine(Contains("newbranch (worktree)")).
			Press(keys.Branches.FastForward).
			Lines(
				Contains("mybranch").Contains("✓"),
				Contains("newbranch (worktree)").Contains("✓").IsSelected(),
			)
	},
})
View Source
var ForceRemoveWorktree = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Force remove a dirty worktree",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
		shell.EmptyCommit("commit 2")
		shell.EmptyCommit("commit 3")
		shell.AddWorktree("mybranch", "../linked-worktree", "newbranch")
		shell.AddFileInWorktree("../linked-worktree")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Worktrees().
			Focus().
			Lines(
				Contains("repo (main)").IsSelected(),
				Contains("linked-worktree"),
			).
			NavigateToLine(Contains("linked-worktree")).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Remove worktree")).
					Content(Equals("Are you sure you want to remove worktree 'linked-worktree'?")).
					Confirm()

				t.ExpectPopup().Confirmation().
					Title(Equals("Remove worktree")).
					Content(Equals("'linked-worktree' contains modified or untracked files (to be honest, it could contain both). Are you sure you want to remove it?")).
					Confirm()
			}).
			Lines(
				Contains("repo (main)").IsSelected(),
			)
	},
})
View Source
var RemoveWorktreeFromBranch = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Remove a worktree from the branches view",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
		shell.EmptyCommit("commit 2")
		shell.EmptyCommit("commit 3")
		shell.AddWorktree("mybranch", "../linked-worktree", "newbranch")
		shell.AddFileInWorktree("../linked-worktree")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("mybranch").IsSelected(),
				Contains("newbranch (worktree)"),
			).
			NavigateToLine(Contains("newbranch")).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().
					Menu().
					Title(Equals("Delete branch 'newbranch'?")).
					Select(Contains("Delete local branch")).
					Confirm()
			}).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Branch newbranch is checked out by worktree linked-worktree")).
					Select(Equals("Remove worktree")).
					Confirm()

				t.ExpectPopup().Confirmation().
					Title(Equals("Remove worktree")).
					Content(Equals("Are you sure you want to remove worktree 'linked-worktree'?")).
					Confirm()

				t.ExpectPopup().Confirmation().
					Title(Equals("Remove worktree")).
					Content(Equals("'linked-worktree' contains modified or untracked files (to be honest, it could contain both). Are you sure you want to remove it?")).
					Confirm()
			}).
			Lines(
				Contains("mybranch"),
				Contains("newbranch").DoesNotContain("(worktree)").IsSelected(),
			)

		t.Views().Worktrees().
			Focus().
			Lines(
				Contains("repo (main)").IsSelected(),
			)
	},
})
View Source
var ResetWindowTabs = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Verify that window tabs are reset whenever switching repos",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
		shell.EmptyCommit("commit 2")
		shell.EmptyCommit("commit 3")
		shell.AddWorktree("mybranch", "../linked-worktree", "newbranch")
		shell.AddFileInWorktree("../linked-worktree")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {

		t.Views().Remotes().
			Focus()

		t.Views().Worktrees().
			Focus().
			Lines(
				Contains("repo (main)").IsSelected(),
				Contains("linked-worktree"),
			).
			NavigateToLine(Contains("linked-worktree")).
			Press(keys.Universal.Select).
			Lines(
				Contains("linked-worktree").IsSelected(),
				Contains("repo (main)"),
			).
			Press(keys.Universal.NextBlock)

		t.Views().Branches().
			IsFocused()
	},
})
View Source
var SymlinkIntoRepoSubdir = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Open lazygit in a symlink into a repo's subdirectory",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
		config.UserConfig.Gui.ShowFileTree = false
	},
	SetupRepo: func(shell *Shell) {

		shell.CreateFileAndAdd("a/b/c/blah", "blah\n")
		shell.Commit("initial commit")
		shell.UpdateFile("a/b/c/blah", "updated content\n")

		shell.Chdir("..")
		shell.RunCommand([]string{"ln", "-s", "repo/a/b/c", "link"})

		shell.Chdir("link")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Lines(
				Contains("master"),
			)

		t.Views().Commits().
			Lines(
				Contains("initial commit"),
			)

		t.Views().Files().
			IsFocused().
			Lines(
				Contains(" M a/b/c/blah"),
			).
			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("initial commit"),
			)
	},
})
View Source
var WorktreeInRepo = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Add a worktree inside the repo, then remove the directory and confirm the worktree is removed",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("mybranch")
		shell.CreateFileAndAdd("README.md", "hello world")
		shell.Commit("initial commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Lines(
				Contains("mybranch"),
			)

		t.Views().Worktrees().
			Focus().
			Lines(
				Contains("repo (main)"),
			).
			Press(keys.Universal.New).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Worktree")).
					Select(Contains(`Create worktree from ref`).DoesNotContain(("detached"))).
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New worktree base ref")).
					InitialText(Equals("mybranch")).
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New worktree path")).
					Type("linked-worktree").
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New branch name (leave blank to checkout mybranch)")).
					Type("newbranch").
					Confirm()
			}).
			Lines(
				Contains("linked-worktree").IsSelected(),
				Contains("repo (main)"),
			).
			NavigateToLine(Contains("repo (main)")).
			Press(keys.Universal.Select).
			Lines(
				Contains("repo (main)").IsSelected(),
				Contains("linked-worktree"),
			)

		t.Views().Files().
			Focus().
			Lines(
				Contains("linked-worktree"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Discard changes")).
					Select(Contains("Discard all changes")).
					Confirm()
			}).
			IsEmpty()

		t.Views().Worktrees().
			Focus().
			Lines(
				Contains("repo (main)").IsSelected(),
				Contains("linked-worktree (missing)"),
			)
	},
})

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL