Code

merge script: improve log message subject
authorJonathan Nieder <jrnieder@gmail.com>
Tue, 17 Aug 2010 07:04:43 +0000 (02:04 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Aug 2010 21:02:04 +0000 (14:02 -0700)
 - point out remote-tracking branches as "remote branch
   'upstream/master'";
 - avoid misleading log messages when a tag and branch
   share a name.

This approximates the builtin merge command's behavior well
enough to pass the relevant tests.

Based roughly on v1.6.4.2~10^2 (merge: indicate remote tracking
branches in merge message, 2009-08-09) and v1.6.4.2~10^2~1 (merge: fix
incorrect merge message for ambiguous tag/branch, 2009-08-09).

Cc: Jeff King <peff@peff.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/examples/git-merge.sh

index 50042df1b90bbdf7130a1baa4177b531245634ba..d49156666091eda246abcac8c7c76a0917872d1c 100755 (executable)
@@ -134,21 +134,32 @@ finish () {
 merge_name () {
        remote="$1"
        rh=$(git rev-parse --verify "$remote^0" 2>/dev/null) || return
-       bh=$(git show-ref -s --verify "refs/heads/$remote" 2>/dev/null)
-       if test "$rh" = "$bh"
-       then
-               echo "$rh               branch '$remote' of ."
-       elif truname=$(expr "$remote" : '\(.*\)~[1-9][0-9]*$') &&
+       if truname=$(expr "$remote" : '\(.*\)~[0-9]*$') &&
                git show-ref -q --verify "refs/heads/$truname" 2>/dev/null
        then
                echo "$rh               branch '$truname' (early part) of ."
-       elif test "$remote" = "FETCH_HEAD" -a -r "$GIT_DIR/FETCH_HEAD"
+               return
+       fi
+       if found_ref=$(git rev-parse --symbolic-full-name --verify \
+                                                       "$remote" 2>/dev/null)
+       then
+               if test "${found_ref#refs/heads/}" != "$found_ref"
+               then
+                       echo "$rh               branch '$remote' of ."
+                       return
+               elif test "${found_ref#refs/remotes/}" != "$found_ref"
+               then
+                       echo "$rh               remote branch '$remote' of ."
+                       return
+               fi
+       fi
+       if test "$remote" = "FETCH_HEAD" -a -r "$GIT_DIR/FETCH_HEAD"
        then
                sed -e 's/      not-for-merge   /               /' -e 1q \
                        "$GIT_DIR/FETCH_HEAD"
-       else
-               echo "$rh               commit '$remote'"
+               return
        fi
+       echo "$rh               commit '$remote'"
 }
 
 parse_config () {