Skip to content

Commit b7b5fce

Browse files
pcloudsgitster
authored andcommitted
switch: better names for -b and -B
The shortcut of these options do not make much sense when used with switch. And their descriptions are also tied to checkout. Move -b/-B to cmd_checkout() and new -c/-C with the same functionality in cmd_switch_branch() Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d787d31 commit b7b5fce

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

builtin/checkout.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,14 +1368,10 @@ static struct option *add_common_options(struct checkout_opts *opts,
13681368
return newopts;
13691369
}
13701370

1371-
static struct option *add_switch_branch_options(struct checkout_opts *opts,
1372-
struct option *prevopts)
1371+
static struct option *add_common_switch_branch_options(
1372+
struct checkout_opts *opts, struct option *prevopts)
13731373
{
13741374
struct option options[] = {
1375-
OPT_STRING('b', NULL, &opts->new_branch, N_("branch"),
1376-
N_("create and checkout a new branch")),
1377-
OPT_STRING('B', NULL, &opts->new_branch_force, N_("branch"),
1378-
N_("create/reset and checkout a branch")),
13791375
OPT_BOOL('l', NULL, &opts->new_branch_log, N_("create reflog for new branch")),
13801376
OPT_BOOL(0, "detach", &opts->force_detach, N_("detach HEAD at named commit")),
13811377
OPT_SET_INT('t', "track", &opts->track, N_("set upstream info for new branch"),
@@ -1571,15 +1567,22 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
15711567
int cmd_checkout(int argc, const char **argv, const char *prefix)
15721568
{
15731569
struct checkout_opts opts;
1574-
struct option *options = NULL;
1570+
struct option *options;
1571+
struct option checkout_options[] = {
1572+
OPT_STRING('b', NULL, &opts.new_branch, N_("branch"),
1573+
N_("create and checkout a new branch")),
1574+
OPT_STRING('B', NULL, &opts.new_branch_force, N_("branch"),
1575+
N_("create/reset and checkout a branch")),
1576+
OPT_END()
1577+
};
15751578
int ret;
15761579

15771580
memset(&opts, 0, sizeof(opts));
15781581
opts.no_dwim_new_local_branch = 0;
15791582

1580-
options = parse_options_dup(options);
1583+
options = parse_options_dup(checkout_options);
15811584
options = add_common_options(&opts, options);
1582-
options = add_switch_branch_options(&opts, options);
1585+
options = add_common_switch_branch_options(&opts, options);
15831586
options = add_checkout_path_options(&opts, options);
15841587

15851588
ret = checkout_main(argc, argv, prefix, &opts,
@@ -1592,14 +1595,21 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
15921595
{
15931596
struct checkout_opts opts;
15941597
struct option *options = NULL;
1598+
struct option switch_options[] = {
1599+
OPT_STRING('c', "create", &opts.new_branch, N_("branch"),
1600+
N_("create and switch to a new branch")),
1601+
OPT_STRING('C', "force-create", &opts.new_branch_force, N_("branch"),
1602+
N_("create/reset and switch to a branch")),
1603+
OPT_END()
1604+
};
15951605
int ret;
15961606

15971607
memset(&opts, 0, sizeof(opts));
15981608
opts.no_dwim_new_local_branch = 0;
15991609

1600-
options = parse_options_dup(options);
1610+
options = parse_options_dup(switch_options);
16011611
options = add_common_options(&opts, options);
1602-
options = add_switch_branch_options(&opts, options);
1612+
options = add_common_switch_branch_options(&opts, options);
16031613

16041614
ret = checkout_main(argc, argv, prefix, &opts,
16051615
options, switch_branch_usage);

0 commit comments

Comments
 (0)