Skip to content

Commit d44e712

Browse files
Santi Béjargitster
authored andcommitted
pull: support rebased upstream + fetch + pull --rebase
You cannot do a "git pull --rebase" with a rebased upstream, if you have already run "git fetch". Try to behave as if the "git fetch" was not run. In other words, find the fork point of the current branch, where the tip of upstream branch used to be, and use it as the upstream parameter of "git rebase". This patch computes the fork point by walking the reflog to find the first commit which is an ancestor of the current branch. Maybe there are smarter ways to compute it, but this is a straight forward implementation. Signed-off-by: Santi Béjar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a418441 commit d44e712

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

git-pull.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,18 @@ test true = "$rebase" && {
124124
git diff-index --ignore-submodules --cached --quiet HEAD -- ||
125125
die "refusing to pull with rebase: your working tree is not up-to-date"
126126

127+
oldremoteref= &&
127128
. git-parse-remote &&
128-
reflist="$(get_remote_merge_branch "$@" 2>/dev/null)" &&
129-
oldremoteref="$(git rev-parse -q --verify \
130-
"$reflist")"
129+
remoteref="$(get_remote_merge_branch "$@" 2>/dev/null)" &&
130+
oldremoteref="$(git rev-parse -q --verify "$remoteref")" &&
131+
for reflog in $(git rev-list -g $remoteref 2>/dev/null)
132+
do
133+
if test "$reflog" = "$(git merge-base $reflog $curr_branch)"
134+
then
135+
oldremoteref="$reflog"
136+
break
137+
fi
138+
done
131139
}
132140
orig_head=$(git rev-parse -q --verify HEAD)
133141
git fetch $verbosity --update-head-ok "$@" || exit 1

t/t5520-pull.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,14 @@ test_expect_success '--rebase with rebased default upstream' '
117117
118118
'
119119

120-
test_expect_failure 'rebased upstream + fetch + pull --rebase' '
120+
test_expect_success 'rebased upstream + fetch + pull --rebase' '
121121
122122
git update-ref refs/remotes/me/copy copy-orig &&
123123
git reset --hard to-rebase-orig &&
124124
git checkout --track -b to-rebase3 me/copy &&
125125
git reset --hard to-rebase-orig &&
126126
git fetch &&
127-
test_must_fail git pull --rebase &&
128-
git rebase --abort &&
127+
git pull --rebase &&
129128
test "conflicting modification" = "$(cat file)" &&
130129
test file = "$(cat file2)"
131130

0 commit comments

Comments
 (0)