Skip to content

Commit a96dc01

Browse files
trastgitster
authored andcommitted
rebase -i -p: fix parent rewriting
The existing parent rewriting did not handle the case where a previous commit was amended (via edit or squash). Fix by always putting the new sha1 of the last commit into the $REWRITTEN map. Signed-off-by: Thomas Rast <trast@student.ethz.ch>
1 parent 71d9451 commit a96dc01

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

git-rebase--interactive.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ pick_one_preserving_merges () {
165165
die "Cannot write current commit's replacement sha1"
166166
fi
167167

168+
echo $sha1 > "$DOTEST"/current-commit
169+
168170
# rewrite parents; if none were rewritten, we can fast-forward.
169-
preserve=t
170171
new_parents=
171172
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -f2-)
172173
do
173174
if test -f "$REWRITTEN"/$p
174175
then
175-
preserve=f
176176
new_p=$(cat "$REWRITTEN"/$p)
177177
test $p != $new_p && fast_forward=f
178178
case "$new_parents" in
@@ -189,7 +189,6 @@ pick_one_preserving_merges () {
189189
case $fast_forward in
190190
t)
191191
output warn "Fast forward to $sha1"
192-
test $preserve = f || echo $sha1 > "$REWRITTEN"/$sha1
193192
output git reset --hard $sha1 ||
194193
die "Cannot fast forward to $sha1"
195194
;;
@@ -201,7 +200,6 @@ pick_one_preserving_merges () {
201200
output git checkout $first_parent 2> /dev/null ||
202201
die "Cannot move HEAD to $first_parent"
203202

204-
echo $sha1 > "$DOTEST"/current-commit
205203
case "$new_parents" in
206204
' '*' '*)
207205
# redo merge

t/t3404-rebase-interactive.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,18 @@ test_expect_success 'preserve merges with -p' '
250250
test $(git show HEAD:unrelated-file) = 1
251251
'
252252

253+
test_expect_success 'edit ancestor with -p' '
254+
FAKE_LINES="1 edit 2 3 4" git rebase -i -p HEAD~3 &&
255+
echo 2 > unrelated-file &&
256+
test_tick &&
257+
git commit -m L2-modified --amend unrelated-file &&
258+
git rebase --continue &&
259+
git update-index --refresh &&
260+
git diff-files --quiet &&
261+
git diff-index --quiet --cached HEAD -- &&
262+
test $(git show HEAD:unrelated-file) = 2
263+
'
264+
253265
test_expect_success '--continue tries to commit' '
254266
test_tick &&
255267
test_must_fail git rebase -i --onto new-branch1 HEAD^ &&

0 commit comments

Comments
 (0)