Skip to content

Commit d25c72f

Browse files
committed
Merge branch 'en/rebase-against-rebase-fix'
* en/rebase-against-rebase-fix: pull --rebase: Avoid spurious conflicts and reapplying unnecessary patches t5520-pull: Add testcases showing spurious conflicts from git pull --rebase
2 parents 2eb5469 + cf65426 commit d25c72f

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

git-pull.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ then
273273
exit
274274
fi
275275

276+
if test true = "$rebase"
277+
then
278+
o=$(git show-branch --merge-base $curr_branch $merge_head $oldremoteref)
279+
if test "$oldremoteref" = "$o"
280+
then
281+
unset oldremoteref
282+
fi
283+
fi
284+
276285
merge_name=$(git fmt-merge-msg $log_arg <"$GIT_DIR/FETCH_HEAD") || exit
277286
case "$rebase" in
278287
true)

t/t5520-pull.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ test_description='pulling into void'
44

55
. ./test-lib.sh
66

7+
modify () {
8+
sed -e "$1" <"$2" >"$2.x" &&
9+
mv "$2.x" "$2"
10+
}
11+
712
D=`pwd`
813

914
test_expect_success setup '
@@ -160,4 +165,61 @@ test_expect_success 'pull --rebase works on branch yet to be born' '
160165
test_cmp expect actual
161166
'
162167

168+
test_expect_success 'setup for detecting upstreamed changes' '
169+
mkdir src &&
170+
(cd src &&
171+
git init &&
172+
printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
173+
git add stuff &&
174+
git commit -m "Initial revision"
175+
) &&
176+
git clone src dst &&
177+
(cd src &&
178+
modify s/5/43/ stuff &&
179+
git commit -a -m "5->43" &&
180+
modify s/6/42/ stuff &&
181+
git commit -a -m "Make it bigger"
182+
) &&
183+
(cd dst &&
184+
modify s/5/43/ stuff &&
185+
git commit -a -m "Independent discovery of 5->43"
186+
)
187+
'
188+
189+
test_expect_success 'git pull --rebase detects upstreamed changes' '
190+
(cd dst &&
191+
git pull --rebase &&
192+
test -z "$(git ls-files -u)"
193+
)
194+
'
195+
196+
test_expect_success 'setup for avoiding reapplying old patches' '
197+
(cd dst &&
198+
test_might_fail git rebase --abort &&
199+
git reset --hard origin/master
200+
) &&
201+
git clone --bare src src-replace.git &&
202+
rm -rf src &&
203+
mv src-replace.git src &&
204+
(cd dst &&
205+
modify s/2/22/ stuff &&
206+
git commit -a -m "Change 2" &&
207+
modify s/3/33/ stuff &&
208+
git commit -a -m "Change 3" &&
209+
modify s/4/44/ stuff &&
210+
git commit -a -m "Change 4" &&
211+
git push &&
212+
213+
modify s/44/55/ stuff &&
214+
git commit --amend -a -m "Modified Change 4"
215+
)
216+
'
217+
218+
test_expect_success 'git pull --rebase does not reapply old patches' '
219+
(cd dst &&
220+
test_must_fail git pull --rebase &&
221+
test 1 = $(find .git/rebase-apply -name "000*" | wc -l)
222+
)
223+
'
224+
163225
test_done

0 commit comments

Comments
 (0)