rebase -i: fix squashing corner case
When squashing, rebase -i did not prevent fast forwards. This could happen when picking some other commit than the first one, and then squashing the first commit. So do not allow fast forwards when squashing. Noticed by Johannes Sixt. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Aug 23, 2007 at 09:55 UTC
1d25c8cf82eead72e11287d574ef72d3ebec0db1
2 files changed
+24
-2
git-rebase--interactive.sh
+3
-2
@@ -96,13 +96,14 @@ die_abort () {
96
}
97
98
pick_one () {
99
- case "$1" in -n) sha1=$2 ;; *) sha1=$1 ;; esac
99
+ no_ff=
100
+ case "$1" in -n) sha1=$2; no_ff=t ;; *) sha1=$1 ;; esac
101
output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
102
test -d "$REWRITTEN" &&
103
pick_one_preserving_merges "$@" && return
104
parent_sha1=$(git rev-parse --verify $sha1^ 2>/dev/null)
105
current_sha1=$(git rev-parse --verify HEAD)
105
- if test $current_sha1 = $parent_sha1; then
106
+ if test $no_ff$current_sha1 = $parent_sha1; then
107
output git reset --hard $sha1
108
test "a$1" = a-n && output git reset --soft $current_sha1
109
sha1=$(git rev-parse --short $sha1)
t/t3404-rebase-interactive.sh
+21
@@ -264,6 +264,27 @@ test_expect_success 'interrupted squash works as expected' '
264
test $one = $(git rev-parse HEAD~2)
265
'
266
267
+test_expect_success 'interrupted squash works as expected (case 2)' '
268
+ for n in one two three four
269
+ do
270
+ echo $n >> conflict &&
271
+ git add conflict &&
272
+ git commit -m $n
273
+ done &&
274
+ one=$(git rev-parse HEAD~3) &&
275
+ ! FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
276
+ (echo one; echo four) > conflict &&
277
+ git add conflict &&
278
+ ! git rebase --continue &&
279
+ (echo one; echo two; echo four) > conflict &&
280
+ git add conflict &&
281
+ ! git rebase --continue &&
282
+ echo resolved > conflict &&
283
+ git add conflict &&
284
+ git rebase --continue &&
285
+ test $one = $(git rev-parse HEAD~2)
286
+'
287
+
288
test_expect_success 'ignore patch if in upstream' '
289
HEAD=$(git rev-parse HEAD) &&
290
git checkout -b has-cherry-picked HEAD^ &&