git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: vishal@kernel.org
To: git@vger.kernel.org
Cc: "Vishal Verma" <vishal@stellar.sh>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Rafael Ascensão" <rafa.almas@gmail.com>
Subject: [PATCH v2] builtin/merges: clarify --squash behavior with --commit
Date: Fri, 26 Apr 2019 15:17:03 -0600	[thread overview]
Message-ID: <20190426211703.25604-1-vishal@kernel.org> (raw)
In-Reply-To: <dfc0a40233677ce0e1d9d073c41b6f0fea3bf746.camel@stellar.sh>

From: Vishal Verma <vishal@stellar.sh>

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.

Add a note to the --squash option for git-merge to clarify the
incompatibility.

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.

Cc: Junio C Hamano <gitster@pobox.com>
Cc: Rafael Ascensão <rafa.almas@gmail.com>
Signed-off-by: Vishal Verma <vishal@stellar.sh>
---

v2:
 - Error out when both --squash and --commit are supplied (Junio)
 - Adjust the documentation accordingly.

 Documentation/merge-options.txt |  2 ++
 builtin/merge.c                 | 18 +++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt
index 92a7d936c1..263b194247 100644
--- a/Documentation/merge-options.txt
+++ b/Documentation/merge-options.txt
@@ -95,6 +95,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>::
diff --git a/builtin/merge.c b/builtin/merge.c
index 5ce8946d39..98f268ac57 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -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,25 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	if (verbosity < 0)
 		show_diffstat = 0;
 
+	/*
+	 * This indicates option_commit was influenced by the command line.
+	 * Check and error out for the squash case.
+	 */
+	if ((option_commit > 0) && squash)
+		die(_("You cannot combine --squash with --commit."));
+
+	/* If option_commit is the default '-1', we can 'enable' it */
+	if (option_commit < 0)
+		option_commit = 1;
+
 	if (squash) {
 		if (fast_forward == FF_NO)
 			die(_("You cannot combine --squash with --no-ff."));
+		/*
+		 * 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;
 	}
 
-- 
2.20.1


      reply	other threads:[~2019-04-26 21:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24 21:22 [PATCH] Documentation/merge-options: clarify --squash behavior Vishal Verma
2019-04-25  4:16 ` Junio C Hamano
2019-04-25 16:26   ` Vishal Verma
2019-04-26 21:17     ` vishal [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190426211703.25604-1-vishal@kernel.org \
    --to=vishal@kernel.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=rafa.almas@gmail.com \
    --cc=vishal@stellar.sh \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).