]> git.ipfire.org Git - thirdparty/git.git/commit
rebase: apply and cleanup autostash when rebase fails to start
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Mon, 2 Sep 2024 15:12:59 +0000 (15:12 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Sep 2024 18:24:43 +0000 (11:24 -0700)
commitbf6ab087d14b839f8a7b188a7af62e43164873fb
tree7988faf6b8c1c1f6f73f438c5f2f73c478df7ff5
parent39bf06adf96da25b87c9aa7d35a32ef3683eb4a4
rebase: apply and cleanup autostash when rebase fails to start

If "git rebase" fails to start after stashing the user's uncommitted
changes then it forgets to restore the stashed changes and remove the
state directory. To make matters worse, running "git rebase --abort" to
apply the stashed changes and cleanup the state directory fails because
the state directory only contains the "autostash" file and is missing
the "head-name" and "onto" files required by read_basic_state().

Fix this by applying the autostash and removing the state directory if
the pre-rebase hook or initial checkout fail. This matches what
finish_rebase() does at the end of a successful rebase. If the user
modifies any files after the autostash is created it is possible there
will be conflicts when the autostash is applied. In that case
apply_autostash() saves the stash in a new entry under refs/stash and so
it is safe to remove the state directory containing the autostash file.

New tests are added to check the autostash is applied and the state
directory is removed if the rebase fails to start. Checks are also added
to some existing tests in order to ensure there is no state directory
left behind when a rebase fails to start and no autostash has been
created.

Reported-by: Brian Lyles <brianmlyles@gmail.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/rebase.c
t/t3400-rebase.sh
t/t3413-rebase-hook.sh
t/t3420-rebase-autostash.sh