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
};
@@ -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 )
@@ -522,7 +517,7 @@ static int apply_stash(int argc, const char **argv, const char *prefix)
522
517
};
523
518
524
519
argc = parse_options (argc , argv , prefix , options ,
525
- git_stash_helper_apply_usage , 0 );
520
+ git_stash_apply_usage , 0 );
526
521
527
522
if (get_stash_info (& info , argc , argv ))
528
523
return -1 ;
@@ -595,7 +590,7 @@ static int drop_stash(int argc, const char **argv, const char *prefix)
595
590
};
596
591
597
592
argc = parse_options (argc , argv , prefix , options ,
598
- git_stash_helper_drop_usage , 0 );
593
+ git_stash_drop_usage , 0 );
599
594
600
595
if (get_stash_info (& info , argc , argv ))
601
596
return -1 ;
@@ -621,7 +616,7 @@ static int pop_stash(int argc, const char **argv, const char *prefix)
621
616
};
622
617
623
618
argc = parse_options (argc , argv , prefix , options ,
624
- git_stash_helper_pop_usage , 0 );
619
+ git_stash_pop_usage , 0 );
625
620
626
621
if (get_stash_info (& info , argc , argv ))
627
622
return -1 ;
@@ -648,7 +643,7 @@ static int branch_stash(int argc, const char **argv, const char *prefix)
648
643
};
649
644
650
645
argc = parse_options (argc , argv , prefix , options ,
651
- git_stash_helper_branch_usage , 0 );
646
+ git_stash_branch_usage , 0 );
652
647
653
648
if (!argc ) {
654
649
fprintf_ln (stderr , _ ("No branch name specified" ));
@@ -683,7 +678,7 @@ static int list_stash(int argc, const char **argv, const char *prefix)
683
678
};
684
679
685
680
argc = parse_options (argc , argv , prefix , options ,
686
- git_stash_helper_list_usage ,
681
+ git_stash_list_usage ,
687
682
PARSE_OPT_KEEP_UNKNOWN );
688
683
689
684
if (!ref_exists (ref_stash ))
@@ -763,7 +758,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
763
758
argc = setup_revisions (argc , argv , & rev , NULL );
764
759
if (argc > 1 ) {
765
760
free_stash_info (& info );
766
- usage_with_options (git_stash_helper_show_usage , options );
761
+ usage_with_options (git_stash_show_usage , options );
767
762
}
768
763
769
764
rev .diffopt .flags .recursive = 1 ;
@@ -809,7 +804,7 @@ static int store_stash(int argc, const char **argv, const char *prefix)
809
804
};
810
805
811
806
argc = parse_options (argc , argv , prefix , options ,
812
- git_stash_helper_store_usage ,
807
+ git_stash_store_usage ,
813
808
PARSE_OPT_KEEP_UNKNOWN );
814
809
815
810
if (argc != 1 ) {
@@ -1223,30 +1218,19 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
1223
1218
1224
1219
static int create_stash (int argc , const char * * argv , const char * prefix )
1225
1220
{
1226
- int include_untracked = 0 ;
1227
1221
int ret = 0 ;
1228
- const char * stash_msg = NULL ;
1229
1222
struct strbuf stash_msg_buf = STRBUF_INIT ;
1230
1223
struct stash_info info ;
1231
1224
struct pathspec ps ;
1232
- struct option options [] = {
1233
- OPT_BOOL ('u' , "include-untracked" , & include_untracked ,
1234
- N_ ("include untracked files in stash" )),
1235
- OPT_STRING ('m' , "message" , & stash_msg , N_ ("message" ),
1236
- N_ ("stash message" )),
1237
- OPT_END ()
1238
- };
1239
1225
1240
- argc = parse_options (argc , argv , prefix , options ,
1241
- git_stash_helper_create_usage ,
1242
- 0 );
1226
+ /* Starting with argv[1], since argv[0] is "create" */
1227
+ strbuf_join_argv (& stash_msg_buf , argc - 1 , ++ argv , ' ' );
1243
1228
1244
1229
memset (& ps , 0 , sizeof (ps ));
1245
1230
if (!check_changes_tracked_files (ps ))
1246
1231
return 0 ;
1247
1232
1248
- strbuf_addstr (& stash_msg_buf , stash_msg );
1249
- ret = do_create_stash (ps , & stash_msg_buf , include_untracked , 0 , & info ,
1233
+ ret = do_create_stash (ps , & stash_msg_buf , 0 , 0 , & info ,
1250
1234
NULL , 0 );
1251
1235
if (!ret )
1252
1236
printf_ln ("%s" , oid_to_hex (& info .w_commit ));
@@ -1478,9 +1462,10 @@ static int push_stash(int argc, const char **argv, const char *prefix)
1478
1462
OPT_END ()
1479
1463
};
1480
1464
1481
- argc = parse_options (argc , argv , prefix , options ,
1482
- git_stash_helper_push_usage ,
1483
- 0 );
1465
+ if (argc )
1466
+ argc = parse_options (argc , argv , prefix , options ,
1467
+ git_stash_push_usage ,
1468
+ 0 );
1484
1469
1485
1470
parse_pathspec (& ps , 0 , PATHSPEC_PREFER_FULL , prefix , argv );
1486
1471
return do_push_stash (ps , stash_msg , quiet , keep_index , patch_mode ,
@@ -1513,7 +1498,7 @@ static int save_stash(int argc, const char **argv, const char *prefix)
1513
1498
};
1514
1499
1515
1500
argc = parse_options (argc , argv , prefix , options ,
1516
- git_stash_helper_save_usage ,
1501
+ git_stash_save_usage ,
1517
1502
PARSE_OPT_KEEP_DASHDASH );
1518
1503
1519
1504
if (argc )
@@ -1527,27 +1512,29 @@ static int save_stash(int argc, const char **argv, const char *prefix)
1527
1512
return ret ;
1528
1513
}
1529
1514
1530
- int cmd_stash__helper (int argc , const char * * argv , const char * prefix )
1515
+ int cmd_stash (int argc , const char * * argv , const char * prefix )
1531
1516
{
1517
+ int i = -1 ;
1532
1518
pid_t pid = getpid ();
1533
1519
const char * index_file ;
1520
+ struct argv_array args = ARGV_ARRAY_INIT ;
1534
1521
1535
1522
struct option options [] = {
1536
1523
OPT_END ()
1537
1524
};
1538
1525
1539
1526
git_config (git_diff_basic_config , NULL );
1540
1527
1541
- argc = parse_options (argc , argv , prefix , options , git_stash_helper_usage ,
1528
+ argc = parse_options (argc , argv , prefix , options , git_stash_usage ,
1542
1529
PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH );
1543
1530
1544
1531
index_file = get_index_file ();
1545
1532
strbuf_addf (& stash_index_path , "%s.stash.%" PRIuMAX , index_file ,
1546
1533
(uintmax_t )pid );
1547
1534
1548
- if (argc < 1 )
1549
- usage_with_options ( git_stash_helper_usage , options );
1550
- if (!strcmp (argv [0 ], "apply" ))
1535
+ if (! argc )
1536
+ return !! push_stash ( 0 , NULL , prefix );
1537
+ else if (!strcmp (argv [0 ], "apply" ))
1551
1538
return !!apply_stash (argc , argv , prefix );
1552
1539
else if (!strcmp (argv [0 ], "clear" ))
1553
1540
return !!clear_stash (argc , argv , prefix );
@@ -1569,7 +1556,42 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
1569
1556
return !!push_stash (argc , argv , prefix );
1570
1557
else if (!strcmp (argv [0 ], "save" ))
1571
1558
return !!save_stash (argc , argv , prefix );
1559
+ else if (* argv [0 ] != '-' )
1560
+ usage_msg_opt (xstrfmt (_ ("unknown subcommand: %s" ), argv [0 ]),
1561
+ git_stash_usage , options );
1562
+
1563
+ if (strcmp (argv [0 ], "-p" )) {
1564
+ while (++ i < argc && strcmp (argv [i ], "--" )) {
1565
+ /*
1566
+ * `akpqu` is a string which contains all short options,
1567
+ * except `-m` which is verified separately.
1568
+ */
1569
+ if ((strlen (argv [i ]) == 2 ) && * argv [i ] == '-' &&
1570
+ strchr ("akpqu" , argv [i ][1 ]))
1571
+ continue ;
1572
+
1573
+ if (!strcmp (argv [i ], "--all" ) ||
1574
+ !strcmp (argv [i ], "--keep-index" ) ||
1575
+ !strcmp (argv [i ], "--no-keep-index" ) ||
1576
+ !strcmp (argv [i ], "--patch" ) ||
1577
+ !strcmp (argv [i ], "--quiet" ) ||
1578
+ !strcmp (argv [i ], "--include-untracked" ))
1579
+ continue ;
1580
+
1581
+ /*
1582
+ * `-m` and `--message=` are verified separately because
1583
+ * they need to be immediately followed by a string
1584
+ * (i.e.`-m"foobar"` or `--message="foobar"`).
1585
+ */
1586
+ if (starts_with (argv [i ], "-m" ) ||
1587
+ starts_with (argv [i ], "--message=" ))
1588
+ continue ;
1589
+
1590
+ usage_with_options (git_stash_usage , options );
1591
+ }
1592
+ }
1572
1593
1573
- usage_msg_opt (xstrfmt (_ ("unknown subcommand: %s" ), argv [0 ]),
1574
- git_stash_helper_usage , options );
1594
+ argv_array_push (& args , "push" );
1595
+ argv_array_pushv (& args , argv );
1596
+ return !!push_stash (args .argc , args .argv , prefix );
1575
1597
}
0 commit comments