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 ) {
@@ -1227,29 +1222,18 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
1227
1222
1228
1223
static int create_stash (int argc , const char * * argv , const char * prefix )
1229
1224
{
1230
- int include_untracked = 0 ;
1231
1225
int ret = 0 ;
1232
- const char * stash_msg = NULL ;
1233
1226
struct strbuf stash_msg_buf = STRBUF_INIT ;
1234
1227
struct stash_info info ;
1235
1228
struct pathspec ps ;
1236
- struct option options [] = {
1237
- OPT_BOOL ('u' , "include-untracked" , & include_untracked ,
1238
- N_ ("include untracked files in stash" )),
1239
- OPT_STRING ('m' , "message" , & stash_msg , N_ ("message" ),
1240
- N_ ("stash message" )),
1241
- OPT_END ()
1242
- };
1243
1229
1244
- argc = parse_options (argc , argv , prefix , options ,
1245
- git_stash_helper_create_usage ,
1246
- 0 );
1230
+ /* Starting with argv[1], since argv[0] is "create" */
1231
+ strbuf_join_argv (& stash_msg_buf , argc - 1 , ++ argv , ' ' );
1247
1232
1248
1233
memset (& ps , 0 , sizeof (ps ));
1249
1234
if (!check_changes_tracked_files (ps ))
1250
1235
return 0 ;
1251
1236
1252
- strbuf_addstr (& stash_msg_buf , stash_msg );
1253
1237
if (!(ret = do_create_stash (ps , & stash_msg_buf , 0 , 0 , & info , NULL , 0 )))
1254
1238
printf_ln ("%s" , oid_to_hex (& info .w_commit ));
1255
1239
@@ -1479,9 +1463,10 @@ static int push_stash(int argc, const char **argv, const char *prefix)
1479
1463
OPT_END ()
1480
1464
};
1481
1465
1482
- argc = parse_options (argc , argv , prefix , options ,
1483
- git_stash_helper_push_usage ,
1484
- 0 );
1466
+ if (argc )
1467
+ argc = parse_options (argc , argv , prefix , options ,
1468
+ git_stash_push_usage ,
1469
+ 0 );
1485
1470
1486
1471
parse_pathspec (& ps , 0 , PATHSPEC_PREFER_FULL , prefix , argv );
1487
1472
return do_push_stash (ps , stash_msg , quiet , keep_index , patch_mode ,
@@ -1514,7 +1499,7 @@ static int save_stash(int argc, const char **argv, const char *prefix)
1514
1499
};
1515
1500
1516
1501
argc = parse_options (argc , argv , prefix , options ,
1517
- git_stash_helper_save_usage ,
1502
+ git_stash_save_usage ,
1518
1503
PARSE_OPT_KEEP_DASHDASH );
1519
1504
1520
1505
if (argc )
@@ -1528,27 +1513,29 @@ static int save_stash(int argc, const char **argv, const char *prefix)
1528
1513
return ret ;
1529
1514
}
1530
1515
1531
- int cmd_stash__helper (int argc , const char * * argv , const char * prefix )
1516
+ int cmd_stash (int argc , const char * * argv , const char * prefix )
1532
1517
{
1518
+ int i = -1 ;
1533
1519
pid_t pid = getpid ();
1534
1520
const char * index_file ;
1521
+ struct argv_array args = ARGV_ARRAY_INIT ;
1535
1522
1536
1523
struct option options [] = {
1537
1524
OPT_END ()
1538
1525
};
1539
1526
1540
1527
git_config (git_diff_basic_config , NULL );
1541
1528
1542
- argc = parse_options (argc , argv , prefix , options , git_stash_helper_usage ,
1529
+ argc = parse_options (argc , argv , prefix , options , git_stash_usage ,
1543
1530
PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH );
1544
1531
1545
1532
index_file = get_index_file ();
1546
1533
strbuf_addf (& stash_index_path , "%s.stash.%" PRIuMAX , index_file ,
1547
1534
(uintmax_t )pid );
1548
1535
1549
- if (argc < 1 )
1550
- usage_with_options ( git_stash_helper_usage , options );
1551
- if (!strcmp (argv [0 ], "apply" ))
1536
+ if (! argc )
1537
+ return !! push_stash ( 0 , NULL , prefix );
1538
+ else if (!strcmp (argv [0 ], "apply" ))
1552
1539
return !!apply_stash (argc , argv , prefix );
1553
1540
else if (!strcmp (argv [0 ], "clear" ))
1554
1541
return !!clear_stash (argc , argv , prefix );
@@ -1570,7 +1557,42 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
1570
1557
return !!push_stash (argc , argv , prefix );
1571
1558
else if (!strcmp (argv [0 ], "save" ))
1572
1559
return !!save_stash (argc , argv , prefix );
1560
+ else if (* argv [0 ] != '-' )
1561
+ usage_msg_opt (xstrfmt (_ ("unknown subcommand: %s" ), argv [0 ]),
1562
+ git_stash_usage , options );
1563
+
1564
+ if (strcmp (argv [0 ], "-p" )) {
1565
+ while (++ i < argc && strcmp (argv [i ], "--" )) {
1566
+ /*
1567
+ * `akpqu` is a string which contains all short options,
1568
+ * except `-m` which is verified separately.
1569
+ */
1570
+ if ((strlen (argv [i ]) == 2 ) && * argv [i ] == '-' &&
1571
+ strchr ("akpqu" , argv [i ][1 ]))
1572
+ continue ;
1573
+
1574
+ if (!strcmp (argv [i ], "--all" ) ||
1575
+ !strcmp (argv [i ], "--keep-index" ) ||
1576
+ !strcmp (argv [i ], "--no-keep-index" ) ||
1577
+ !strcmp (argv [i ], "--patch" ) ||
1578
+ !strcmp (argv [i ], "--quiet" ) ||
1579
+ !strcmp (argv [i ], "--include-untracked" ))
1580
+ continue ;
1581
+
1582
+ /*
1583
+ * `-m` and `--message=` are verified separately because
1584
+ * they need to be immediately followed by a string
1585
+ * (i.e.`-m"foobar"` or `--message="foobar"`).
1586
+ */
1587
+ if (starts_with (argv [i ], "-m" ) ||
1588
+ starts_with (argv [i ], "--message=" ))
1589
+ continue ;
1590
+
1591
+ usage_with_options (git_stash_usage , options );
1592
+ }
1593
+ }
1573
1594
1574
- usage_msg_opt (xstrfmt (_ ("unknown subcommand: %s" ), argv [0 ]),
1575
- git_stash_helper_usage , options );
1595
+ argv_array_push (& args , "push" );
1596
+ argv_array_pushv (& args , argv );
1597
+ return !!push_stash (args .argc , args .argv , prefix );
1576
1598
}
0 commit comments