branch

package
v0.0.0-...-00ab8b8 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CheckoutByName = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Try to checkout branch by name. Verify that it also works on the branch with the special name @.",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.
			CreateNCommits(3).
			NewBranch("@").
			Checkout("master").
			EmptyCommit("blah")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("master").IsSelected(),
				Contains("@"),
			).
			SelectNextItem().
			Press(keys.Branches.CheckoutBranchByName).
			Tap(func() {
				t.ExpectPopup().Prompt().Title(Equals("Branch name:")).Type("new-branch").Confirm()

				t.ExpectPopup().Alert().Title(Equals("Branch not found")).Content(Equals("Branch not found. Create a new branch named new-branch?")).Confirm()
			}).
			Lines(
				MatchesRegexp(`\*.*new-branch`).IsSelected(),
				Contains("master"),
				Contains("@"),
			)
	},
})
View Source
var CreateTag = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Create a new tag on branch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.
			CreateNCommits(10).
			NewBranch("new-branch").
			EmptyCommit("new commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				MatchesRegexp(`\*\s*new-branch`).IsSelected(),
				MatchesRegexp(`master`),
			).
			SelectNextItem().
			Press(keys.Branches.CreateTag)

		t.ExpectPopup().CommitMessagePanel().
			Title(Equals("Tag name")).
			Type("new-tag").
			Confirm()

		t.Views().Tags().Focus().
			Lines(
				MatchesRegexp(`new-tag`).IsSelected(),
			)

		t.Git().
			TagNamesAt("HEAD", []string{}).
			TagNamesAt("master", []string{"new-tag"})
	},
})
View Source
var Delete = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Try all combination of local and remote branch deletions",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.
			CloneIntoRemote("origin").
			EmptyCommit("blah").
			NewBranch("branch-one").
			PushBranch("origin", "branch-one").
			NewBranch("branch-two").
			PushBranch("origin", "branch-two").
			EmptyCommit("deletion blocker").
			NewBranch("branch-three")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				MatchesRegexp(`\*.*branch-three`).IsSelected(),
				MatchesRegexp(`branch-two`),
				MatchesRegexp(`branch-one`),
				MatchesRegexp(`master`),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().
					Menu().
					Tooltip(Contains("You cannot delete the checked out branch!")).
					Title(Equals("Delete branch 'branch-three'?")).
					Select(Contains("Delete local branch")).
					Confirm().
					Tap(func() {
						t.ExpectToast(Contains("You cannot delete the checked out branch!"))
					}).
					Cancel()
			}).
			SelectNextItem().
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().
					Menu().
					Title(Equals("Delete branch 'branch-two'?")).
					Select(Contains("Delete local branch")).
					Confirm()
			}).
			Tap(func() {
				t.ExpectPopup().
					Confirmation().
					Title(Equals("Force delete branch")).
					Content(Equals("'branch-two' is not fully merged. Are you sure you want to delete it?")).
					Confirm()
			}).
			Lines(
				MatchesRegexp(`\*.*branch-three`),
				MatchesRegexp(`branch-one`).IsSelected(),
				MatchesRegexp(`master`),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().
					Menu().
					Title(Equals("Delete branch 'branch-one'?")).
					Select(Contains("Delete remote branch")).
					Confirm()
			}).
			Tap(func() {
				t.ExpectPopup().
					Confirmation().
					Title(Equals("Delete branch 'branch-one'?")).
					Content(Equals("Are you sure you want to delete the remote branch 'branch-one' from 'origin'?")).
					Confirm()
			}).
			Tap(func() {
				t.Views().Remotes().
					Focus().
					Lines(Contains("origin")).
					PressEnter()

				t.Views().
					RemoteBranches().
					Lines(Equals("branch-two")).
					Press(keys.Universal.Return)

				t.Views().
					Branches().
					Focus()
			}).
			Lines(
				MatchesRegexp(`\*.*branch-three`),
				MatchesRegexp(`branch-one \(upstream gone\)`).IsSelected(),
				MatchesRegexp(`master`),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().
					Menu().
					Title(Equals("Delete branch 'branch-one'?")).
					Select(Contains("Delete local branch")).
					Confirm()
			}).
			Lines(
				MatchesRegexp(`\*.*branch-three`),
				MatchesRegexp(`master`).IsSelected(),
			)
	},
})
View Source
var DeleteRemoteBranchWithCredentialPrompt = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Delete a remote branch where credentials are required",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(config *config.AppConfig) {
	},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("one")

		shell.CloneIntoRemote("origin")

		shell.NewBranch("mybranch")

		shell.PushBranch("origin", "mybranch")

		shell.CopyHelpFile("pre-push", ".git/hooks/pre-push")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		deleteBranch := func() {
			t.Views().Branches().
				Focus().
				Press(keys.Universal.Remove)

			t.ExpectPopup().
				Menu().
				Title(Equals("Delete branch 'mybranch'?")).
				Select(Contains("Delete remote branch")).
				Confirm()

			t.ExpectPopup().
				Confirmation().
				Title(Equals("Delete branch 'mybranch'?")).
				Content(Equals("Are you sure you want to delete the remote branch 'mybranch' from 'origin'?")).
				Confirm()
		}

		t.Views().Status().Content(Contains("✓ repo → mybranch"))

		deleteBranch()

		t.ExpectPopup().Prompt().
			Title(Equals("Username")).
			Type("username").
			Confirm()

		t.ExpectPopup().Prompt().
			Title(Equals("Password")).
			Type("incorrect password").
			Confirm()

		t.ExpectPopup().Alert().
			Title(Equals("Error")).
			Content(Contains("incorrect username/password")).
			Confirm()

		t.Views().Status().Content(Contains("✓ repo → mybranch"))

		deleteBranch()

		t.ExpectPopup().Prompt().
			Title(Equals("Username")).
			Type("username").
			Confirm()

		t.ExpectPopup().Prompt().
			Title(Equals("Password")).
			Type("password").
			Confirm()

		t.Views().Status().Content(Contains("repo → mybranch").DoesNotContain("✓"))
		t.Views().Branches().TopLines(Contains("mybranch (upstream gone)"))
	},
})
View Source
var DetachedHead = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Create a new branch on detached head",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.
			CreateNCommits(10).
			Checkout("HEAD^")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				MatchesRegexp(`\*.*HEAD`).IsSelected(),
				MatchesRegexp(`master`),
			).
			Press(keys.Universal.New)

		t.ExpectPopup().Prompt().
			Title(MatchesRegexp(`^New branch name \(branch is off of '[0-9a-f]+'\)$`)).
			Type("new-branch").
			Confirm()

		t.Views().Branches().
			Lines(
				MatchesRegexp(`\* new-branch`).IsSelected(),
				MatchesRegexp(`master`),
			)

		t.Git().CurrentBranchName("new-branch")
	},
})
View Source
var OpenPullRequestNoUpstream = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Open up a pull request with a missing upstream branch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo:    func(shell *Shell) {},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().
			Branches().
			Focus().
			Press(keys.Branches.CreatePullRequest)

		t.ExpectPopup().Alert().
			Title(Equals("Error")).
			Content(Contains("Cannot open a pull request for a branch with no upstream")).
			Confirm()
	},
})
View Source
var OpenWithCliArg = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Open straight to branches panel using a CLI arg",
	ExtraCmdArgs: []string{"branch"},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().IsFocused()
	},
})
View Source
var Rebase = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Rebase onto another branch, deal with the conflicts.",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shared.MergeConflictsSetup(shell)
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().TopLines(
			Contains("first change"),
			Contains("original"),
		)

		t.Views().Branches().
			Focus().
			Lines(
				Contains("first-change-branch"),
				Contains("second-change-branch"),
				Contains("original-branch"),
			).
			SelectNextItem().
			Press(keys.Branches.RebaseBranch)

		t.ExpectPopup().Menu().
			Title(Equals("Rebase 'first-change-branch' onto 'second-change-branch'")).
			Select(Contains("Simple rebase")).
			Confirm()

		t.Common().AcknowledgeConflicts()

		t.Views().Files().
			IsFocused().
			SelectedLine(Contains("file")).
			PressEnter()

		t.Views().MergeConflicts().
			IsFocused().
			PressPrimaryAction()

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

		t.Common().ContinueOnConflictsResolved()

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

		t.Views().Commits().TopLines(
			Contains("second-change-branch unrelated change"),
			Contains("second change"),
			Contains("original"),
		)
	},
})
View Source
var RebaseAbortOnConflict = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Rebase onto another branch, abort when there are conflicts.",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shared.MergeConflictsSetup(shell)
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().TopLines(
			Contains("first change"),
			Contains("original"),
		)

		t.Views().Branches().
			Focus().
			Lines(
				Contains("first-change-branch"),
				Contains("second-change-branch"),
				Contains("original-branch"),
			).
			SelectNextItem().
			Press(keys.Branches.RebaseBranch)

		t.ExpectPopup().Menu().
			Title(Equals("Rebase 'first-change-branch' onto 'second-change-branch'")).
			Select(Contains("Simple rebase")).
			Confirm()

		t.ExpectPopup().Menu().
			Title(Equals("Conflicts!")).
			Select(Contains("Abort the rebase")).
			Confirm()

		t.Views().Branches().
			IsFocused()

		t.Views().Files().
			IsEmpty()
	},
})
View Source
var RebaseAndDrop = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Rebase onto another branch, deal with the conflicts. Also mark a commit to be dropped before continuing.",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shared.MergeConflictsSetup(shell)

		shell.EmptyCommit("to remove")
		shell.EmptyCommit("to keep")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			TopLines(
				Contains("to keep"),
				Contains("to remove"),
				Contains("first change"),
				Contains("original"),
			)

		t.Views().Branches().
			Focus().
			Lines(
				Contains("first-change-branch").IsSelected(),
				Contains("second-change-branch"),
				Contains("original-branch"),
			).
			SelectNextItem().
			Press(keys.Branches.RebaseBranch)

		t.ExpectPopup().Menu().
			Title(Equals("Rebase 'first-change-branch' onto 'second-change-branch'")).
			Select(Contains("Simple rebase")).
			Confirm()

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

		t.Common().AcknowledgeConflicts()

		t.Views().Files().IsFocused().
			SelectedLine(MatchesRegexp("UU.*file"))

		t.Views().Commits().
			Focus().
			TopLines(
				MatchesRegexp(`pick.*to keep`).IsSelected(),
				MatchesRegexp(`pick.*to remove`),
				MatchesRegexp(`conflict.*YOU ARE HERE.*first change`),
				MatchesRegexp("second-change-branch unrelated change"),
				MatchesRegexp("second change"),
				MatchesRegexp("original"),
			).
			SelectNextItem().
			Press(keys.Universal.Remove).
			TopLines(
				MatchesRegexp(`pick.*to keep`),
				MatchesRegexp(`drop.*to remove`).IsSelected(),
				MatchesRegexp(`conflict.*YOU ARE HERE.*first change`),
				MatchesRegexp("second-change-branch unrelated change"),
				MatchesRegexp("second change"),
				MatchesRegexp("original"),
			)

		t.Views().Files().
			Focus().
			PressEnter()

		t.Views().MergeConflicts().
			IsFocused().
			PressPrimaryAction()

		t.Common().ContinueOnConflictsResolved()

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

		t.Views().Commits().TopLines(
			Contains("to keep"),
			Contains("second-change-branch unrelated change").IsSelected(),
			Contains("second change"),
			Contains("original"),
		)
	},
})
View Source
var RebaseCancelOnConflict = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Rebase onto another branch, cancel when there are conflicts.",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shared.MergeConflictsSetup(shell)
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().TopLines(
			Contains("first change"),
			Contains("original"),
		)

		t.Views().Branches().
			Focus().
			Lines(
				Contains("first-change-branch"),
				Contains("second-change-branch"),
				Contains("original-branch"),
			).
			SelectNextItem().
			Press(keys.Branches.RebaseBranch)

		t.ExpectPopup().Menu().
			Title(Equals("Rebase 'first-change-branch' onto 'second-change-branch'")).
			Select(Contains("Simple rebase")).
			Confirm()

		t.ExpectPopup().Menu().
			Title(Equals("Conflicts!")).
			Select(Contains("Abort the rebase")).
			Cancel()

		t.Views().Branches().
			IsFocused()

		t.Views().Files().
			Lines(
				Contains("UU file"),
			)
	},
})
View Source
var RebaseDoesNotAutosquash = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Rebase a branch that has fixups onto another branch, and verify that the fixups are not squashed even if rebase.autoSquash is enabled globally.",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.SetConfig("rebase.autoSquash", "true")

		shell.
			EmptyCommit("base").
			NewBranch("my-branch").
			Checkout("master").
			EmptyCommit("master commit").
			Checkout("my-branch").
			EmptyCommit("branch commit").
			EmptyCommit("fixup! branch commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Lines(
				Contains("fixup! branch commit"),
				Contains("branch commit"),
				Contains("base"),
			)

		t.Views().Branches().
			Focus().
			Lines(
				Contains("my-branch").IsSelected(),
				Contains("master"),
			).
			SelectNextItem().
			Press(keys.Branches.RebaseBranch)

		t.ExpectPopup().Menu().
			Title(Equals("Rebase 'my-branch' onto 'master'")).
			Select(Contains("Simple rebase")).
			Confirm()

		t.Views().Commits().Lines(
			Contains("fixup! branch commit"),
			Contains("branch commit"),
			Contains("master commit"),
			Contains("base"),
		)
	},
})
View Source
var RebaseFromMarkedBase = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Rebase onto another branch from a marked base commit",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.
			NewBranch("base-branch").
			EmptyCommit("one").
			EmptyCommit("two").
			EmptyCommit("three").
			NewBranch("active-branch").
			EmptyCommit("active one").
			EmptyCommit("active two").
			EmptyCommit("active three").
			Checkout("base-branch").
			NewBranch("target-branch").
			EmptyCommit("target one").
			EmptyCommit("target two").
			Checkout("active-branch")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("active three"),
				Contains("active two"),
				Contains("active one"),
				Contains("three"),
				Contains("two"),
				Contains("one"),
			).
			NavigateToLine(Contains("active one")).
			Press(keys.Commits.MarkCommitAsBaseForRebase).
			Lines(
				Contains("active three").Contains("✓"),
				Contains("active two").Contains("✓"),
				Contains("↑↑↑ Will rebase from here ↑↑↑ active one"),
				Contains("three").DoesNotContain("✓"),
				Contains("two").DoesNotContain("✓"),
				Contains("one").DoesNotContain("✓"),
			)

		t.Views().Information().Content(Contains("Marked a base commit for rebase"))

		t.Views().Branches().
			Focus().
			Lines(
				Contains("active-branch"),
				Contains("target-branch"),
				Contains("base-branch"),
			).
			SelectNextItem().
			Press(keys.Branches.RebaseBranch)

		t.ExpectPopup().Menu().
			Title(Equals("Rebase 'active-branch' from marked base onto 'target-branch'")).
			Select(Contains("Simple rebase")).
			Confirm()

		t.Views().Commits().Lines(
			Contains("active three").DoesNotContain("✓"),
			Contains("active two").DoesNotContain("✓"),
			Contains("target two").DoesNotContain("✓"),
			Contains("target one").DoesNotContain("✓"),
			Contains("three").DoesNotContain("✓"),
			Contains("two").DoesNotContain("✓"),
			Contains("one").DoesNotContain("✓"),
		)
	},
})
View Source
var RebaseToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Rebase the current branch to the selected branch upstream",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.
			CloneIntoRemote("origin").
			EmptyCommit("ensure-master").
			EmptyCommit("to-be-added").
			PushBranch("origin", "master").
			HardReset("HEAD~1").
			NewBranchFrom("base-branch", "master").
			EmptyCommit("base-branch-commit").
			NewBranch("target").
			EmptyCommit("target-commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().Lines(
			Contains("target-commit"),
			Contains("base-branch-commit"),
			Contains("ensure-master"),
		)

		t.Views().Branches().
			Focus().
			Lines(
				Contains("target").IsSelected(),
				Contains("base-branch"),
				Contains("master"),
			).
			SelectNextItem().
			Lines(
				Contains("target"),
				Contains("base-branch").IsSelected(),
				Contains("master"),
			).
			Press(keys.Branches.SetUpstream).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Upstream options")).
					Select(Contains("Rebase checked-out branch onto upstream of selected branch")).
					Tooltip(Contains("Disabled: The selected branch has no upstream (or the upstream is not stored locally)")).
					Confirm().
					Tap(func() {
						t.ExpectToast(Equals("Disabled: The selected branch has no upstream (or the upstream is not stored locally)"))
					}).
					Cancel()
			}).
			SelectNextItem().
			Lines(
				Contains("target"),
				Contains("base-branch"),
				Contains("master").IsSelected(),
			).
			Press(keys.Branches.SetUpstream).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Upstream options")).
					Select(Contains("Rebase checked-out branch onto origin/master...")).
					Confirm()
				t.ExpectPopup().Menu().
					Title(Equals("Rebase 'target' onto 'origin/master'")).
					Select(Contains("Simple rebase")).
					Confirm()
			})

		t.Views().Commits().Lines(
			Contains("target-commit"),
			Contains("base-branch-commit"),
			Contains("to-be-added"),
			Contains("ensure-master"),
		)
	},
})
View Source
var Rename = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Rename a branch, replacing spaces in the name with dashes",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("master"),
			).
			Press(keys.Branches.RenameBranch).
			Tap(func() {
				t.ExpectPopup().Prompt().
					Title(Contains("Enter new branch name")).
					InitialText(Equals("master")).
					Clear().
					Type("new branch name").
					Confirm()
			}).
			Lines(
				Contains("new-branch-name"),
			)
	},
})
View Source
var Reset = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Hard reset to another branch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("current-branch")
		shell.EmptyCommit("root commit")

		shell.NewBranch("other-branch")
		shell.EmptyCommit("other-branch commit")

		shell.Checkout("current-branch")
		shell.EmptyCommit("current-branch commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().Lines(
			Contains("current-branch commit"),
			Contains("root commit"),
		)

		t.Views().Branches().
			Focus().
			Lines(
				Contains("current-branch").IsSelected(),
				Contains("other-branch"),
			).
			SelectNextItem().
			Press(keys.Commits.ViewResetOptions)

		t.ExpectPopup().Menu().
			Title(Contains("Reset to other-branch")).
			Select(Contains("Hard reset")).
			Confirm()

		t.Views().Commits().
			Lines(
				Contains("other-branch commit"),
				Contains("root commit"),
			)
	},
})
View Source
var ResetToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Hard reset the current branch to the selected branch upstream",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.
			CloneIntoRemote("origin").
			NewBranch("hard-branch").
			EmptyCommit("hard commit").
			PushBranch("origin", "hard-branch").
			NewBranch("soft-branch").
			EmptyCommit("soft commit").
			PushBranch("origin", "soft-branch").
			NewBranch("base").
			EmptyCommit("base-branch commit").
			CreateFile("file-1", "content").
			GitAdd("file-1").
			Commit("commit with file").
			CreateFile("file-2", "content").
			GitAdd("file-2")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {

		t.Views().Branches().
			Focus().
			Lines(
				Contains("base").IsSelected(),
				Contains("soft-branch"),
				Contains("hard-branch"),
			).
			Press(keys.Branches.SetUpstream).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Upstream options")).
					Select(Contains("Reset checked-out branch onto upstream of selected branch")).
					Tooltip(Contains("Disabled: The selected branch has no upstream (or the upstream is not stored locally)")).
					Confirm().
					Tap(func() {
						t.ExpectToast(Equals("Disabled: The selected branch has no upstream (or the upstream is not stored locally)"))
					}).
					Cancel()
			}).
			SelectNextItem().
			Lines(
				Contains("base"),
				Contains("soft-branch").IsSelected(),
				Contains("hard-branch"),
			).
			Press(keys.Branches.SetUpstream).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Upstream options")).
					Select(Contains("Reset checked-out branch onto origin/soft-branch...")).
					Confirm()

				t.ExpectPopup().Menu().
					Title(Equals("Reset to origin/soft-branch")).
					Select(Contains("Soft reset")).
					Confirm()
			})
		t.Views().Commits().Lines(
			Contains("soft commit"),
			Contains("hard commit"),
		)
		t.Views().Files().Lines(
			Contains("file-1").Contains("A"),
			Contains("file-2").Contains("A"),
		)

		t.Views().Branches().
			Focus().
			Lines(
				Contains("base"),
				Contains("soft-branch").IsSelected(),
				Contains("hard-branch"),
			).
			NavigateToLine(Contains("hard-branch")).
			Press(keys.Branches.SetUpstream).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Upstream options")).
					Select(Contains("Reset checked-out branch onto origin/hard-branch...")).
					Confirm()

				t.ExpectPopup().Menu().
					Title(Equals("Reset to origin/hard-branch")).
					Select(Contains("Hard reset")).
					Confirm()
			})
		t.Views().Commits().Lines(Contains("hard commit"))
		t.Views().Files().IsEmpty()
	},
})
View Source
var SetUpstream = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Set the upstream of a branch",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("one")
		shell.CloneIntoRemote("origin")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Press(keys.Universal.NextScreenMode).
			Lines(
				Contains("master").DoesNotContain("origin master").IsSelected(),
			).
			Press(keys.Branches.SetUpstream).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Upstream options")).
					Select(Contains(" Set upstream of selected branch")).
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("Enter upstream as '<remote> <branchname>'")).
					SuggestionLines(Equals("origin master")).
					ConfirmFirstSuggestion()
			}).
			Lines(
				Contains("master").Contains("origin master").IsSelected(),
			)
	},
})
View Source
var ShowDivergenceFromUpstream = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Show divergence from upstream",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file", "content1")
		shell.Commit("one")
		shell.UpdateFileAndAdd("file", "content2")
		shell.Commit("two")
		shell.CreateFileAndAdd("file3", "content3")
		shell.Commit("three")

		shell.CloneIntoRemote("origin")

		shell.SetBranchUpstream("master", "origin/master")

		shell.HardReset("HEAD^^")
		shell.CreateFileAndAdd("file4", "content4")
		shell.Commit("four")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Lines(
				Contains("four"),
				Contains("one"),
			)

		t.Views().Branches().
			Focus().
			Lines(Contains("master")).
			Press(keys.Branches.SetUpstream)

		t.ExpectPopup().Menu().Title(Contains("Upstream")).Select(Contains("View divergence from upstream")).Confirm()

		t.Views().SubCommits().
			IsFocused().
			Title(Contains("Commits (master <-> origin/master)")).
			Lines(
				DoesNotContainAnyOf("↓", "↑").Contains("--- Remote ---"),
				Contains("↓").Contains("three"),
				Contains("↓").Contains("two"),
				DoesNotContainAnyOf("↓", "↑").Contains("--- Local ---"),
				Contains("↑").Contains("four"),
			)
	},
})
View Source
var SortLocalBranches = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Sort local branches by recency, date or alphabetically",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.
			EmptyCommit("commit").
			NewBranch("first").
			EmptyCommitWithDate("commit", "2023-04-07 10:00:00").
			NewBranch("second").
			EmptyCommitWithDate("commit", "2023-04-07 12:00:00").
			NewBranch("third").
			EmptyCommitWithDate("commit", "2023-04-07 11:00:00").
			Checkout("master")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {

		t.Views().Branches().
			Focus().
			Lines(
				Contains("master").IsSelected(),
				Contains("third"),
				Contains("second"),
				Contains("first"),
			).
			SelectNextItem()

		t.Views().Branches().
			Press(keys.Branches.SortOrder)

		t.ExpectPopup().Menu().Title(Equals("Sort order")).
			Select(Contains("-committerdate")).
			Confirm()

		t.Views().Branches().
			IsFocused().
			Lines(
				Contains("master").IsSelected(),
				Contains("second"),
				Contains("third"),
				Contains("first"),
			)

		t.Views().Branches().
			Press(keys.Branches.SortOrder)

		t.ExpectPopup().Menu().Title(Equals("Sort order")).
			Select(Contains("refname")).
			Confirm()

		t.Views().Branches().
			IsFocused().
			Lines(
				Contains("master").IsSelected(),
				Contains("first"),
				Contains("second"),
				Contains("third"),
			)
	},
})
View Source
var SortRemoteBranches = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Sort remote branches alphabetically or by date",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("first")
		shell.EmptyCommitWithDate("commit", "2023-04-07 10:00:00")
		shell.NewBranch("second")
		shell.EmptyCommitWithDate("commit", "2023-04-07 12:00:00")
		shell.NewBranch("third")
		shell.EmptyCommitWithDate("commit", "2023-04-07 11:00:00")
		shell.CloneIntoRemote("origin")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Remotes().
			Focus().
			Lines(
				Contains("origin").IsSelected(),
			).
			PressEnter()

		t.Views().RemoteBranches().
			IsFocused().
			Lines(
				Contains("first").IsSelected(),
				Contains("second"),
				Contains("third"),
			).
			SelectNextItem()

		t.Views().RemoteBranches().
			Press(keys.Branches.SortOrder)

		t.ExpectPopup().Menu().Title(Equals("Sort order")).
			Select(Contains("-committerdate")).
			Confirm()

		t.Views().RemoteBranches().
			IsFocused().
			Lines(
				Contains("second").IsSelected(),
				Contains("third"),
				Contains("first"),
			)
	},
})
View Source
var Suggestions = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Checking out a branch with name suggestions",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.
			EmptyCommit("my commit message").
			NewBranch("new-branch").
			NewBranch("new-branch-2").
			NewBranch("new-branch-3").
			NewBranch("branch-to-checkout").
			NewBranch("other-new-branch-2").
			NewBranch("other-new-branch-3")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Press(keys.Branches.CheckoutBranchByName)

		t.ExpectPopup().Prompt().
			Title(Equals("Branch name:")).
			Type("branch-to").
			SuggestionTopLines(Contains("branch-to-checkout")).
			ConfirmFirstSuggestion()

		t.Git().CurrentBranchName("branch-to-checkout")
	},
})
View Source
var UnsetUpstream = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Unset upstream of selected branch, both when it exists and when it doesn't",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.
			EmptyCommit("one").
			NewBranch("branch_to_remove").
			Checkout("master").
			CloneIntoRemote("origin").
			SetBranchUpstream("master", "origin/master").
			SetBranchUpstream("branch_to_remove", "origin/branch_to_remove").
			RunCommand([]string{"git", "push", "origin", "--delete", "branch_to_remove"})
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Press(keys.Universal.NextScreenMode).
			SelectedLines(
				Contains("master").Contains("origin master"),
			).
			Press(keys.Branches.SetUpstream).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Upstream options")).
					Select(Contains("Unset upstream of selected branch")).
					Confirm()
			}).
			SelectedLines(
				Contains("master").DoesNotContain("origin master"),
			)

		t.Views().Branches().
			Focus().
			SelectNextItem().
			SelectedLines(
				Contains("branch_to_remove").Contains("origin branch_to_remove").Contains("upstream gone"),
			).
			Press(keys.Branches.SetUpstream).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Upstream options")).
					Select(Contains("Unset upstream of selected branch")).
					Confirm()
			}).
			SelectedLines(
				Contains("branch_to_remove").DoesNotContain("origin branch_to_remove").DoesNotContain("upstream gone"),
			)
	},
})

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