Skip to content

Commit 1d14d0c

Browse files
stellarhoppergitster
authored andcommitted
merge: refuse --commit with --squash
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 <[email protected]> Cc: Rafael Ascensão <[email protected]> Cc: Johannes Schindelin <[email protected]> Signed-off-by: Vishal Verma <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aeb582a commit 1d14d0c

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
@@ -90,6 +90,8 @@ merge.
9090
+
9191
With --no-squash perform the merge and commit the result. This
9292
option can be used to override --squash.
93+
+
94+
With --squash, --commit is not allowed, and will fail.
9395

9496
-s <strategy>::
9597
--strategy=<strategy>::

builtin/merge.c

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

5959
static int show_diffstat = 1, shortlog_len = -1, squash;
60-
static int option_commit = 1;
60+
static int option_commit = -1;
6161
static int option_edit = -1;
6262
static int allow_trivial = 1, have_message, verify_signatures;
6363
static int overwrite_ignore = 1;
@@ -1304,9 +1304,19 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13041304
if (squash) {
13051305
if (fast_forward == FF_NO)
13061306
die(_("You cannot combine --squash with --no-ff."));
1307+
if (option_commit > 0)
1308+
die(_("You cannot combine --squash with --commit."));
1309+
/*
1310+
* squash can now silently disable option_commit - this is not
1311+
* a problem as it is only overriding the default, not a user
1312+
* supplied option.
1313+
*/
13071314
option_commit = 0;
13081315
}
13091316

1317+
if (option_commit < 0)
1318+
option_commit = 1;
1319+
13101320
if (!argc) {
13111321
if (default_to_upstream)
13121322
argc = setup_with_upstream(&argv);

t/t7600-merge.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,12 @@ test_expect_success 'combining --squash and --no-ff is refused' '
525525
test_must_fail git merge --no-ff --squash c1
526526
'
527527

528+
test_expect_success 'combining --squash and --commit is refused' '
529+
git reset --hard c0 &&
530+
test_must_fail git merge --squash --commit c1 &&
531+
test_must_fail git merge --commit --squash c1
532+
'
533+
528534
test_expect_success 'option --ff-only overwrites --no-ff' '
529535
git merge --no-ff --ff-only c1 &&
530536
test_must_fail git merge --no-ff --ff-only c2

0 commit comments

Comments
 (0)