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