]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'vv/merge-squash-with-explicit-commit' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 25 Jul 2019 21:27:10 +0000 (14:27 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Jul 2019 21:27:10 +0000 (14:27 -0700)
"git merge --squash" is designed to update the working tree and the
index without creating the commit, and this cannot be countermanded
by adding the "--commit" option; the command now refuses to work
when both options are given.

* vv/merge-squash-with-explicit-commit:
  merge: refuse --commit with --squash

Documentation/merge-options.txt
builtin/merge.c
t/t7600-merge.sh

index 61876dbc335e240b8842aba3dd4e3fd8a54e574a..79a00d2a4abd6f7191f2639185e199fa85f6289b 100644 (file)
@@ -102,6 +102,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 e96f72af8044769df6b4ef42f0525b572b0c39e2..57c2a24f6d82fc7cedcc86979db6ff1a8fa6bc50 100644 (file)
@@ -58,7 +58,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;
@@ -1339,9 +1339,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 7f9c68cbe75a688357e6c71486c3897861421681..4ec5d9ec790a0d54f4883fc118b5df25c94f43f4 100755 (executable)
@@ -570,6 +570,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