1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-29 22:48:24 +02:00

Add no-ff merge option

This will put whatever git's default merge variant is as the first menu item,
and add a second item which is the opposite (no-ff if the default is ff, and
vice versa).

If users prefer to always have the same option first no matter whether it's
applicable, they can make ff always appear first by setting git's "merge.ff"
config to "true" or "only", or by setting lazygit's "git.merging.args" config to
"--ff" or "--ff-only"; if they want no-ff to appear first, they can do that by
setting git's "merge.ff" config to "false", or by setting lazygit's
"git.merging.args" config to "--no-ff". Which of these they choose depends on
whether they want the config to also apply to other git clients including the
cli, or only to lazygit.
This commit is contained in:
Stefan Haller
2025-10-15 14:59:04 +02:00
parent c88381b9ce
commit 62854026a3
8 changed files with 275 additions and 19 deletions

View File

@@ -0,0 +1,68 @@
package branch
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var MergeFastForward = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Merge a branch into another using fast-forward merge",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Git.LocalBranchSortOrder = "alphabetical"
},
SetupRepo: func(shell *Shell) {
shell.NewBranch("original-branch").
EmptyCommit("one").
NewBranch("branch1").
EmptyCommit("branch1").
Checkout("original-branch").
NewBranchFrom("branch2", "original-branch").
EmptyCommit("branch2").
Checkout("original-branch")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Focus().
Lines(
Contains("original-branch").IsSelected(),
Contains("branch1"),
Contains("branch2"),
).
SelectNextItem().
Press(keys.Branches.MergeIntoCurrentBranch)
t.ExpectPopup().Menu().
Title(Equals("Merge")).
TopLines(
Contains("Regular merge (fast-forward)"),
Contains("Regular merge (with merge commit)"),
).
Select(Contains("Regular merge (fast-forward)")).
Confirm()
t.Views().Commits().
Lines(
Contains("branch1").IsSelected(),
Contains("one"),
)
// Check that branch2 can't be merged using fast-forward
t.Views().Branches().
Focus().
NavigateToLine(Contains("branch2")).
Press(keys.Branches.MergeIntoCurrentBranch)
t.ExpectPopup().Menu().
Title(Equals("Merge")).
TopLines(
Contains("Regular merge (with merge commit)"),
Contains("Regular merge (fast-forward)"),
).
Select(Contains("Regular merge (fast-forward)")).
Confirm()
t.ExpectToast(Contains("Cannot fast-forward 'original-branch' to 'branch2'"))
},
})

View File

@@ -0,0 +1,76 @@
package branch
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var MergeNonFastForward = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Merge a branch into another using non-fast-forward merge",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Git.LocalBranchSortOrder = "alphabetical"
},
SetupRepo: func(shell *Shell) {
shell.NewBranch("original-branch").
EmptyCommit("one").
NewBranch("branch1").
EmptyCommit("branch1").
Checkout("original-branch").
NewBranchFrom("branch2", "original-branch").
EmptyCommit("branch2").
Checkout("original-branch")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Focus().
Lines(
Contains("original-branch").IsSelected(),
Contains("branch1"),
Contains("branch2"),
).
SelectNextItem().
Press(keys.Branches.MergeIntoCurrentBranch)
t.ExpectPopup().Menu().
Title(Equals("Merge")).
TopLines(
Contains("Regular merge (fast-forward)"),
Contains("Regular merge (with merge commit)"),
).
Select(Contains("Regular merge (with merge commit)")).
Confirm()
t.Views().Commits().
Lines(
Contains("⏣─╮ Merge branch 'branch1' into original-branch").IsSelected(),
Contains("│ ◯ * branch1"),
Contains("◯─╯ one"),
)
// Check that branch2 shows the non-fast-forward option first
t.Views().Branches().
Focus().
NavigateToLine(Contains("branch2")).
Press(keys.Branches.MergeIntoCurrentBranch)
t.ExpectPopup().Menu().
Title(Equals("Merge")).
TopLines(
Contains("Regular merge (with merge commit)"),
Contains("Regular merge (fast-forward)"),
).
Select(Contains("Regular merge (with merge commit)")).
Confirm()
t.Views().Commits().
Lines(
Contains("⏣─╮ Merge branch 'branch2' into original-branch").IsSelected(),
Contains("│ ◯ * branch2"),
Contains("⏣─│─╮ Merge branch 'branch1' into original-branch"),
Contains("│ │ ◯ * branch1"),
Contains("◯─┴─╯ one"),
)
},
})

View File

@@ -48,6 +48,8 @@ var tests = []*components.IntegrationTest{
branch.DeleteRemoteBranchWithDifferentName,
branch.DeleteWhileFiltering,
branch.DetachedHead,
branch.MergeFastForward,
branch.MergeNonFastForward,
branch.MoveCommitsToNewBranchFromBaseBranch,
branch.MoveCommitsToNewBranchFromMainBranch,
branch.MoveCommitsToNewBranchKeepStacked,

View File

@@ -103,7 +103,7 @@ var ModeSpecificKeybindingSuggestions = NewIntegrationTest(NewIntegrationTestArg
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Merge")).
Select(Contains("Regular merge")).
Select(Contains("Regular merge (with merge commit)")).
Confirm()
t.Common().AcknowledgeConflicts()