git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] merge: do not contaminate option_commit with --squash

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 26, 2016, 21:32 UTC
Message-ID
<xmqqk2jkdpjr.fsf_-_@gitster.mtv.corp.google.com>
In-Reply-To
<xmqqtwiy6end.fsf@gitster.mtv.corp.google.com>

It is true that we do not make a commit when we are asked to do "merge --squash", and the code does so by setting option_commit variable to zero when seeing the squash option. But this made it impossible to see from the value of option_commit if --no-commit was given from the command line, or --squash turned it off.

We check for the value of option_commit at only two places. Check for the value of squash at them, too.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * Just a preliminary clean-up for the next one which is on topic.
 builtin/merge.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index bf2f261..de9d1b6 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1237,11 +1237,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	if (verbosity < 0)
 		show_diffstat = 0;
 
-	if (squash) {
-		if (fast_forward == FF_NO)
-			die(_("You cannot combine --squash with --no-ff."));
-		option_commit = 0;
-	}
+	if (squash && fast_forward == FF_NO)
+		die(_("You cannot combine --squash with --no-ff."));
 
 	if (!argc) {
 		if (default_to_upstream)
@@ -1449,10 +1446,10 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		 * We are not doing octopus and not fast-forward.  Need
 		 * a real merge.
 		 */
-	else if (!remoteheads->next && !common->next && option_commit) {
+	else if (!remoteheads->next && !common->next && option_commit && !squash)
 		/*
 		 * We are not doing octopus, not fast-forward, and have
-		 * only one common.
+		 * only one common.  And we do want to create a new commit.
 		 */
 		refresh_cache(REFRESH_QUIET);
 		if (allow_trivial && fast_forward != FF_ONLY) {
@@ -1535,7 +1532,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		ret = try_merge_strategy(use_strategies[i]->name,
 					 common, remoteheads,
 					 head_commit, head_arg);
-		if (!option_commit && !ret) {
+		if ((!option_commit || squash) && !ret) {
 			merge_was_ok = 1;
 			/*
 			 * This is necessary here just to avoid writing
-- 
2.8.1-491-g88b9e4a
Previous: Junio C HamanoNext: Johannes Schindelin
Message 9 of 21 in “git merge branch --no-commit does commit fast forward merges”
  1. Christoph PaulikApr 17, 2016
  2. Jacob KellerApr 17, 2016
  3. Johannes SchindelinApr 18, 2016
  4. Andrew ArdillApr 18, 2016
  5. Christoph PaulikApr 18, 2016
  6. Andrew ArdillApr 18, 2016
  7. Junio C HamanoApr 18, 2016
  8. Junio C HamanoApr 18, 2016
  9. 1/2 merge: do not contaminate option_commit with --squashJunio C Hamano, Apr 26, 2016
  10. Johannes SchindelinApr 27, 2016
  11. Junio C HamanoApr 27, 2016
  12. Johannes SchindelinApr 27, 2016
  13. 2/2 merge: warn --no-commit merge when no new commit is createdJunio C Hamano, Apr 26, 2016
  14. Stefan BellerApr 26, 2016
  15. Junio C HamanoApr 26, 2016
  16. Eric SunshineApr 27, 2016
  17. Johannes SixtApr 27, 2016
  18. Johannes SchindelinApr 27, 2016
  19. Junio C HamanoApr 27, 2016
  20. Johannes SchindelinApr 27, 2016
  21. Junio C HamanoApr 27, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.