From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>,
Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Daniel Hahler <git@thequod.de>,
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Subject: [PATCH v2] rebase -i: restore autostash on abort
Date: Wed, 29 Jun 2016 08:21:27 +0200 [thread overview]
Message-ID: <20160629062127.8946-1-ps@pks.im> (raw)
In-Reply-To: <20160628175704.26095-1-ps@pks.im>
When we abort an interactive rebase we do so by calling
`die_abort`, which cleans up after us by removing the rebase
state directory. If the user has requested to use the autostash
feature, though, the state directory may also contain a reference
to the autostash, which will now be deleted.
Fix the issue by trying to re-apply the autostash in `die_abort`.
This will also handle the case where the autostash does not apply
cleanly anymore by recording it in a user-visible stash.
Reported-by: Daniel Hahler <git@thequod.de>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
The original bug-report can be found at [1], the previous version
of this patch at [2].
I've included a second test which now also tests how we fare when
we actually fail to restore the autostash after the editor has
been aborted.
Another minor change is fixing of a typo inherited from the
previous test "abort rebase -i with --autostash" (commited ->
committed). I don't think there's any benefit in fixing the typo
in the existing test so I'll just keep it there.
[1]: http://article.gmane.org/gmane.comp.version-control.git/297404
[2]: http://article.gmane.org/gmane.comp.version-control.git/298481
git-rebase--interactive.sh | 1 +
t/t3420-rebase-autostash.sh | 31 +++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 05f22e4..4f499d2 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -212,6 +212,7 @@ exit_with_patch () {
}
die_abort () {
+ apply_autostash
rm -rf "$state_dir"
die "$1"
}
diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh
index 944154b..532ff5c 100755
--- a/t/t3420-rebase-autostash.sh
+++ b/t/t3420-rebase-autostash.sh
@@ -192,4 +192,35 @@ test_expect_success 'abort rebase -i with --autostash' '
test_cmp expected file0
'
+test_expect_success 'restore autostash on editor failure' '
+ test_when_finished "git reset --hard" &&
+ echo uncommitted-content >file0 &&
+ (
+ test_set_editor "false" &&
+ test_must_fail git rebase -i --autostash HEAD^
+ ) &&
+ echo uncommitted-content >expected &&
+ test_cmp expected file0
+'
+
+test_expect_success 'autostash is saved on editor failure with conflict' '
+ test_when_finished "git reset --hard" &&
+ echo uncommitted-content >file0 &&
+ (
+ write_script abort-editor.sh <<-\EOF &&
+ echo conflicting-content >file0
+ exit 1
+ EOF
+ test_set_editor "$(pwd)/abort-editor.sh" &&
+ test_must_fail git rebase -i --autostash HEAD^ &&
+ rm -f abort-editor.sh
+ ) &&
+ echo conflicting-content >expected &&
+ test_cmp expected file0 &&
+ git checkout file0 &&
+ git stash pop &&
+ echo uncommitted-content >expected &&
+ test_cmp expected file0
+'
+
test_done
--
2.9.0
next prev parent reply other threads:[~2016-06-29 6:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-28 17:57 [PATCH] rebase -i: restore autostash on abort Patrick Steinhardt
2016-06-28 19:02 ` Junio C Hamano
2016-06-28 20:42 ` Matthieu Moy
2016-06-28 21:13 ` Junio C Hamano
2016-06-29 6:28 ` Patrick Steinhardt
2016-06-29 6:21 ` Patrick Steinhardt [this message]
2016-06-29 14:02 ` [PATCH v2] " Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160629062127.8946-1-ps@pks.im \
--to=ps@pks.im \
--cc=Johannes.Schindelin@gmx.de \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=git@thequod.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).