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