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>
Thomas Rast committed
Aug 13, 2008 at 23:41 UTC
a96dc01e21603849cb454a311f18780c2e839f29
2 files changed
+14
-4
git-rebase--interactive.sh
+2
-4
@@ -165,14 +165,14 @@ pick_one_preserving_merges () {
165
die "Cannot write current commit's replacement sha1"
166
fi
167
168
+ echo $sha1 > "$DOTEST"/current-commit
169
+
170
# rewrite parents; if none were rewritten, we can fast-forward.
169
- preserve=t
171
new_parents=
172
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -f2-)
173
do
174
if test -f "$REWRITTEN"/$p
175
then
175
- preserve=f
176
new_p=$(cat "$REWRITTEN"/$p)
177
test $p != $new_p && fast_forward=f
178
case "$new_parents" in
@@ -189,7 +189,6 @@ pick_one_preserving_merges () {
189
case $fast_forward in
190
t)
191
output warn "Fast forward to $sha1"
192
- test $preserve = f || echo $sha1 > "$REWRITTEN"/$sha1
192
output git reset --hard $sha1 ||
193
die "Cannot fast forward to $sha1"
194
;;
@@ -201,7 +200,6 @@ pick_one_preserving_merges () {
200
output git checkout $first_parent 2> /dev/null ||
201
die "Cannot move HEAD to $first_parent"
202
204
- echo $sha1 > "$DOTEST"/current-commit
203
case "$new_parents" in
204
' '*' '*)
205
# redo merge
t/t3404-rebase-interactive.sh
+12
@@ -250,6 +250,18 @@ test_expect_success 'preserve merges with -p' '
250
test $(git show HEAD:unrelated-file) = 1
251
'
252
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
+
265
test_expect_success '--continue tries to commit' '
266
test_tick &&
267
test_must_fail git rebase -i --onto new-branch1 HEAD^ &&