]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge: refuse --commit with --squash
authorVishal Verma <vishal@stellar.sh>
Fri, 24 May 2019 18:36:17 +0000 (12:36 -0600)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 May 2019 18:53:11 +0000 (11:53 -0700)
Convert option_commit to tristate, representing the states of
'default/untouched', 'enabled-by-cli', 'disabled-by-cli'. With this in
place, check whether option_commit was enabled by cli when squashing a
merge. If so, error out, as this is not supported.

Previously, when --squash was supplied, 'option_commit' was silently
dropped. This could have been surprising to a user who tried to override
the no-commit behavior of squash using --commit explicitly.

Add a note to the --squash option for git-merge to clarify the
incompatibility, and add a test case to t7600-merge.sh

Cc: Junio C Hamano <gitster@pobox.com>
Cc: Rafael Ascensão <rafa.almas@gmail.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Vishal Verma <vishal@stellar.sh>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/merge-options.txt
builtin/merge.c
t/t7600-merge.sh

index 63a3fc09548abe8d34faab98f183e1817b21b878..a147d436ed38dfbc8154df63b39a25e7be59bac9 100644 (file)
@@ -90,6 +90,8 @@ merge.
 +
 With --no-squash perform the merge and commit the result. This
 option can be used to override --squash.
++
+With --squash, --commit is not allowed, and will fail.
 
 -s <strategy>::
 --strategy=<strategy>::
index e47d77baeebe888cfb67f8e03804ffc3ee3715c0..18b90913d83df4e6380f1de82320c5b61651cc42 100644 (file)
@@ -57,7 +57,7 @@ static const char * const builtin_merge_usage[] = {
 };
 
 static int show_diffstat = 1, shortlog_len = -1, squash;
-static int option_commit = 1;
+static int option_commit = -1;
 static int option_edit = -1;
 static int allow_trivial = 1, have_message, verify_signatures;
 static int overwrite_ignore = 1;
@@ -1304,9 +1304,19 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        if (squash) {
                if (fast_forward == FF_NO)
                        die(_("You cannot combine --squash with --no-ff."));
+               if (option_commit > 0)
+                       die(_("You cannot combine --squash with --commit."));
+               /*
+                * squash can now silently disable option_commit - this is not
+                * a problem as it is only overriding the default, not a user
+                * supplied option.
+                */
                option_commit = 0;
        }
 
+       if (option_commit < 0)
+               option_commit = 1;
+
        if (!argc) {
                if (default_to_upstream)
                        argc = setup_with_upstream(&argv);
index 106148254d0ce067e8f5f842faac8fbf1ee90f15..eeb2222b4a45784cd7b4bfb4924376280eb7762a 100755 (executable)
@@ -525,6 +525,12 @@ test_expect_success 'combining --squash and --no-ff is refused' '
        test_must_fail git merge --no-ff --squash c1
 '
 
+test_expect_success 'combining --squash and --commit is refused' '
+       git reset --hard c0 &&
+       test_must_fail git merge --squash --commit c1 &&
+       test_must_fail git merge --commit --squash c1
+'
+
 test_expect_success 'option --ff-only overwrites --no-ff' '
        git merge --no-ff --ff-only c1 &&
        test_must_fail git merge --no-ff --ff-only c2