Skip to content

Commit 97af7ff

Browse files
Santi Béjargitster
authored andcommitted
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>
1 parent cb9d398 commit 97af7ff

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

git-parse-remote.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,34 @@ get_remote_refs_for_fetch () {
229229
esac
230230
}
231231

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+
232260
resolve_alternates () {
233261
# original URL (xxx.git)
234262
top_=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
@@ -262,3 +290,4 @@ get_uploadpack () {
262290
;;
263291
esac
264292
}
293+

git-pull.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,9 @@ test true = "$rebase" && {
125125
die "refusing to pull with rebase: your working tree is not up-to-date"
126126

127127
. 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)" &&
132129
oldremoteref="$(git rev-parse -q --verify \
133-
"refs/remotes/$origin/$reflist")"
130+
"$reflist")"
134131
}
135132
orig_head=$(git rev-parse -q --verify HEAD)
136133
git fetch $verbosity --update-head-ok "$@" || exit 1

0 commit comments

Comments
 (0)