git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Timothy Chen <tnachen@gmail.com>
To: git@vger.kernel.org
Cc: Timothy Chen <tnachen@gmail.com>
Subject: [PATCH] Allow multiple merges to invalid HEAD
Date: Sat,  2 Apr 2011 23:46:56 -0700	[thread overview]
Message-ID: <1301813216-19507-1-git-send-email-tnachen@gmail.com> (raw)

Currently git merge only allows one branch when current HEAD
is not yet pointing to a valid commit.

This patch will allow multiple branches to be passed in,
and first updates current HEAD to the first branch's head then subsequently
merge the rest of the branches.
---
 builtin/merge.c |   57 +++++++++++++++++++++++++++++-------------------------
 1 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/builtin/merge.c b/builtin/merge.c
index d54e7dd..290e0d4 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1090,9 +1090,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		 * to forbid "git merge" into a branch yet to be born.
 		 * We do the same for "git pull".
 		 */
-		if (argc != 1)
-			die(_("Can merge only exactly one commit into "
-				"empty head"));
 		if (squash)
 			die(_("Squash commit into empty head not supported yet"));
 		if (!allow_fast_forward)
@@ -1101,36 +1098,44 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		remote_head = peel_to_type(argv[0], 0, NULL, OBJ_COMMIT);
 		if (!remote_head)
 			die(_("%s - not something we can merge"), argv[0]);
-		read_empty(remote_head->sha1, 0);
 		update_ref("initial pull", "HEAD", remote_head->sha1, NULL, 0,
 				DIE_ON_ERR);
-		return 0;
-	} else {
-		struct strbuf merge_names = STRBUF_INIT;
 
-		/* We are invoked directly as the first-class UI. */
+		if (argc < 2)
+			return 0;
+
+		hashcpy(head, remote_head->sha1);
+		read_empty(remote_head->sha1, 0);
+		head_arg = argv[0];
+		argc--;
+		argv++;
+	}
+
+	struct strbuf merge_names = STRBUF_INIT;
+
+	/* We are invoked directly as the first-class UI. */
+	if(!head_invalid)
 		head_arg = "HEAD";
 
-		/*
-		 * All the rest are the commits being merged;
-		 * prepare the standard merge summary message to
-		 * be appended to the given message.  If remote
-		 * is invalid we will die later in the common
-		 * codepath so we discard the error in this
-		 * loop.
-		 */
-		for (i = 0; i < argc; i++)
-			merge_name(argv[i], &merge_names);
-
-		if (!have_message || shortlog_len) {
-			fmt_merge_msg(&merge_names, &merge_msg, !have_message,
-				      shortlog_len);
-			if (merge_msg.len)
-				strbuf_setlen(&merge_msg, merge_msg.len - 1);
-		}
+	/*
+	 * All the rest are the commits being merged;
+	 * prepare the standard merge summary message to
+	 * be appended to the given message.  If remote
+	 * is invalid we will die later in the common
+	 * codepath so we discard the error in this
+	 * loop.
+	 */
+	for (i = 0; i < argc; i++)
+		merge_name(argv[i], &merge_names);
+
+	if (!have_message || shortlog_len) {
+		fmt_merge_msg(&merge_names, &merge_msg, !have_message,
+				  shortlog_len);
+		if (merge_msg.len)
+			strbuf_setlen(&merge_msg, merge_msg.len - 1);
 	}
 
-	if (head_invalid || !argc)
+	if (!argc)
 		usage_with_options(builtin_merge_usage,
 			builtin_merge_options);
 
-- 
1.7.3.4

             reply	other threads:[~2011-04-03  6:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-03  6:46 Timothy Chen [this message]
2011-04-03  7:07 ` [PATCH] Allow multiple merges to invalid HEAD Junio C Hamano
2011-04-03 21:52   ` Jonathan Nieder
2011-04-03  8:08 ` Junio C Hamano
2011-04-03 22:22 ` Jonathan Nieder
2011-04-05  6:01   ` Timothy Chen

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=1301813216-19507-1-git-send-email-tnachen@gmail.com \
    --to=tnachen@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 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 NNTP newsgroup(s).