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

[PATCH 2/2] merge: warn --no-commit merge when no new commit is created

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

A user who uses "--no-commit" does so with the intention to record a resulting merge after amending the merge result in the working tree. But there is nothing to amend and record, if the same "git merge" without "--no-commit" wouldn't have created a merge commit (there are two cases: (1) the other branch is a descendant of the current branch, (2) the other branch is an ancestor of the current branch).

The user would want to know that before doing further damange to his history. When "merge --no-commit" fast-forwarded or succeeded with "already up-to-date" or "fast-forward", give a warning message.

We may want to turn this into a die() after a transition period.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * The necessary update to avoid end-user mistake would look like
   this.  I am not queuing this or further working on it myself,
   as I am not sure if it is all that useful.
 builtin/merge.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff --git a/builtin/merge.c b/builtin/merge.c
index f641751..66c536d 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1157,6 +1157,15 @@ static struct commit_list *collect_parents(struct commit *head_commit,
 	return remoteheads;
 }
 
+static void no_commit_impossible(const char *message)
+{
+	if (!option_commit) {
+		warning("%s\n%s", _(message),
+			_("--no-commit is impossible"));
+		warning(_("In future versions of Git, this will become an error."));
+	}
+}
+
 int cmd_merge(int argc, const char **argv, const char *prefix)
 {
 	unsigned char result_tree[20];
@@ -1403,6 +1412,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		 * If head can reach all the merge then we are up to date.
 		 * but first the most common case of merging one remote.
 		 */
+		no_commit_impossible(_("Already up-to-date"));
 		finish_up_to_date("Already up-to-date.");
 		goto done;
 	} else if (fast_forward != FF_NO && !remoteheads->next &&
@@ -1412,6 +1422,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		struct strbuf msg = STRBUF_INIT;
 		struct commit *commit;
 
+		no_commit_impossible(_("Fast-forward"));
 		if (verbosity >= 0) {
 			char from[GIT_SHA1_HEXSZ + 1], to[GIT_SHA1_HEXSZ + 1];
 			find_unique_abbrev_r(from, head_commit->object.oid.hash,
@@ -1488,6 +1499,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 			}
 		}
 		if (up_to_date) {
+			no_commit_impossible(_("Already up-to-date"));
 			finish_up_to_date("Already up-to-date. Yeeah!");
 			goto done;
 		}
-- 
2.8.1-491-g88b9e4a
Previous: Johannes SchindelinNext: Stefan Beller
Message 13 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.