[RFC/PATCH 2/2] get_remote_merge_branch: Support for arbitrary mapping

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This function is used in "git pull --rebase" to know the tracking branch.

Signed-off-by: Santi Béjar <santi@xxxxxxxxxxx>
---
 git-parse-remote.sh |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index 5f47b18..1aa6ffe 100755
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -74,8 +74,6 @@ get_remote_merge_branch () {
 	    repo=$1
 	    shift
 	    ref=$1
-	    # FIXME: It should return the tracking branch
-	    #        Currently only works with the default mapping
 	    case "$ref" in
 	    +*)
 		ref=$(expr "z$ref" : 'z+\(.*\)')
@@ -83,13 +81,18 @@ get_remote_merge_branch () {
 	    esac
 	    expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
 	    remote=$(expr "z$ref" : 'z\([^:]*\):')
-	    case "$remote" in
-	    '' | HEAD ) remote=HEAD ;;
-	    heads/*) remote=${remote#heads/} ;;
-	    refs/heads/*) remote=${remote#refs/heads/} ;;
-	    refs/* | tags/* | remotes/* ) remote=
-	    esac
+	    while true ; do
+		case "$remote" in
+		'' | HEAD ) remote=;;
+		heads/*) remote=refs/$remote;;
+		refs/heads/*) ;;
+		refs/* | tags/* | remotes/* ) remote=;;
+		*) remote=heads/$remote
+		esac
 
-	    [ -n "$remote" ] && echo "refs/remotes/$repo/$remote"
+		[ -n "$remote" ] &&
+		git remote tracking $repo $remote && break
+		case "$remote" in refs/heads/* | "" ) break ; esac
+	    done
 	esac
 }
-- 
1.6.3.2.406.gd6a466

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]