Skip to content

Commit 6e0b1c6

Browse files
committed
Merge branch 'vv/merge-squash-with-explicit-commit'
"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
2 parents 3a54d80 + 1d14d0c commit 6e0b1c6

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Documentation/merge-options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ merge.
102102
+
103103
With --no-squash perform the merge and commit the result. This
104104
option can be used to override --squash.
105+
+
106+
With --squash, --commit is not allowed, and will fail.
105107

106108
-s <strategy>::
107109
--strategy=<strategy>::

builtin/merge.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static const char * const builtin_merge_usage[] = {
5959
};
6060

6161
static int show_diffstat = 1, shortlog_len = -1, squash;
62-
static int option_commit = 1;
62+
static int option_commit = -1;
6363
static int option_edit = -1;
6464
static int allow_trivial = 1, have_message, verify_signatures;
6565
static int overwrite_ignore = 1;
@@ -1345,9 +1345,19 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13451345
if (squash) {
13461346
if (fast_forward == FF_NO)
13471347
die(_("You cannot combine --squash with --no-ff."));
1348+
if (option_commit > 0)
1349+
die(_("You cannot combine --squash with --commit."));
1350+
/*
1351+
* squash can now silently disable option_commit - this is not
1352+
* a problem as it is only overriding the default, not a user
1353+
* supplied option.
1354+
*/
13481355
option_commit = 0;
13491356
}
13501357

1358+
if (option_commit < 0)
1359+
option_commit = 1;
1360+
13511361
if (!argc) {
13521362
if (default_to_upstream)
13531363
argc = setup_with_upstream(&argv);

t/t7600-merge.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,12 @@ test_expect_success 'combining --squash and --no-ff is refused' '
570570
test_must_fail git merge --no-ff --squash c1
571571
'
572572

573+
test_expect_success 'combining --squash and --commit is refused' '
574+
git reset --hard c0 &&
575+
test_must_fail git merge --squash --commit c1 &&
576+
test_must_fail git merge --commit --squash c1
577+
'
578+
573579
test_expect_success 'option --ff-only overwrites --no-ff' '
574580
git merge --no-ff --ff-only c1 &&
575581
test_must_fail git merge --no-ff --ff-only c2

0 commit comments

Comments
 (0)