Skip to content

Commit e9460a6

Browse files
Santi Béjargitster
authored andcommitted
parse-remote: support default reflist in get_remote_merge_branch
Expand get_remote_merge_branch to compute the tracking branch to merge when called without arguments (or only the remote name). This allows "git pull --rebase" without arguments (default upstream branch) to work with a rebased upstream. With explicit arguments it already worked. Also add a test to check for this case. Signed-off-by: Santi Béjar <santi@agolina.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 97af7ff commit e9460a6

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

git-parse-remote.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,13 @@ get_remote_refs_for_fetch () {
232232
get_remote_merge_branch () {
233233
case "$#" in
234234
0|1)
235-
die "internal error: get-remote-merge-branch." ;;
235+
origin="$1"
236+
default=$(get_default_remote)
237+
test -z "$origin" && origin=$default
238+
curr_branch=$(git symbolic-ref -q HEAD)
239+
[ "$origin" = "$default" ] &&
240+
echo $(git for-each-ref --format='%(upstream)' $curr_branch)
241+
;;
236242
*)
237243
repo=$1
238244
shift

t/t5520-pull.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,34 @@ test_expect_success '--rebase with rebased upstream' '
9292
9393
git remote add -f me . &&
9494
git checkout copy &&
95+
git tag copy-orig &&
9596
git reset --hard HEAD^ &&
9697
echo conflicting modification > file &&
9798
git commit -m conflict file &&
9899
git checkout to-rebase &&
99100
echo file > file2 &&
100101
git commit -m to-rebase file2 &&
102+
git tag to-rebase-orig &&
101103
git pull --rebase me copy &&
102104
test "conflicting modification" = "$(cat file)" &&
103105
test file = $(cat file2)
104106
105107
'
106108

109+
test_expect_success '--rebase with rebased default upstream' '
110+
111+
git update-ref refs/remotes/me/copy copy-orig &&
112+
git checkout --track -b to-rebase2 me/copy &&
113+
git reset --hard to-rebase-orig &&
114+
git pull --rebase &&
115+
test "conflicting modification" = "$(cat file)" &&
116+
test file = $(cat file2)
117+
118+
'
119+
107120
test_expect_success 'pull --rebase dies early with dirty working directory' '
108121
122+
git checkout to-rebase &&
109123
git update-ref refs/remotes/me/copy copy^ &&
110124
COPY=$(git rev-parse --verify me/copy) &&
111125
git rebase --onto $COPY copy &&

0 commit comments

Comments
 (0)