rebase --abort: do not update branch ref
If a non-interactive rebase of a ref fails at commit X and is aborted by the user, the ref will be updated twice. First to point at X (with the reflog message "rebase finished: $head_name onto $onto"), and then back to $orig_head. It should not be updated at all. Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Martin von Zweigbergk committed
Nov 21, 2010 at 12:11 UTC
729ec9e23a13a0610a19a24901d0ab5e2bc44a12
2 files changed
+22
-9
git-rebase.sh
+10
-9
@@ -274,15 +274,16 @@ do
274
die "No rebase in progress?"
275
276
git rerere clear
277
- if test -d "$dotest"
278
- then
279
- GIT_QUIET=$(cat "$dotest/quiet")
280
- move_to_original_branch
281
- else
282
- dotest="$GIT_DIR"/rebase-apply
283
- GIT_QUIET=$(cat "$dotest/quiet")
284
- move_to_original_branch
285
- fi
277
+
278
+ test -d "$dotest" || dotest="$GIT_DIR"/rebase-apply
279
+
280
+ head_name="$(cat "$dotest"/head-name)" &&
281
+ case "$head_name" in
282
+ refs/*)
283
+ git symbolic-ref HEAD $head_name ||
284
+ die "Could not move back to $head_name"
285
+ ;;
286
+ esac
287
git reset --hard $(cat "$dotest/orig-head")
288
rm -r "$dotest"
289
exit
t/t3407-rebase-abort.sh
+12
@@ -72,6 +72,18 @@ testrebase() {
72
test $(git rev-parse to-rebase) = $(git rev-parse pre-rebase) &&
73
test ! -d "$dotest"
74
'
75
+
76
+ test_expect_success "rebase$type --abort does not update reflog" '
77
+ cd "$work_dir" &&
78
+ # Clean up the state from the previous one
79
+ git reset --hard pre-rebase &&
80
+ git reflog show to-rebase > reflog_before &&
81
+ test_must_fail git rebase$type master &&
82
+ git rebase --abort &&
83
+ git reflog show to-rebase > reflog_after &&
84
+ test_cmp reflog_before reflog_after &&
85
+ rm reflog_before reflog_after
86
+ '
87
}
88
89
testrebase "" .git/rebase-apply