Skip to content

Commit 7c16ef7

Browse files
Denton-Lgitster
authored andcommitted
switch: fix errors and comments related to -c and -C
In d787d31 (checkout: split part of it to new command 'switch', 2019-03-29), the `git switch` command was created by extracting the common functionality of cmd_checkout() in checkout_main(). However, in b7b5fce (switch: better names for -b and -B, 2019-03-29), the branch creation and force creation options for 'switch' were changed to -c and -C, respectively. As a result of this, error messages and comments that previously referred to `-b` and `-B` became invalid for `git switch`. For error messages that refer to `-b` and `-B`, use a format string instead so that `-c` and `-C` can be printed when `git switch` is invoked. Reported-by: Robert Simpson Signed-off-by: Denton Liu <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b86a4be commit 7c16ef7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

builtin/checkout.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,9 @@ static struct option *add_checkout_path_options(struct checkout_opts *opts,
14871487
return newopts;
14881488
}
14891489

1490+
/* create-branch option (either b or c) */
1491+
static char cb_option = 'b';
1492+
14901493
static int checkout_main(int argc, const char **argv, const char *prefix,
14911494
struct checkout_opts *opts, struct option *options,
14921495
const char * const usagestr[])
@@ -1530,7 +1533,8 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
15301533
}
15311534

15321535
if ((!!opts->new_branch + !!opts->new_branch_force + !!opts->new_orphan_branch) > 1)
1533-
die(_("-b, -B and --orphan are mutually exclusive"));
1536+
die(_("-%c, -%c and --orphan are mutually exclusive"),
1537+
cb_option, toupper(cb_option));
15341538

15351539
if (opts->overlay_mode == 1 && opts->patch_mode)
15361540
die(_("-p and --overlay are mutually exclusive"));
@@ -1558,15 +1562,15 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
15581562
/*
15591563
* From here on, new_branch will contain the branch to be checked out,
15601564
* and new_branch_force and new_orphan_branch will tell us which one of
1561-
* -b/-B/--orphan is being used.
1565+
* -b/-B/-c/-C/--orphan is being used.
15621566
*/
15631567
if (opts->new_branch_force)
15641568
opts->new_branch = opts->new_branch_force;
15651569

15661570
if (opts->new_orphan_branch)
15671571
opts->new_branch = opts->new_orphan_branch;
15681572

1569-
/* --track without -b/-B/--orphan should DWIM */
1573+
/* --track without -c/-C/-b/-B/--orphan should DWIM */
15701574
if (opts->track != BRANCH_TRACK_UNSPECIFIED && !opts->new_branch) {
15711575
const char *argv0 = argv[0];
15721576
if (!argc || !strcmp(argv0, "--"))
@@ -1575,7 +1579,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
15751579
skip_prefix(argv0, "remotes/", &argv0);
15761580
argv0 = strchr(argv0, '/');
15771581
if (!argv0 || !argv0[1])
1578-
die(_("missing branch name; try -b"));
1582+
die(_("missing branch name; try -%c"), cb_option);
15791583
opts->new_branch = argv0 + 1;
15801584
}
15811585

@@ -1766,6 +1770,8 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
17661770
options = add_common_options(&opts, options);
17671771
options = add_common_switch_branch_options(&opts, options);
17681772

1773+
cb_option = 'c';
1774+
17691775
ret = checkout_main(argc, argv, prefix, &opts,
17701776
options, switch_branch_usage);
17711777
FREE_AND_NULL(options);

0 commit comments

Comments
 (0)