@@ -110,6 +110,7 @@ static GIT_PATH_FUNC(orig_head, "rebase-merge/orig-head")
110110static GIT_PATH_FUNC (git_path_rebase_verbose , "rebase-merge/verbose" ) /* TODO: turn into opt */
111111static GIT_PATH_FUNC (git_path_strategy , "rebase-merge/strategy" )
112112static GIT_PATH_FUNC (git_path_strategy_opts , "rebase-merge/strategy_opts" )
113+ static GIT_PATH_FUNC (autostash , "rebase-merge/autostash" )
113114
114115#define IS_REBASE_I () (opts->action == REPLAY_INTERACTIVE_REBASE)
115116
@@ -1670,6 +1671,47 @@ static enum todo_command peek_command(struct todo_list *todo_list, int offset)
16701671 return -1 ;
16711672}
16721673
1674+ static int apply_autostash (struct replay_opts * opts )
1675+ {
1676+ struct strbuf stash_sha1 = STRBUF_INIT ;
1677+ struct child_process child = CHILD_PROCESS_INIT ;
1678+ int ret = 0 ;
1679+
1680+ if (strbuf_read_file (& stash_sha1 , autostash (), 0 ) <= 0 ) {
1681+ strbuf_release (& stash_sha1 );
1682+ return 0 ;
1683+ }
1684+ strbuf_trim (& stash_sha1 );
1685+
1686+ child .git_cmd = 1 ;
1687+ argv_array_push (& child .args , "stash" );
1688+ argv_array_push (& child .args , "apply" );
1689+ argv_array_push (& child .args , stash_sha1 .buf );
1690+ if (!run_command (& child ))
1691+ printf (_ ("Applied autostash." ));
1692+ else {
1693+ struct child_process store = CHILD_PROCESS_INIT ;
1694+
1695+ store .git_cmd = 1 ;
1696+ argv_array_push (& store .args , "stash" );
1697+ argv_array_push (& store .args , "store" );
1698+ argv_array_push (& store .args , "-m" );
1699+ argv_array_push (& store .args , "autostash" );
1700+ argv_array_push (& store .args , "-q" );
1701+ argv_array_push (& store .args , stash_sha1 .buf );
1702+ if (run_command (& store ))
1703+ ret = error (_ ("Cannot store %s" ), stash_sha1 .buf );
1704+ else
1705+ printf (_ ("Applying autostash resulted in conflicts.\n"
1706+ "Your changes are safe in the stash.\n"
1707+ "You can run \"git stash pop\" or"
1708+ " \"git stash drop\" at any time.\n" ));
1709+ }
1710+
1711+ strbuf_release (& stash_sha1 );
1712+ return ret ;
1713+ }
1714+
16731715static const char * reflog_message (struct replay_opts * opts ,
16741716 const char * sub_action , const char * fmt , ...)
16751717{
@@ -1822,6 +1864,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
18221864 /* we don't care if this copying failed */
18231865 run_command (& child );
18241866 }
1867+ apply_autostash (opts );
18251868
18261869 strbuf_release (& buf );
18271870 strbuf_release (& head_ref );
0 commit comments