@@ -58,6 +58,11 @@ static const char * const git_stash_helper_clear_usage[] = {
58
58
NULL
59
59
};
60
60
61
+ static const char * const git_stash_helper_store_usage [] = {
62
+ N_ ("git stash--helper store [-m|--message <message>] [-q|--quiet] <commit>" ),
63
+ NULL
64
+ };
65
+
61
66
static const char * ref_stash = "refs/stash" ;
62
67
static struct strbuf stash_index_path = STRBUF_INIT ;
63
68
@@ -730,6 +735,61 @@ static int show_stash(int argc, const char **argv, const char *prefix)
730
735
return diff_result_code (& rev .diffopt , 0 );
731
736
}
732
737
738
+ static int do_store_stash (const struct object_id * w_commit , const char * stash_msg ,
739
+ int quiet )
740
+ {
741
+ if (!stash_msg )
742
+ stash_msg = "Created via \"git stash store\"." ;
743
+
744
+ if (update_ref (stash_msg , ref_stash , w_commit , NULL ,
745
+ REF_FORCE_CREATE_REFLOG ,
746
+ quiet ? UPDATE_REFS_QUIET_ON_ERR :
747
+ UPDATE_REFS_MSG_ON_ERR )) {
748
+ if (!quiet ) {
749
+ fprintf_ln (stderr , _ ("Cannot update %s with %s" ),
750
+ ref_stash , oid_to_hex (w_commit ));
751
+ }
752
+ return -1 ;
753
+ }
754
+
755
+ return 0 ;
756
+ }
757
+
758
+ static int store_stash (int argc , const char * * argv , const char * prefix )
759
+ {
760
+ int quiet = 0 ;
761
+ const char * stash_msg = NULL ;
762
+ struct object_id obj ;
763
+ struct object_context dummy ;
764
+ struct option options [] = {
765
+ OPT__QUIET (& quiet , N_ ("be quiet" )),
766
+ OPT_STRING ('m' , "message" , & stash_msg , "message" ,
767
+ N_ ("stash message" )),
768
+ OPT_END ()
769
+ };
770
+
771
+ argc = parse_options (argc , argv , prefix , options ,
772
+ git_stash_helper_store_usage ,
773
+ PARSE_OPT_KEEP_UNKNOWN );
774
+
775
+ if (argc != 1 ) {
776
+ if (!quiet )
777
+ fprintf_ln (stderr , _ ("\"git stash store\" requires one "
778
+ "<commit> argument" ));
779
+ return -1 ;
780
+ }
781
+
782
+ if (get_oid_with_context (argv [0 ], quiet ? GET_OID_QUIETLY : 0 , & obj ,
783
+ & dummy )) {
784
+ if (!quiet )
785
+ fprintf_ln (stderr , _ ("Cannot update %s with %s" ),
786
+ ref_stash , argv [0 ]);
787
+ return -1 ;
788
+ }
789
+
790
+ return do_store_stash (& obj , stash_msg , quiet );
791
+ }
792
+
733
793
int cmd_stash__helper (int argc , const char * * argv , const char * prefix )
734
794
{
735
795
pid_t pid = getpid ();
@@ -764,6 +824,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
764
824
return !!list_stash (argc , argv , prefix );
765
825
else if (!strcmp (argv [0 ], "show" ))
766
826
return !!show_stash (argc , argv , prefix );
827
+ else if (!strcmp (argv [0 ], "store" ))
828
+ return !!store_stash (argc , argv , prefix );
767
829
768
830
usage_msg_opt (xstrfmt (_ ("unknown subcommand: %s" ), argv [0 ]),
769
831
git_stash_helper_usage , options );
0 commit comments