@@ -27,6 +27,8 @@ static const char * const git_stash_helper_usage[] = {
2727 N_ ("git stash--helper [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
2828 " [-u|--include-untracked] [-a|--all] [-m|--message <message>]\n"
2929 " [--] [<pathspec>...]]" ),
30+ N_ ("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
31+ " [-u|--include-untracked] [-a|--all] [<message>]" ),
3032 NULL
3133};
3234
@@ -82,6 +84,12 @@ static const char * const git_stash_helper_push_usage[] = {
8284 NULL
8385};
8486
87+ static const char * const git_stash_helper_save_usage [] = {
88+ N_ ("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
89+ " [-u|--include-untracked] [-a|--all] [<message>]" ),
90+ NULL
91+ };
92+
8593static const char * ref_stash = "refs/stash" ;
8694static struct strbuf stash_index_path = STRBUF_INIT ;
8795
@@ -1488,6 +1496,46 @@ static int push_stash(int argc, const char **argv, const char *prefix)
14881496 include_untracked );
14891497}
14901498
1499+ static int save_stash (int argc , const char * * argv , const char * prefix )
1500+ {
1501+ int keep_index = -1 ;
1502+ int patch_mode = 0 ;
1503+ int include_untracked = 0 ;
1504+ int quiet = 0 ;
1505+ int ret = 0 ;
1506+ const char * stash_msg = NULL ;
1507+ struct pathspec ps ;
1508+ struct strbuf stash_msg_buf = STRBUF_INIT ;
1509+ struct option options [] = {
1510+ OPT_BOOL ('k' , "keep-index" , & keep_index ,
1511+ N_ ("keep index" )),
1512+ OPT_BOOL ('p' , "patch" , & patch_mode ,
1513+ N_ ("stash in patch mode" )),
1514+ OPT__QUIET (& quiet , N_ ("quiet mode" )),
1515+ OPT_BOOL ('u' , "include-untracked" , & include_untracked ,
1516+ N_ ("include untracked files in stash" )),
1517+ OPT_SET_INT ('a' , "all" , & include_untracked ,
1518+ N_ ("include ignore files" ), 2 ),
1519+ OPT_STRING ('m' , "message" , & stash_msg , "message" ,
1520+ N_ ("stash message" )),
1521+ OPT_END ()
1522+ };
1523+
1524+ argc = parse_options (argc , argv , prefix , options ,
1525+ git_stash_helper_save_usage ,
1526+ PARSE_OPT_KEEP_DASHDASH );
1527+
1528+ if (argc )
1529+ stash_msg = strbuf_join_argv (& stash_msg_buf , argc , argv , ' ' );
1530+
1531+ memset (& ps , 0 , sizeof (ps ));
1532+ ret = do_push_stash (ps , stash_msg , quiet , keep_index ,
1533+ patch_mode , include_untracked );
1534+
1535+ strbuf_release (& stash_msg_buf );
1536+ return ret ;
1537+ }
1538+
14911539int cmd_stash__helper (int argc , const char * * argv , const char * prefix )
14921540{
14931541 pid_t pid = getpid ();
@@ -1528,6 +1576,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
15281576 return !!create_stash (argc , argv , prefix );
15291577 else if (!strcmp (argv [0 ], "push" ))
15301578 return !!push_stash (argc , argv , prefix );
1579+ else if (!strcmp (argv [0 ], "save" ))
1580+ return !!save_stash (argc , argv , prefix );
15311581
15321582 usage_msg_opt (xstrfmt (_ ("unknown subcommand: %s" ), argv [0 ]),
15331583 git_stash_helper_usage , options );
0 commit comments