summaryrefslogtreecommitdiffstats
path: root/pkg/integration/tests/branch/checkout_by_name_remote.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2024-03-09 13:36:44 +1100
committerJesse Duffield <jessedduffield@gmail.com>2024-03-09 13:53:14 +1100
commit4a07e037016d90a62b3a99765a1f687909f0c748 (patch)
tree3e1ab3e14bcdf5e03e6d579dc98c60ea9c92e437 /pkg/integration/tests/branch/checkout_by_name_remote.go
parent44f553b6093c69d09718f617e0a7659c64f51015 (diff)
Local-ise remote branches when checking out by namecheckout-by-name
The idea here is that in the git CLI you will often want to checkout a remote branch like origin/blah by doing `git checkout blah`. That will automatically create a local branch named blah that tracks origin/blah. Previously in the suggestions view when checking out a branch by name, we would only show local branches and remote branches like origin/blah but wouldn't show blah as an option (assuming no local branch existed with that name). This meant users would checkout origin/blah and git would check out that branch as a detached head which is rarely what you actually want. Now we give them both options. The alternative approach we could have taken is to still show the branch as origin/blah but then ask if the user wants to check out the branch as detached or as a local branch tracking the remote branch. That approach is certainly more versatile, but it's also something you can do already by going to the remote branch directly via the remotes view. Admittedly, my approach involves less work.
Diffstat (limited to 'pkg/integration/tests/branch/checkout_by_name_remote.go')
-rw-r--r--pkg/integration/tests/branch/checkout_by_name_remote.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/pkg/integration/tests/branch/checkout_by_name_remote.go b/pkg/integration/tests/branch/checkout_by_name_remote.go
new file mode 100644
index 000000000..cd9d01db6
--- /dev/null
+++ b/pkg/integration/tests/branch/checkout_by_name_remote.go
@@ -0,0 +1,66 @@
+package branch
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var CheckoutByNameRemote = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Checkout a remote branch by name, both using the full name and the local name.",
+ ExtraCmdArgs: []string{},
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.EmptyCommit("initial commit")
+ // create an origin/foo remote branch
+ shell.CloneIntoRemote("origin")
+ shell.NewBranch("foo")
+ shell.PushBranch("origin", "foo")
+ // delete the local version of the branch because we need to test checking it out from scratch
+ shell.Checkout("master")
+ shell.DeleteBranch("foo")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Branches().
+ Focus().
+ Lines(
+ Contains("master").IsSelected(),
+ ).
+ // maximising window so that we can see the tracked branch
+ Press(keys.Universal.NextScreenMode).
+ Press(keys.Branches.CheckoutBranchByName).
+ Tap(func() {
+ t.ExpectPopup().Prompt().
+ Title(Equals("Branch name:")).
+ Type("foo").
+ SuggestionLines(
+ Contains("foo"),
+ Contains("origin/foo"),
+ ).
+ ConfirmFirstSuggestion()
+ }).
+ Lines(
+ Contains("foo").
+ // we have not checked out origin/foo...
+ DoesNotContain("origin/foo").
+ // ... but we are tracking it (formatted as '<remote> <branch>')
+ Contains("origin foo"),
+ Contains("master"),
+ ).
+ Press(keys.Branches.CheckoutBranchByName).
+ Tap(func() {
+ t.ExpectPopup().Prompt().
+ Title(Equals("Branch name:")).
+ Type("origin/foo").
+ SuggestionLines(
+ Contains("origin/foo"),
+ ).
+ ConfirmFirstSuggestion()
+ }).
+ Lines(
+ Contains("HEAD detached at origin/foo"),
+ Contains("foo"),
+ Contains("master"),
+ )
+ },
+})