Skip to content

Commit 840b3ca

Browse files
committed
rebase: protect against diff.renames configuration
We currently do not disable diff.renames configuration while rebase internally runs "format-patch" to feed "am -3". The end user configuration for "diff" should not affect the result produced by the higher level command that is related to "diff" only because internally it is implemented in terms of it. For that matter, I have a feeling that format-patch should not even look at diff.renames, but we seem to have been doing this for a long time so there is no easy way to fix this thinko. In any case, here is a much straightforward fix for "rebase". [jn: with test case from David] Reported-by: David D. Kilzer <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e877a4c commit 840b3ca

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

git-rebase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ fi
543543
if test -z "$do_merge"
544544
then
545545
git format-patch -k --stdout --full-index --ignore-if-in-upstream \
546-
$root_flag "$revisions" |
546+
--no-renames $root_flag "$revisions" |
547547
git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
548548
move_to_original_branch
549549
ret=$?

t/t3400-rebase.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ test_expect_success 'prepare repository with topic branches' '
1919
echo First >A &&
2020
git update-index --add A &&
2121
git commit -m "Add A." &&
22-
git checkout -b my-topic-branch &&
22+
git checkout -b force-3way &&
23+
echo Dummy >Y &&
24+
git update-index --add Y &&
25+
git commit -m "Add Y." &&
26+
git checkout -b filemove &&
27+
git reset --soft master &&
28+
mkdir D &&
29+
git mv A D/A &&
30+
git commit -m "Move A." &&
31+
git checkout -b my-topic-branch master &&
2332
echo Second >B &&
2433
git update-index --add B &&
2534
git commit -m "Add B." &&
@@ -128,6 +137,19 @@ test_expect_success 'rebase a single mode change' '
128137
GIT_TRACE=1 git rebase master
129138
'
130139

140+
test_expect_success 'rebase is not broken by diff.renames' '
141+
git config diff.renames copies &&
142+
test_when_finished "git config --unset diff.renames" &&
143+
git checkout filemove &&
144+
GIT_TRACE=1 git rebase force-3way
145+
'
146+
147+
test_expect_success 'setup: recover' '
148+
test_might_fail git rebase --abort &&
149+
git reset --hard &&
150+
git checkout modechange
151+
'
152+
131153
test_expect_success 'Show verbose error when HEAD could not be detached' '
132154
>B &&
133155
test_must_fail git rebase topic 2>output.err >output.out &&

0 commit comments

Comments
 (0)