git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: skillzero@gmail.com
Cc: git@vger.kernel.org
Subject: Re: git merge remote branch says "Merge commit ..."?
Date: Fri, 22 May 2009 03:49:27 -0400	[thread overview]
Message-ID: <20090522074927.GB1409@coredump.intra.peff.net> (raw)
In-Reply-To: <2729632a0905211250v4e7537caybe9e703c14361b5f@mail.gmail.com>

On Thu, May 21, 2009 at 12:50:48PM -0700, skillzero@gmail.com wrote:

> I noticed that if I do 'git merge origin/branch' that the log message
> says (using --log):
> 
> Merge commit 'origin/branch'
> 
>    * commit 'origin/branch':
>      Fixed some bug.
> 
> If I do the same thing from a local tracking branch of origin/branch, it says:
> 
> Merge branch 'branch'
> 
>    * branch:
>      Fixed some bug.
> 
> Is it expected that it say "commit" instead of "branch" when the
> branch is not a local tracking branch? I sometimes merge from remote
> branches when I don't need to do anything with that branch locally
> (e.g. I already did the work on another computer and I'm just merging
> the result into my test machine before I push to the shared server).

I think doing a "git merge origin/master" is perfectly normal for some
workflows. For example:

  $ git fetch origin ;# grab it
  $ gitk origin/master...master ;# check if it is good to merge
  $ git merge origin/master ;# and merge it

The final step _could_ be a pull, but there is no point in repeating the
fetch (which might be costly).

There is already code in fmt-merge-msg to handle remote branches; it
looks like we just need to signal that code the same way "git fetch"
would. Maybe something like the patch below (which is really just a
cut-and-paste of the code directly above it to special-case real
branches).

It gives a sensible "Merge" line but you end up with

  * remote branch 'origin/master':
    ...

instead of

  * origin/master:
    ...

So it probably requires some deeper digging into what git-fetch is
doing, and to emulate that (I am pretty ignorant of this part of the
code).

---
diff --git a/builtin-merge.c b/builtin-merge.c
index 0b58e5e..a74a4d0 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -378,6 +378,17 @@ static void merge_name(const char *remote, struct strbuf *msg)
 		goto cleanup;
 	}
 
+	strbuf_setlen(&buf, 0);
+	strbuf_addstr(&buf, "refs/remotes/");
+	strbuf_addstr(&buf, remote);
+	resolve_ref(buf.buf, branch_head, 0, 0);
+
+	if (!hashcmp(remote_head->sha1, branch_head)) {
+		strbuf_addf(msg, "%s\t\tremote branch '%s'\n",
+				sha1_to_hex(branch_head), remote);
+		goto cleanup;
+	}
+
 	/* See if remote matches <name>^^^.. or <name>~<number> */
 	for (len = 0, ptr = remote + strlen(remote);
 	     remote < ptr && ptr[-1] == '^';

  reply	other threads:[~2009-05-22  7:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-21 19:50 git merge remote branch says "Merge commit ..."? skillzero
2009-05-22  7:49 ` Jeff King [this message]
2009-05-22 17:29   ` Eric Raible
2009-05-22 17:54     ` Jeff King
2009-05-22 18:08       ` git merge remote branch says Eric Raible
2009-05-22 18:10         ` Jeff King
2009-05-22 18:30       ` git merge remote branch says "Merge commit ..."? Johannes Sixt
2009-05-23  9:17         ` Jeff King
2009-05-23  9:26           ` Junio C Hamano
2009-05-25  9:44             ` Jeff King

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=20090522074927.GB1409@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=skillzero@gmail.com \
    /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).