@@ -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
@@ -1492,6 +1500,46 @@ static int push_stash(int argc, const char **argv, const char *prefix)
14921500 include_untracked );
14931501}
14941502
1503+ static int save_stash (int argc , const char * * argv , const char * prefix )
1504+ {
1505+ int keep_index = -1 ;
1506+ int patch_mode = 0 ;
1507+ int include_untracked = 0 ;
1508+ int quiet = 0 ;
1509+ int ret = 0 ;
1510+ const char * stash_msg = NULL ;
1511+ struct pathspec ps ;
1512+ struct strbuf stash_msg_buf = STRBUF_INIT ;
1513+ struct option options [] = {
1514+ OPT_BOOL ('k' , "keep-index" , & keep_index ,
1515+ N_ ("keep index" )),
1516+ OPT_BOOL ('p' , "patch" , & patch_mode ,
1517+ N_ ("stash in patch mode" )),
1518+ OPT__QUIET (& quiet , N_ ("quiet mode" )),
1519+ OPT_BOOL ('u' , "include-untracked" , & include_untracked ,
1520+ N_ ("include untracked files in stash" )),
1521+ OPT_SET_INT ('a' , "all" , & include_untracked ,
1522+ N_ ("include ignore files" ), 2 ),
1523+ OPT_STRING ('m' , "message" , & stash_msg , "message" ,
1524+ N_ ("stash message" )),
1525+ OPT_END ()
1526+ };
1527+
1528+ argc = parse_options (argc , argv , prefix , options ,
1529+ git_stash_helper_save_usage ,
1530+ PARSE_OPT_KEEP_DASHDASH );
1531+
1532+ if (argc )
1533+ stash_msg = strbuf_join_argv (& stash_msg_buf , argc , argv , ' ' );
1534+
1535+ memset (& ps , 0 , sizeof (ps ));
1536+ ret = do_push_stash (ps , stash_msg , quiet , keep_index ,
1537+ patch_mode , include_untracked );
1538+
1539+ strbuf_release (& stash_msg_buf );
1540+ return ret ;
1541+ }
1542+
14951543int cmd_stash__helper (int argc , const char * * argv , const char * prefix )
14961544{
14971545 pid_t pid = getpid ();
@@ -1532,6 +1580,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
15321580 return !!create_stash (argc , argv , prefix );
15331581 else if (!strcmp (argv [0 ], "push" ))
15341582 return !!push_stash (argc , argv , prefix );
1583+ else if (!strcmp (argv [0 ], "save" ))
1584+ return !!save_stash (argc , argv , prefix );
15351585
15361586 usage_msg_opt (xstrfmt (_ ("unknown subcommand: %s" ), argv [0 ]),
15371587 git_stash_helper_usage , options );
0 commit comments