16
16
17
17
#define INCLUDE_ALL_FILES 2
18
18
19
- static const char * const git_stash_helper_usage [] = {
20
- N_ ("git stash--helper list [<options>]" ),
21
- N_ ("git stash--helper show [<options>] [<stash>]" ),
22
- N_ ("git stash--helper drop [-q|--quiet] [<stash>]" ),
23
- N_ ("git stash--helper ( pop | apply ) [--index] [-q|--quiet] [<stash>]" ),
24
- N_ ("git stash--helper branch <branchname> [<stash>]" ),
25
- N_ ("git stash--helper clear" ),
26
- N_ ("git stash--helper [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
19
+ static const char * const git_stash_usage [] = {
20
+ N_ ("git stash list [<options>]" ),
21
+ N_ ("git stash show [<options>] [<stash>]" ),
22
+ N_ ("git stash drop [-q|--quiet] [<stash>]" ),
23
+ N_ ("git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]" ),
24
+ N_ ("git stash branch <branchname> [<stash>]" ),
25
+ N_ ("git stash clear" ),
26
+ N_ ("git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
27
27
" [-u|--include-untracked] [-a|--all] [-m|--message <message>]\n"
28
28
" [--] [<pathspec>...]]" ),
29
- N_ ("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
29
+ N_ ("git stash save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
30
30
" [-u|--include-untracked] [-a|--all] [<message>]" ),
31
31
NULL
32
32
};
33
33
34
- static const char * const git_stash_helper_list_usage [] = {
35
- N_ ("git stash--helper list [<options>]" ),
34
+ static const char * const git_stash_list_usage [] = {
35
+ N_ ("git stash list [<options>]" ),
36
36
NULL
37
37
};
38
38
39
- static const char * const git_stash_helper_show_usage [] = {
40
- N_ ("git stash--helper show [<options>] [<stash>]" ),
39
+ static const char * const git_stash_show_usage [] = {
40
+ N_ ("git stash show [<options>] [<stash>]" ),
41
41
NULL
42
42
};
43
43
44
- static const char * const git_stash_helper_drop_usage [] = {
45
- N_ ("git stash--helper drop [-q|--quiet] [<stash>]" ),
44
+ static const char * const git_stash_drop_usage [] = {
45
+ N_ ("git stash drop [-q|--quiet] [<stash>]" ),
46
46
NULL
47
47
};
48
48
49
- static const char * const git_stash_helper_pop_usage [] = {
50
- N_ ("git stash--helper pop [--index] [-q|--quiet] [<stash>]" ),
49
+ static const char * const git_stash_pop_usage [] = {
50
+ N_ ("git stash pop [--index] [-q|--quiet] [<stash>]" ),
51
51
NULL
52
52
};
53
53
54
- static const char * const git_stash_helper_apply_usage [] = {
55
- N_ ("git stash--helper apply [--index] [-q|--quiet] [<stash>]" ),
54
+ static const char * const git_stash_apply_usage [] = {
55
+ N_ ("git stash apply [--index] [-q|--quiet] [<stash>]" ),
56
56
NULL
57
57
};
58
58
59
- static const char * const git_stash_helper_branch_usage [] = {
60
- N_ ("git stash--helper branch <branchname> [<stash>]" ),
59
+ static const char * const git_stash_branch_usage [] = {
60
+ N_ ("git stash branch <branchname> [<stash>]" ),
61
61
NULL
62
62
};
63
63
64
- static const char * const git_stash_helper_clear_usage [] = {
65
- N_ ("git stash--helper clear" ),
64
+ static const char * const git_stash_clear_usage [] = {
65
+ N_ ("git stash clear" ),
66
66
NULL
67
67
};
68
68
69
- static const char * const git_stash_helper_store_usage [] = {
70
- N_ ("git stash--helper store [-m|--message <message>] [-q|--quiet] <commit>" ),
69
+ static const char * const git_stash_store_usage [] = {
70
+ N_ ("git stash store [-m|--message <message>] [-q|--quiet] <commit>" ),
71
71
NULL
72
72
};
73
73
74
- static const char * const git_stash_helper_create_usage [] = {
75
- N_ ("git stash--helper create [<message>]" ),
76
- NULL
77
- };
78
-
79
- static const char * const git_stash_helper_push_usage [] = {
80
- N_ ("git stash--helper [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
74
+ static const char * const git_stash_push_usage [] = {
75
+ N_ ("git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
81
76
" [-u|--include-untracked] [-a|--all] [-m|--message <message>]\n"
82
77
" [--] [<pathspec>...]]" ),
83
78
NULL
84
79
};
85
80
86
- static const char * const git_stash_helper_save_usage [] = {
87
- N_ ("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
81
+ static const char * const git_stash_save_usage [] = {
82
+ N_ ("git stash save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
88
83
" [-u|--include-untracked] [-a|--all] [<message>]" ),
89
84
NULL
90
85
};
@@ -221,7 +216,7 @@ static int clear_stash(int argc, const char **argv, const char *prefix)
221
216
};
222
217
223
218
argc = parse_options (argc , argv , prefix , options ,
224
- git_stash_helper_clear_usage ,
219
+ git_stash_clear_usage ,
225
220
PARSE_OPT_STOP_AT_NON_OPTION );
226
221
227
222
if (argc )
@@ -526,7 +521,7 @@ static int apply_stash(int argc, const char **argv, const char *prefix)
526
521
};
527
522
528
523
argc = parse_options (argc , argv , prefix , options ,
529
- git_stash_helper_apply_usage , 0 );
524
+ git_stash_apply_usage , 0 );
530
525
531
526
if (get_stash_info (& info , argc , argv ))
532
527
return -1 ;
@@ -599,7 +594,7 @@ static int drop_stash(int argc, const char **argv, const char *prefix)
599
594
};
600
595
601
596
argc = parse_options (argc , argv , prefix , options ,
602
- git_stash_helper_drop_usage , 0 );
597
+ git_stash_drop_usage , 0 );
603
598
604
599
if (get_stash_info (& info , argc , argv ))
605
600
return -1 ;
@@ -625,7 +620,7 @@ static int pop_stash(int argc, const char **argv, const char *prefix)
625
620
};
626
621
627
622
argc = parse_options (argc , argv , prefix , options ,
628
- git_stash_helper_pop_usage , 0 );
623
+ git_stash_pop_usage , 0 );
629
624
630
625
if (get_stash_info (& info , argc , argv ))
631
626
return -1 ;
@@ -652,7 +647,7 @@ static int branch_stash(int argc, const char **argv, const char *prefix)
652
647
};
653
648
654
649
argc = parse_options (argc , argv , prefix , options ,
655
- git_stash_helper_branch_usage , 0 );
650
+ git_stash_branch_usage , 0 );
656
651
657
652
if (!argc ) {
658
653
fprintf_ln (stderr , _ ("No branch name specified" ));
@@ -687,7 +682,7 @@ static int list_stash(int argc, const char **argv, const char *prefix)
687
682
};
688
683
689
684
argc = parse_options (argc , argv , prefix , options ,
690
- git_stash_helper_list_usage ,
685
+ git_stash_list_usage ,
691
686
PARSE_OPT_KEEP_UNKNOWN );
692
687
693
688
if (!ref_exists (ref_stash ))
@@ -767,7 +762,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
767
762
argc = setup_revisions (argc , argv , & rev , NULL );
768
763
if (argc > 1 ) {
769
764
free_stash_info (& info );
770
- usage_with_options (git_stash_helper_show_usage , options );
765
+ usage_with_options (git_stash_show_usage , options );
771
766
}
772
767
773
768
rev .diffopt .flags .recursive = 1 ;
@@ -813,7 +808,7 @@ static int store_stash(int argc, const char **argv, const char *prefix)
813
808
};
814
809
815
810
argc = parse_options (argc , argv , prefix , options ,
816
- git_stash_helper_store_usage ,
811
+ git_stash_store_usage ,
817
812
PARSE_OPT_KEEP_UNKNOWN );
818
813
819
814
if (argc != 1 ) {
@@ -1237,28 +1232,16 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
1237
1232
1238
1233
static int create_stash (int argc , const char * * argv , const char * prefix )
1239
1234
{
1240
- int include_untracked = 0 ;
1241
1235
int ret = 0 ;
1242
- const char * stash_msg = NULL ;
1243
1236
struct strbuf stash_msg_buf = STRBUF_INIT ;
1244
1237
struct stash_info info ;
1245
1238
struct pathspec ps ;
1246
- struct option options [] = {
1247
- OPT_BOOL ('u' , "include-untracked" , & include_untracked ,
1248
- N_ ("include untracked files in stash" )),
1249
- OPT_STRING ('m' , "message" , & stash_msg , N_ ("message" ),
1250
- N_ ("stash message" )),
1251
- OPT_END ()
1252
- };
1253
1239
1254
- argc = parse_options (argc , argv , prefix , options ,
1255
- git_stash_helper_create_usage ,
1256
- 0 );
1240
+ /* Starting with argv[1], since argv[0] is "create" */
1241
+ strbuf_join_argv (& stash_msg_buf , argc - 1 , ++ argv , ' ' );
1257
1242
1258
1243
memset (& ps , 0 , sizeof (ps ));
1259
- strbuf_addstr (& stash_msg_buf , stash_msg );
1260
- ret = do_create_stash (ps , & stash_msg_buf , include_untracked , 0 , & info ,
1261
- NULL , 0 );
1244
+ ret = do_create_stash (ps , & stash_msg_buf , 0 , 0 , & info , NULL , 0 );
1262
1245
1263
1246
if (!ret )
1264
1247
printf_ln ("%s" , oid_to_hex (& info .w_commit ));
@@ -1493,9 +1476,10 @@ static int push_stash(int argc, const char **argv, const char *prefix)
1493
1476
OPT_END ()
1494
1477
};
1495
1478
1496
- argc = parse_options (argc , argv , prefix , options ,
1497
- git_stash_helper_push_usage ,
1498
- 0 );
1479
+ if (argc )
1480
+ argc = parse_options (argc , argv , prefix , options ,
1481
+ git_stash_push_usage ,
1482
+ 0 );
1499
1483
1500
1484
parse_pathspec (& ps , 0 , PATHSPEC_PREFER_FULL , prefix , argv );
1501
1485
return do_push_stash (ps , stash_msg , quiet , keep_index , patch_mode ,
@@ -1528,7 +1512,7 @@ static int save_stash(int argc, const char **argv, const char *prefix)
1528
1512
};
1529
1513
1530
1514
argc = parse_options (argc , argv , prefix , options ,
1531
- git_stash_helper_save_usage ,
1515
+ git_stash_save_usage ,
1532
1516
PARSE_OPT_KEEP_DASHDASH );
1533
1517
1534
1518
if (argc )
@@ -1542,27 +1526,29 @@ static int save_stash(int argc, const char **argv, const char *prefix)
1542
1526
return ret ;
1543
1527
}
1544
1528
1545
- int cmd_stash__helper (int argc , const char * * argv , const char * prefix )
1529
+ int cmd_stash (int argc , const char * * argv , const char * prefix )
1546
1530
{
1531
+ int i = -1 ;
1547
1532
pid_t pid = getpid ();
1548
1533
const char * index_file ;
1534
+ struct argv_array args = ARGV_ARRAY_INIT ;
1549
1535
1550
1536
struct option options [] = {
1551
1537
OPT_END ()
1552
1538
};
1553
1539
1554
1540
git_config (git_diff_basic_config , NULL );
1555
1541
1556
- argc = parse_options (argc , argv , prefix , options , git_stash_helper_usage ,
1542
+ argc = parse_options (argc , argv , prefix , options , git_stash_usage ,
1557
1543
PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH );
1558
1544
1559
1545
index_file = get_index_file ();
1560
1546
strbuf_addf (& stash_index_path , "%s.stash.%" PRIuMAX , index_file ,
1561
1547
(uintmax_t )pid );
1562
1548
1563
- if (argc < 1 )
1564
- usage_with_options ( git_stash_helper_usage , options );
1565
- if (!strcmp (argv [0 ], "apply" ))
1549
+ if (! argc )
1550
+ return !! push_stash ( 0 , NULL , prefix );
1551
+ else if (!strcmp (argv [0 ], "apply" ))
1566
1552
return !!apply_stash (argc , argv , prefix );
1567
1553
else if (!strcmp (argv [0 ], "clear" ))
1568
1554
return !!clear_stash (argc , argv , prefix );
@@ -1584,7 +1570,42 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
1584
1570
return !!push_stash (argc , argv , prefix );
1585
1571
else if (!strcmp (argv [0 ], "save" ))
1586
1572
return !!save_stash (argc , argv , prefix );
1573
+ else if (* argv [0 ] != '-' )
1574
+ usage_msg_opt (xstrfmt (_ ("unknown subcommand: %s" ), argv [0 ]),
1575
+ git_stash_usage , options );
1576
+
1577
+ if (strcmp (argv [0 ], "-p" )) {
1578
+ while (++ i < argc && strcmp (argv [i ], "--" )) {
1579
+ /*
1580
+ * `akpqu` is a string which contains all short options,
1581
+ * except `-m` which is verified separately.
1582
+ */
1583
+ if ((strlen (argv [i ]) == 2 ) && * argv [i ] == '-' &&
1584
+ strchr ("akpqu" , argv [i ][1 ]))
1585
+ continue ;
1586
+
1587
+ if (!strcmp (argv [i ], "--all" ) ||
1588
+ !strcmp (argv [i ], "--keep-index" ) ||
1589
+ !strcmp (argv [i ], "--no-keep-index" ) ||
1590
+ !strcmp (argv [i ], "--patch" ) ||
1591
+ !strcmp (argv [i ], "--quiet" ) ||
1592
+ !strcmp (argv [i ], "--include-untracked" ))
1593
+ continue ;
1594
+
1595
+ /*
1596
+ * `-m` and `--message=` are verified separately because
1597
+ * they need to be immediately followed by a string
1598
+ * (i.e.`-m"foobar"` or `--message="foobar"`).
1599
+ */
1600
+ if (starts_with (argv [i ], "-m" ) ||
1601
+ starts_with (argv [i ], "--message=" ))
1602
+ continue ;
1603
+
1604
+ usage_with_options (git_stash_usage , options );
1605
+ }
1606
+ }
1587
1607
1588
- usage_msg_opt (xstrfmt (_ ("unknown subcommand: %s" ), argv [0 ]),
1589
- git_stash_helper_usage , options );
1608
+ argv_array_push (& args , "push" );
1609
+ argv_array_pushv (& args , argv );
1610
+ return !!push_stash (args .argc , args .argv , prefix );
1590
1611
}
0 commit comments