parse-remote: function to get the tracking branch to be merge
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 (get_remote_merge_branch) with this new meaning. No behavior changes. The new function behaves like the old code in "git pull --rebase". In particular, it only works with the default refspec mapping and with remote branches, not tags. Signed-off-by: Santi Béjar <santi@agolina.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Santi Béjar committed
Jun 12, 2009 at 00:39 UTC
97af7ff0553ed81bb905dbc0c8b0f9a0c10bfb3d
2 files changed
+31
-5
git-parse-remote.sh
+29
@@ -229,6 +229,34 @@ get_remote_refs_for_fetch () {
229
esac
230
}
231
232
+get_remote_merge_branch () {
233
+ case "$#" in
234
+ 0|1)
235
+ die "internal error: get-remote-merge-branch." ;;
236
+ *)
237
+ repo=$1
238
+ shift
239
+ ref=$1
240
+ # FIXME: It should return the tracking branch
241
+ # Currently only works with the default mapping
242
+ case "$ref" in
243
+ +*)
244
+ ref=$(expr "z$ref" : 'z+\(.*\)')
245
+ ;;
246
+ esac
247
+ expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
248
+ remote=$(expr "z$ref" : 'z\([^:]*\):')
249
+ case "$remote" in
250
+ '' | HEAD ) remote=HEAD ;;
251
+ heads/*) remote=${remote#heads/} ;;
252
+ refs/heads/*) remote=${remote#refs/heads/} ;;
253
+ refs/* | tags/* | remotes/* ) remote=
254
+ esac
255
+
256
+ [ -n "$remote" ] && echo "refs/remotes/$repo/$remote"
257
+ esac
258
+}
259
+
260
resolve_alternates () {
261
# original URL (xxx.git)
262
top_=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
@@ -262,3 +290,4 @@ get_uploadpack () {
290
;;
291
esac
292
}
293
+
git-pull.sh
+2
-5
@@ -125,12 +125,9 @@ test true = "$rebase" && {
125
die "refusing to pull with rebase: your working tree is not up-to-date"
126
127
. git-parse-remote &&
128
- origin="$1"
129
- test -z "$origin" && origin=$(get_default_remote)
130
- reflist="$(get_remote_refs_for_fetch "$@" 2>/dev/null |
131
- sed "s|refs/heads/\(.*\):|\1|")" &&
128
+ reflist="$(get_remote_merge_branch "$@" 2>/dev/null)" &&
129
oldremoteref="$(git rev-parse -q --verify \
133
- "refs/remotes/$origin/$reflist")"
130
+ "$reflist")"
131
}
132
orig_head=$(git rev-parse -q --verify HEAD)
133
git fetch $verbosity --update-head-ok "$@" || exit 1