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