mirror of
https://github.com/git/git.git
synced 2024-11-24 02:17:02 +08:00
sequencer (rebase -i): respect the rebase.autostash setting
Git's `rebase` command inspects the `rebase.autostash` config setting to determine whether it should stash any uncommitted changes before rebasing and re-apply them afterwards. As we introduce more bits and pieces to let the sequencer act as interactive rebase's backend, here is the part that adds support for the autostash feature. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
795160457d
commit
796c7972c7
43
sequencer.c
43
sequencer.c
@ -113,6 +113,7 @@ static GIT_PATH_FUNC(rebase_path_orig_head, "rebase-merge/orig-head")
|
||||
static GIT_PATH_FUNC(rebase_path_verbose, "rebase-merge/verbose")
|
||||
static GIT_PATH_FUNC(rebase_path_head_name, "rebase-merge/head-name")
|
||||
static GIT_PATH_FUNC(rebase_path_onto, "rebase-merge/onto")
|
||||
static GIT_PATH_FUNC(rebase_path_autostash, "rebase-merge/autostash")
|
||||
|
||||
static inline int is_rebase_i(const struct replay_opts *opts)
|
||||
{
|
||||
@ -1801,6 +1802,47 @@ static enum todo_command peek_command(struct todo_list *todo_list, int offset)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int apply_autostash(struct replay_opts *opts)
|
||||
{
|
||||
struct strbuf stash_sha1 = STRBUF_INIT;
|
||||
struct child_process child = CHILD_PROCESS_INIT;
|
||||
int ret = 0;
|
||||
|
||||
if (!read_oneliner(&stash_sha1, rebase_path_autostash(), 1)) {
|
||||
strbuf_release(&stash_sha1);
|
||||
return 0;
|
||||
}
|
||||
strbuf_trim(&stash_sha1);
|
||||
|
||||
child.git_cmd = 1;
|
||||
argv_array_push(&child.args, "stash");
|
||||
argv_array_push(&child.args, "apply");
|
||||
argv_array_push(&child.args, stash_sha1.buf);
|
||||
if (!run_command(&child))
|
||||
printf(_("Applied autostash."));
|
||||
else {
|
||||
struct child_process store = CHILD_PROCESS_INIT;
|
||||
|
||||
store.git_cmd = 1;
|
||||
argv_array_push(&store.args, "stash");
|
||||
argv_array_push(&store.args, "store");
|
||||
argv_array_push(&store.args, "-m");
|
||||
argv_array_push(&store.args, "autostash");
|
||||
argv_array_push(&store.args, "-q");
|
||||
argv_array_push(&store.args, stash_sha1.buf);
|
||||
if (run_command(&store))
|
||||
ret = error(_("cannot store %s"), stash_sha1.buf);
|
||||
else
|
||||
printf(_("Applying autostash resulted in conflicts.\n"
|
||||
"Your changes are safe in the stash.\n"
|
||||
"You can run \"git stash pop\" or"
|
||||
" \"git stash drop\" at any time.\n"));
|
||||
}
|
||||
|
||||
strbuf_release(&stash_sha1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const char *reflog_message(struct replay_opts *opts,
|
||||
const char *sub_action, const char *fmt, ...)
|
||||
{
|
||||
@ -1980,6 +2022,7 @@ cleanup_head_ref:
|
||||
run_command(&hook);
|
||||
}
|
||||
}
|
||||
apply_autostash(opts);
|
||||
|
||||
strbuf_release(&buf);
|
||||
strbuf_release(&head_ref);
|
||||
|
Loading…
Reference in New Issue
Block a user