From 519c0dcc9749382343f8f80487c9c28d1d206b12 Mon Sep 17 00:00:00 2001 From: Philippe Miossec Date: Sat, 13 Jul 2019 22:37:02 +0200 Subject: [PATCH] Add support for "--rebase-merges" for newest version of git now that we recommend v2.22 (#6769) that deprecate "--preserve-merges" See: * for option deprection: https://github.com/git/git/commit/fa1b86e45743fd5895c33adcd3769782e608bb40#diff-c7361e406139e8cd3a300b80b8f8cc8dR1220 * for some doc: https://stackoverflow.com/questions/15915430/what-exactly-does-gits-rebase-preserve-merges-do-and-why/50555740#50555740 --- GitCommands/Git/GitCommandHelpers.cs | 2 +- GitCommands/Git/GitVersion.cs | 3 +++ UnitTests/GitCommandsTests/Git/GitCommandHelpersTest.cs | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/GitCommands/Git/GitCommandHelpers.cs b/GitCommands/Git/GitCommandHelpers.cs index 4dd478af9b7..8935b81c306 100644 --- a/GitCommands/Git/GitCommandHelpers.cs +++ b/GitCommands/Git/GitCommandHelpers.cs @@ -403,7 +403,7 @@ public static ArgumentString RebaseCmd(string branch, bool interactive, bool pre { interactive, "-i" }, { interactive && autosquash, "--autosquash" }, { interactive && !autosquash, "--no-autosquash" }, - { preserveMerges, "--preserve-merges" }, + { preserveMerges, GitVersion.Current.SupportRebaseMerges ? "--rebase-merges" : "--preserve-merges" }, { autoStash, "--autostash" }, from.QuoteNE(), branch.Quote(), diff --git a/GitCommands/Git/GitVersion.cs b/GitCommands/Git/GitVersion.cs index ec9c766a9a8..cf9e2fb04d0 100644 --- a/GitCommands/Git/GitVersion.cs +++ b/GitCommands/Git/GitVersion.cs @@ -19,6 +19,7 @@ public class GitVersion : IComparable private static readonly GitVersion v2_11_0 = new GitVersion("2.11.0"); private static readonly GitVersion v2_15_0 = new GitVersion("2.15.0"); private static readonly GitVersion v2_15_2 = new GitVersion("2.15.2"); + private static readonly GitVersion v2_19_0 = new GitVersion("2.19.0"); public static readonly GitVersion LastSupportedVersion = v2_11_0; public static readonly GitVersion LastRecommendedVersion = new GitVersion("2.22.0"); @@ -124,6 +125,8 @@ int Get(IReadOnlyList values, int index) public bool SupportNoOptionalLocks => this >= v2_15_2; + public bool SupportRebaseMerges => this >= v2_19_0; + public bool IsUnknown => _a == 0 && _b == 0 && _c == 0 && _d == 0; // Returns true if it's possible to pass given string as command line diff --git a/UnitTests/GitCommandsTests/Git/GitCommandHelpersTest.cs b/UnitTests/GitCommandsTests/Git/GitCommandHelpersTest.cs index 4be3fa8790c..eddc264ac9b 100644 --- a/UnitTests/GitCommandsTests/Git/GitCommandHelpersTest.cs +++ b/UnitTests/GitCommandsTests/Git/GitCommandHelpersTest.cs @@ -605,7 +605,7 @@ public void RebaseCmd() "-c rebase.autoSquash=false rebase -i --no-autosquash \"branch\"", GitCommandHelpers.RebaseCmd("branch", interactive: true, preserveMerges: false, autosquash: false, autoStash: false).Arguments); Assert.AreEqual( - "-c rebase.autoSquash=false rebase --preserve-merges \"branch\"", + GitVersion.Current.SupportRebaseMerges ? "-c rebase.autoSquash=false rebase --rebase-merges \"branch\"" : "-c rebase.autoSquash=false rebase --preserve-merges \"branch\"", GitCommandHelpers.RebaseCmd("branch", interactive: false, preserveMerges: true, autosquash: false, autoStash: false).Arguments); Assert.AreEqual( "-c rebase.autoSquash=false rebase \"branch\"", @@ -617,7 +617,7 @@ public void RebaseCmd() "-c rebase.autoSquash=false rebase -i --autosquash \"branch\"", GitCommandHelpers.RebaseCmd("branch", interactive: true, preserveMerges: false, autosquash: true, autoStash: false).Arguments); Assert.AreEqual( - "-c rebase.autoSquash=false rebase -i --autosquash --preserve-merges --autostash \"branch\"", + GitVersion.Current.SupportRebaseMerges ? "-c rebase.autoSquash=false rebase -i --autosquash --rebase-merges --autostash \"branch\"" : "-c rebase.autoSquash=false rebase -i --autosquash --preserve-merges --autostash \"branch\"", GitCommandHelpers.RebaseCmd("branch", interactive: true, preserveMerges: true, autosquash: true, autoStash: true).Arguments); // TODO quote 'onto'?