Skip to content

Commit 33f2790

Browse files
committed
Merge branch 'vv/merge-squash-with-explicit-commit' into maint
"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 abbd504 + 1d14d0c commit 33f2790

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
@@ -58,7 +58,7 @@ static const char * const builtin_merge_usage[] = {
5858
};
5959

6060
static int show_diffstat = 1, shortlog_len = -1, squash;
61-
static int option_commit = 1;
61+
static int option_commit = -1;
6262
static int option_edit = -1;
6363
static int allow_trivial = 1, have_message, verify_signatures;
6464
static int overwrite_ignore = 1;
@@ -1339,9 +1339,19 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13391339
if (squash) {
13401340
if (fast_forward == FF_NO)
13411341
die(_("You cannot combine --squash with --no-ff."));
1342+
if (option_commit > 0)
1343+
die(_("You cannot combine --squash with --commit."));
1344+
/*
1345+
* squash can now silently disable option_commit - this is not
1346+
* a problem as it is only overriding the default, not a user
1347+
* supplied option.
1348+
*/
13421349
option_commit = 0;
13431350
}
13441351

1352+
if (option_commit < 0)
1353+
option_commit = 1;
1354+
13451355
if (!argc) {
13461356
if (default_to_upstream)
13471357
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)