git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Santi Béjar" <santi@agolina.net>
To: git@vger.kernel.org
Subject: [PATCHv2 1/3] parse-remote: function to get the tracking branch to be merge
Date: Sun,  7 Jun 2009 11:44:20 +0200	[thread overview]
Message-ID: <1244367862-6306-1-git-send-email-santi@agolina.net> (raw)

The only user of get_remote_refs_for_fetch was "git pull --rebase" and
it only wanted the tracking branch to be merge. So, add a simple
function with this new meaning.

No behavior changes.

Signed-off-by: Santi Béjar <santi@agolina.net>
---
 git-parse-remote.sh |   33 +++++++++++++++++++++++++++++++++
 git-pull.sh         |    7 ++-----
 2 files changed, 35 insertions(+), 5 deletions(-)
 mode change 100755 => 100644 git-parse-remote.sh

diff --git a/git-parse-remote.sh b/git-parse-remote.sh
old mode 100755
new mode 100644
index a296719..8b3ba72
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -229,6 +229,38 @@ get_remote_refs_for_fetch () {
 	esac
 }
 
+get_remote_merge_branch () {
+	case "$#" in
+	0|1)
+	    die "internal error: get-remote-merge-branch." ;;
+	*)
+	    repo=$1
+	    shift
+	    # FIXME: It should return the tracking branch
+	    #        Currently only works with the default mapping
+	    for ref
+	    do
+		case "$ref" in
+		+*)
+			ref=$(expr "z$ref" : 'z+\(.*\)')
+			;;
+		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/* ) break
+		esac
+
+		echo "refs/remotes/$repo/$remote"
+		break
+	    done
+	    ;;
+	esac
+}
+
 resolve_alternates () {
 	# original URL (xxx.git)
 	top_=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
@@ -262,3 +294,4 @@ get_uploadpack () {
 		;;
 	esac
 }
+
diff --git a/git-pull.sh b/git-pull.sh
index 3526153..3cf2663 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -125,12 +125,9 @@ test true = "$rebase" && {
 	die "refusing to pull with rebase: your working tree is not up-to-date"
 
 	. git-parse-remote &&
-	origin="$1"
-	test -z "$origin" && origin=$(get_default_remote)
-	reflist="$(get_remote_refs_for_fetch "$@" 2>/dev/null |
-		sed "s|refs/heads/\(.*\):|\1|")" &&
+	reflist="$(get_remote_merge_branch "$@" 2>/dev/null)" &&
 	oldremoteref="$(git rev-parse -q --verify \
-		"refs/remotes/$origin/$reflist")"
+		"$reflist")"
 }
 orig_head=$(git rev-parse -q --verify HEAD)
 git fetch $verbosity --update-head-ok "$@" || exit 1
-- 
1.6.3.1.308.g426b5

                 reply	other threads:[~2009-06-07  9:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1244367862-6306-1-git-send-email-santi@agolina.net \
    --to=santi@agolina.net \
    --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).