Skip to content

Commit a0cddae

Browse files
committed
feature: support --ff-only option for git merge command
Signed-off-by: leo <[email protected]>
1 parent 2b95ea2 commit a0cddae

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

src/Models/MergeMode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public class MergeMode
55
public static readonly MergeMode[] Supported =
66
[
77
new MergeMode("Default", "Fast-forward if possible", ""),
8+
new MergeMode("Fast-forward", "Refuse to merge when fast-forward is not possible", "--ff-only"),
89
new MergeMode("No Fast-forward", "Always create a merge commit", "--no-ff"),
910
new MergeMode("Squash", "Squash merge", "--squash"),
1011
new MergeMode("Don't commit", "Merge without commit", "--no-ff --no-commit"),

src/ViewModels/Histories.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ private void FillCurrentBranchMenu(ContextMenu menu, Models.Branch current)
871871
return;
872872

873873
if (_repo.CanCreatePopup())
874-
_repo.ShowAndStartPopup(new Merge(_repo, b, current.Name));
874+
_repo.ShowAndStartPopup(new Merge(_repo, b, current.Name, true));
875875

876876
e.Handled = true;
877877
};
@@ -972,7 +972,7 @@ private void FillOtherLocalBranchMenu(ContextMenu menu, Models.Branch branch, Mo
972972
merge.Click += (_, e) =>
973973
{
974974
if (_repo.CanCreatePopup())
975-
_repo.ShowPopup(new Merge(_repo, branch, current.Name));
975+
_repo.ShowPopup(new Merge(_repo, branch, current.Name, false));
976976
e.Handled = true;
977977
};
978978
submenu.Items.Add(merge);
@@ -1060,7 +1060,7 @@ private void FillRemoteBranchMenu(ContextMenu menu, Models.Branch branch, Models
10601060
merge.Click += (_, e) =>
10611061
{
10621062
if (_repo.CanCreatePopup())
1063-
_repo.ShowPopup(new Merge(_repo, branch, current.Name));
1063+
_repo.ShowPopup(new Merge(_repo, branch, current.Name, false));
10641064
e.Handled = true;
10651065
};
10661066

src/ViewModels/Merge.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public Models.MergeMode Mode
2121
set;
2222
}
2323

24-
public Merge(Repository repo, Models.Branch source, string into)
24+
public Merge(Repository repo, Models.Branch source, string into, bool forceFastForward)
2525
{
2626
_repo = repo;
2727
_sourceName = source.FriendlyName;
2828

2929
Source = source;
3030
Into = into;
31-
Mode = AutoSelectMergeMode();
31+
Mode = forceFastForward ? Models.MergeMode.Supported[1] : AutoSelectMergeMode();
3232
View = new Views.Merge() { DataContext = this };
3333
}
3434

@@ -72,12 +72,14 @@ private Models.MergeMode AutoSelectMergeMode()
7272
var config = new Commands.Config(_repo.FullPath).Get($"branch.{Into}.mergeoptions");
7373
if (string.IsNullOrEmpty(config))
7474
return Models.MergeMode.Supported[0];
75-
if (config.Equals("--no-ff", StringComparison.Ordinal))
75+
if (config.Equals("--ff-only", StringComparison.Ordinal))
7676
return Models.MergeMode.Supported[1];
77-
if (config.Equals("--squash", StringComparison.Ordinal))
77+
if (config.Equals("--no-ff", StringComparison.Ordinal))
7878
return Models.MergeMode.Supported[2];
79-
if (config.Equals("--no-commit", StringComparison.Ordinal) || config.Equals("--no-ff --no-commit", StringComparison.Ordinal))
79+
if (config.Equals("--squash", StringComparison.Ordinal))
8080
return Models.MergeMode.Supported[3];
81+
if (config.Equals("--no-commit", StringComparison.Ordinal) || config.Equals("--no-ff --no-commit", StringComparison.Ordinal))
82+
return Models.MergeMode.Supported[4];
8183

8284
return Models.MergeMode.Supported[0];
8385
}

src/ViewModels/Repository.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ public ContextMenu CreateContextMenuForLocalBranch(Models.Branch branch)
15161516
return;
15171517

15181518
if (CanCreatePopup())
1519-
ShowAndStartPopup(new Merge(this, b, branch.Name));
1519+
ShowAndStartPopup(new Merge(this, b, branch.Name, true));
15201520

15211521
e.Handled = true;
15221522
};
@@ -1595,7 +1595,7 @@ public ContextMenu CreateContextMenuForLocalBranch(Models.Branch branch)
15951595
merge.Click += (_, e) =>
15961596
{
15971597
if (CanCreatePopup())
1598-
ShowPopup(new Merge(this, branch, _currentBranch.Name));
1598+
ShowPopup(new Merge(this, branch, _currentBranch.Name, false));
15991599
e.Handled = true;
16001600
};
16011601

@@ -1876,7 +1876,7 @@ public ContextMenu CreateContextMenuForRemoteBranch(Models.Branch branch)
18761876
merge.Click += (_, e) =>
18771877
{
18781878
if (CanCreatePopup())
1879-
ShowPopup(new Merge(this, branch, _currentBranch.Name));
1879+
ShowPopup(new Merge(this, branch, _currentBranch.Name, false));
18801880
e.Handled = true;
18811881
};
18821882

0 commit comments

Comments
 (0)