Skip to content

Commit ba5a8a8

Browse files
stefanhallerkarolzwolak
authored andcommitted
Add test for auto-forwarding branches that are checked out by another worktree
The test shows that we are currently auto-forwarding branches even if they are checked out by another worktree; this is quite bad, because when you switch to that other worktree you'll see that the files that are touched by the fetched commits are all modified (which we don't test here).
1 parent 9db64ce commit ba5a8a8

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package sync
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var FetchAndAutoForwardBranchesAllBranchesCheckedOutInOtherWorktree = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Fetch from remote and auto-forward branches with config set to 'allBranches'; check that this skips branches checked out by another worktree",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
config.GetUserConfig().Git.AutoForwardBranches = "allBranches"
14+
config.GetUserConfig().Git.LocalBranchSortOrder = "alphabetical"
15+
},
16+
SetupRepo: func(shell *Shell) {
17+
shell.CreateNCommits(3)
18+
shell.NewBranch("feature")
19+
shell.NewBranch("diverged")
20+
shell.CloneIntoRemote("origin")
21+
shell.SetBranchUpstream("master", "origin/master")
22+
shell.SetBranchUpstream("feature", "origin/feature")
23+
shell.SetBranchUpstream("diverged", "origin/diverged")
24+
shell.Checkout("master")
25+
shell.HardReset("HEAD^")
26+
shell.Checkout("feature")
27+
shell.HardReset("HEAD~2")
28+
shell.Checkout("diverged")
29+
shell.HardReset("HEAD~2")
30+
shell.EmptyCommit("local")
31+
shell.NewBranch("checked-out")
32+
33+
shell.AddWorktreeCheckout("master", "../linked-worktree")
34+
},
35+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
36+
t.Views().Branches().
37+
Lines(
38+
Contains("checked-out").IsSelected(),
39+
Contains("diverged ↓2↑1"),
40+
Contains("feature ↓2").DoesNotContain("↑"),
41+
Contains("master (worktree) ↓1").DoesNotContain("↑"),
42+
)
43+
44+
t.Views().Files().
45+
IsFocused().
46+
Press(keys.Files.Fetch)
47+
48+
// AutoForwardBranches is "allBranches": both master and feature get forwarded
49+
t.Views().Branches().
50+
Lines(
51+
Contains("checked-out").IsSelected(),
52+
Contains("diverged ↓2↑1"),
53+
Contains("feature ✓"),
54+
/* EXPECTED:
55+
Contains("master (worktree) ↓1"),
56+
ACTUAL: */
57+
Contains("master (worktree) ✓"),
58+
)
59+
},
60+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ var tests = []*components.IntegrationTest{
383383
submodule.Reset,
384384
submodule.ResetFolder,
385385
sync.FetchAndAutoForwardBranchesAllBranches,
386+
sync.FetchAndAutoForwardBranchesAllBranchesCheckedOutInOtherWorktree,
386387
sync.FetchAndAutoForwardBranchesNone,
387388
sync.FetchAndAutoForwardBranchesOnlyMainBranches,
388389
sync.FetchPrune,

0 commit comments

Comments
 (0)