Merge branch 'pw/rebase-autostash-fix'
"git rebase --autostash" failed to resurrect the autostashed changes when the command gets aborted after giving back control asking for hlep in conflict resolution. * pw/rebase-autostash-fix: rebase: apply and cleanup autostash when rebase fails to start
This commit is contained in:
@ -527,6 +527,23 @@ static int rebase_write_basic_state(struct rebase_options *opts)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup_autostash(struct rebase_options *opts)
|
||||
{
|
||||
int ret;
|
||||
struct strbuf dir = STRBUF_INIT;
|
||||
const char *path = state_dir_path("autostash", opts);
|
||||
|
||||
if (!file_exists(path))
|
||||
return 0;
|
||||
ret = apply_autostash(path);
|
||||
strbuf_addstr(&dir, opts->state_dir);
|
||||
if (remove_dir_recursively(&dir, 0))
|
||||
ret = error_errno(_("could not remove '%s'"), opts->state_dir);
|
||||
strbuf_release(&dir);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int finish_rebase(struct rebase_options *opts)
|
||||
{
|
||||
struct strbuf dir = STRBUF_INIT;
|
||||
@ -1727,7 +1744,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||
if (require_clean_work_tree(the_repository, "rebase",
|
||||
_("Please commit or stash them."), 1, 1)) {
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
goto cleanup_autostash;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1750,7 +1767,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||
if (options.switch_to) {
|
||||
ret = checkout_up_to_date(&options);
|
||||
if (ret)
|
||||
goto cleanup;
|
||||
goto cleanup_autostash;
|
||||
}
|
||||
|
||||
if (!(options.flags & REBASE_NO_QUIET))
|
||||
@ -1776,8 +1793,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||
/* If a hook exists, give it a chance to interrupt*/
|
||||
if (!ok_to_skip_pre_rebase &&
|
||||
run_hooks_l(the_repository, "pre-rebase", options.upstream_arg,
|
||||
argc ? argv[0] : NULL, NULL))
|
||||
die(_("The pre-rebase hook refused to rebase."));
|
||||
argc ? argv[0] : NULL, NULL)) {
|
||||
ret = error(_("The pre-rebase hook refused to rebase."));
|
||||
goto cleanup_autostash;
|
||||
}
|
||||
|
||||
if (options.flags & REBASE_DIFFSTAT) {
|
||||
struct diff_options opts;
|
||||
@ -1822,9 +1841,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
||||
RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
|
||||
ropts.head_msg = msg.buf;
|
||||
ropts.default_reflog_action = options.reflog_action;
|
||||
if (reset_head(the_repository, &ropts))
|
||||
die(_("Could not detach HEAD"));
|
||||
strbuf_release(&msg);
|
||||
if (reset_head(the_repository, &ropts)) {
|
||||
ret = error(_("Could not detach HEAD"));
|
||||
goto cleanup_autostash;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the onto is a proper descendant of the tip of the branch, then
|
||||
@ -1852,9 +1872,14 @@ run_rebase:
|
||||
|
||||
cleanup:
|
||||
strbuf_release(&buf);
|
||||
strbuf_release(&msg);
|
||||
strbuf_release(&revisions);
|
||||
rebase_options_release(&options);
|
||||
free(squash_onto_name);
|
||||
free(keep_base_onto_name);
|
||||
return !!ret;
|
||||
|
||||
cleanup_autostash:
|
||||
ret |= !!cleanup_autostash(&options);
|
||||
goto cleanup;
|
||||
}
|
||||
|
Reference in New Issue
Block a user