mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-24 19:39:16 +02:00
Dont auto-forward branches that are checked out in another worktree (#4833)
### PR Description This is similar to #2957, except that in that case it was about an explicit fast-forward command, and we solved it by doing the fast-forward in the other work-tree (so that it would fail if that worktree had modified files, for example). In this case it is about the relatively new auto-forward feature (added in v0.50, see #4493), and in this case we fix it by not even trying to auto-forward any branches that are checked out by other worktrees.
This commit is contained in:
@@ -283,7 +283,9 @@ func (self *BranchesHelper) AutoForwardBranches() error {
|
||||
updateCommands := ""
|
||||
// The first branch is the currently checked out branch; skip it
|
||||
for _, branch := range branches[1:] {
|
||||
if branch.RemoteBranchStoredLocally() && (allBranches || lo.Contains(self.c.UserConfig().Git.MainBranches, branch.Name)) {
|
||||
if branch.RemoteBranchStoredLocally() &&
|
||||
!self.checkedOutByOtherWorktree(branch) &&
|
||||
(allBranches || lo.Contains(self.c.UserConfig().Git.MainBranches, branch.Name)) {
|
||||
isStrictlyBehind := branch.IsBehindForPull() && !branch.IsAheadForPull()
|
||||
if isStrictlyBehind {
|
||||
updateCommands += fmt.Sprintf("update %s %s %s\n", branch.FullRefName(), branch.FullUpstreamRefName(), branch.CommitHash)
|
||||
|
@@ -0,0 +1,57 @@
|
||||
package sync
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||
)
|
||||
|
||||
var FetchAndAutoForwardBranchesAllBranchesCheckedOutInOtherWorktree = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Description: "Fetch from remote and auto-forward branches with config set to 'allBranches'; check that this skips branches checked out by another worktree",
|
||||
ExtraCmdArgs: []string{},
|
||||
Skip: false,
|
||||
SetupConfig: func(config *config.AppConfig) {
|
||||
config.GetUserConfig().Git.AutoForwardBranches = "allBranches"
|
||||
config.GetUserConfig().Git.LocalBranchSortOrder = "alphabetical"
|
||||
},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.CreateNCommits(3)
|
||||
shell.NewBranch("feature")
|
||||
shell.NewBranch("diverged")
|
||||
shell.CloneIntoRemote("origin")
|
||||
shell.SetBranchUpstream("master", "origin/master")
|
||||
shell.SetBranchUpstream("feature", "origin/feature")
|
||||
shell.SetBranchUpstream("diverged", "origin/diverged")
|
||||
shell.Checkout("master")
|
||||
shell.HardReset("HEAD^")
|
||||
shell.Checkout("feature")
|
||||
shell.HardReset("HEAD~2")
|
||||
shell.Checkout("diverged")
|
||||
shell.HardReset("HEAD~2")
|
||||
shell.EmptyCommit("local")
|
||||
shell.NewBranch("checked-out")
|
||||
|
||||
shell.AddWorktreeCheckout("master", "../linked-worktree")
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
t.Views().Branches().
|
||||
Lines(
|
||||
Contains("checked-out").IsSelected(),
|
||||
Contains("diverged ↓2↑1"),
|
||||
Contains("feature ↓2").DoesNotContain("↑"),
|
||||
Contains("master (worktree) ↓1").DoesNotContain("↑"),
|
||||
)
|
||||
|
||||
t.Views().Files().
|
||||
IsFocused().
|
||||
Press(keys.Files.Fetch)
|
||||
|
||||
// AutoForwardBranches is "allBranches": both master and feature get forwarded
|
||||
t.Views().Branches().
|
||||
Lines(
|
||||
Contains("checked-out").IsSelected(),
|
||||
Contains("diverged ↓2↑1"),
|
||||
Contains("feature ✓"),
|
||||
Contains("master (worktree) ↓1"),
|
||||
)
|
||||
},
|
||||
})
|
@@ -383,6 +383,7 @@ var tests = []*components.IntegrationTest{
|
||||
submodule.Reset,
|
||||
submodule.ResetFolder,
|
||||
sync.FetchAndAutoForwardBranchesAllBranches,
|
||||
sync.FetchAndAutoForwardBranchesAllBranchesCheckedOutInOtherWorktree,
|
||||
sync.FetchAndAutoForwardBranchesNone,
|
||||
sync.FetchAndAutoForwardBranchesOnlyMainBranches,
|
||||
sync.FetchPrune,
|
||||
|
Reference in New Issue
Block a user