All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Andrew Ardill <andrew.ardill@gmail.com>
Cc: Christoph Paulik <cpaulik@gmail.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	"git\@vger.kernel.org" <git@vger.kernel.org>
Subject: [PATCH 2/2] merge: warn --no-commit merge when no new commit is created
Date: Tue, 26 Apr 2016 14:37:31 -0700	[thread overview]
Message-ID: <xmqqd1pcdpb8.fsf_-_@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <xmqqtwiy6end.fsf@gitster.mtv.corp.google.com> (Junio C. Hamano's message of "Mon, 18 Apr 2016 09:54:46 -0700")

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

  parent reply	other threads:[~2016-04-26 21:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-17 21:10 git merge branch --no-commit does commit fast forward merges Christoph Paulik
2016-04-17 23:52 ` Jacob Keller
2016-04-18  6:26 ` Johannes Schindelin
2016-04-18  7:09   ` Andrew Ardill
2016-04-18  7:23     ` Christoph Paulik
2016-04-18  7:44       ` Andrew Ardill
2016-04-18 16:36         ` Junio C Hamano
2016-04-18 16:54           ` Junio C Hamano
2016-04-26 21:32             ` [PATCH 1/2] merge: do not contaminate option_commit with --squash Junio C Hamano
2016-04-27  6:46               ` Johannes Schindelin
2016-04-27 15:14                 ` Junio C Hamano
2016-04-27 15:19                   ` Johannes Schindelin
2016-04-26 21:37             ` Junio C Hamano [this message]
2016-04-26 21:53               ` [PATCH 2/2] merge: warn --no-commit merge when no new commit is created Stefan Beller
2016-04-26 22:00                 ` Junio C Hamano
2016-04-27  1:39               ` Eric Sunshine
2016-04-27  5:57               ` Johannes Sixt
2016-04-27  6:50               ` Johannes Schindelin
2016-04-27 15:13                 ` Junio C Hamano
2016-04-27 15:37                   ` Johannes Schindelin
2016-04-27 16:02                     ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=xmqqd1pcdpb8.fsf_-_@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=andrew.ardill@gmail.com \
    --cc=cpaulik@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.