Add a test for fast-forwarding a branch being rebased in a worktree

If a branch is being rebased in a worktree, pressing `f` on it moves
the detached HEAD of that worktree instead of the branch. The upstream
commits end up in the rebase in progress, and the branch itself stays
where it was. The same happens for a branch being bisected.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-09-27 11:00:36 +02:00
co-authored by Claude Opus 5.5
parent 9183269ee8
commit 5990946a23
2 changed files with 70 additions and 0 deletions
@@ -0,0 +1,69 @@
package sync
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var FastForwardBranchBeingRebasedInWorktree = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Try to fast-forward a branch that is being rebased in another worktree",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("file", "content")
shell.Commit("one")
shell.EmptyCommit("two")
shell.EmptyCommit("three")
shell.CloneIntoRemote("origin")
shell.SetBranchUpstream("master", "origin/master")
// remove a commit so that there is something to fast-forward to
shell.HardReset("HEAD~1")
shell.NewBranch("other")
shell.AddWorktreeCheckout("master", "../linked-worktree")
// the failing exec stops the rebase after picking "two", with HEAD
// detached from master
shell.RunCommandExpectError([]string{"git", "-C", "../linked-worktree", "rebase", "--exec", "false", "HEAD~1"})
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Focus().
Lines(
Contains("other").IsSelected(),
Contains("master (worktree linked-worktree) ↓1"),
).
NavigateToLine(Contains("master")).
Press(keys.Branches.FastForward)
/* EXPECTED:
t.ExpectPopup().Alert().
Title(Equals("Error")).
Content(Equals("Cannot fast-forward 'master' because it is being rebased or bisected in worktree linked-worktree")).
Confirm()
ACTUAL: */
t.Views().Worktrees().
Focus().
NavigateToLine(Contains("linked-worktree")).
Press(keys.Universal.Select)
t.Views().Information().Content(Contains("Rebasing"))
t.Views().Commits().
Lines(
Contains("─── Pending rebase todos"),
Contains("─── Commits"),
/* EXPECTED:
Contains("two"),
Contains("one"),
ACTUAL: */
Contains("three"),
Contains("two"),
Contains("one"),
)
},
})
+1
View File
@@ -477,6 +477,7 @@ var tests = []*components.IntegrationTest{
sync.FastForwardBehindBranch,
sync.FastForwardBehindBranchCheckedOut,
sync.FastForwardBehindBranchWithoutReflogs,
sync.FastForwardBranchBeingRebasedInWorktree,
sync.FastForwardRewrittenBranch,
sync.FastForwardRewrittenBranchCheckedOut,
sync.FastForwardRewrittenBranchWithLocalCommits,