Skip to content

Commit 729ec9e

Browse files
Martin von Zweigbergkgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1c7d402 commit 729ec9e

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

git-rebase.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,16 @@ do
274274
die "No rebase in progress?"
275275

276276
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
286287
git reset --hard $(cat "$dotest/orig-head")
287288
rm -r "$dotest"
288289
exit

t/t3407-rebase-abort.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ testrebase() {
7272
test $(git rev-parse to-rebase) = $(git rev-parse pre-rebase) &&
7373
test ! -d "$dotest"
7474
'
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+
'
7587
}
7688

7789
testrebase "" .git/rebase-apply

0 commit comments

Comments
 (0)