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>
Johannes Schindelin committed
Jan 2, 2017 at 16:28 UTC
796c7972c7236634655d2333333e9f871149b994
1 file changed
+43
sequencer.c
+43
@@ -113,6 +113,7 @@ static GIT_PATH_FUNC(rebase_path_orig_head, "rebase-merge/orig-head")
113
static GIT_PATH_FUNC(rebase_path_verbose, "rebase-merge/verbose")
114
static GIT_PATH_FUNC(rebase_path_head_name, "rebase-merge/head-name")
115
static GIT_PATH_FUNC(rebase_path_onto, "rebase-merge/onto")
116
+static GIT_PATH_FUNC(rebase_path_autostash, "rebase-merge/autostash")
117
118
static inline int is_rebase_i(const struct replay_opts *opts)
119
{
@@ -1801,6 +1802,47 @@ static enum todo_command peek_command(struct todo_list *todo_list, int offset)
1802
return -1;
1803
}
1804
1805
+static int apply_autostash(struct replay_opts *opts)
1806
+{
1807
+ struct strbuf stash_sha1 = STRBUF_INIT;
1808
+ struct child_process child = CHILD_PROCESS_INIT;
1809
+ int ret = 0;
1810
+
1811
+ if (!read_oneliner(&stash_sha1, rebase_path_autostash(), 1)) {
1812
+ strbuf_release(&stash_sha1);
1813
+ return 0;
1814
+ }
1815
+ strbuf_trim(&stash_sha1);
1816
+
1817
+ child.git_cmd = 1;
1818
+ argv_array_push(&child.args, "stash");
1819
+ argv_array_push(&child.args, "apply");
1820
+ argv_array_push(&child.args, stash_sha1.buf);
1821
+ if (!run_command(&child))
1822
+ printf(_("Applied autostash."));
1823
+ else {
1824
+ struct child_process store = CHILD_PROCESS_INIT;
1825
+
1826
+ store.git_cmd = 1;
1827
+ argv_array_push(&store.args, "stash");
1828
+ argv_array_push(&store.args, "store");
1829
+ argv_array_push(&store.args, "-m");
1830
+ argv_array_push(&store.args, "autostash");
1831
+ argv_array_push(&store.args, "-q");
1832
+ argv_array_push(&store.args, stash_sha1.buf);
1833
+ if (run_command(&store))
1834
+ ret = error(_("cannot store %s"), stash_sha1.buf);
1835
+ else
1836
+ printf(_("Applying autostash resulted in conflicts.\n"
1837
+ "Your changes are safe in the stash.\n"
1838
+ "You can run \"git stash pop\" or"
1839
+ " \"git stash drop\" at any time.\n"));
1840
+ }
1841
+
1842
+ strbuf_release(&stash_sha1);
1843
+ return ret;
1844
+}
1845
+
1846
static const char *reflog_message(struct replay_opts *opts,
1847
const char *sub_action, const char *fmt, ...)
1848
{
@@ -1980,6 +2022,7 @@ cleanup_head_ref:
2022
run_command(&hook);
2023
}
2024
}
2025
+ apply_autostash(opts);
2026
2027
strbuf_release(&buf);
2028
strbuf_release(&head_ref);