@matheusbsbs / matheus-bagliano / commits / 7c16ef7577
Fork 0

switch: fix errors and comments related to -c and -C

In d787d311db (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 b7b5fce270 (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 <liu.denton@gmail.com> Reviewed-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Apr 30, 2020 at 07:54 UTC 7c16ef7577c21c043e8f2779e1d9dd657dd2dace
1 file changed +10 -4
builtin/checkout.c
+10 -4
@@ -1487,6 +1487,9 @@ static struct option *add_checkout_path_options(struct checkout_opts *opts,
1487 return newopts;
1488 }
1489
1490 +/* create-branch option (either b or c) */
1491 +static char cb_option = 'b';
1492 +
1493 static int checkout_main(int argc, const char **argv, const char *prefix,
1494 struct checkout_opts *opts, struct option *options,
1495 const char * const usagestr[])
@@ -1530,7 +1533,8 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1533 }
1534
1535 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));
1538
1539 if (opts->overlay_mode == 1 && opts->patch_mode)
1540 die(_("-p and --overlay are mutually exclusive"));
@@ -1558,7 +1562,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1562 /*
1563 * From here on, new_branch will contain the branch to be checked out,
1564 * 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.
1566 */
1567 if (opts->new_branch_force)
1568 opts->new_branch = opts->new_branch_force;
@@ -1566,7 +1570,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1570 if (opts->new_orphan_branch)
1571 opts->new_branch = opts->new_orphan_branch;
1572
1569 - /* --track without -b/-B/--orphan should DWIM */
1573 + /* --track without -c/-C/-b/-B/--orphan should DWIM */
1574 if (opts->track != BRANCH_TRACK_UNSPECIFIED && !opts->new_branch) {
1575 const char *argv0 = argv[0];
1576 if (!argc || !strcmp(argv0, "--"))
@@ -1575,7 +1579,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1579 skip_prefix(argv0, "remotes/", &argv0);
1580 argv0 = strchr(argv0, '/');
1581 if (!argv0 || !argv0[1])
1578 - die(_("missing branch name; try -b"));
1582 + die(_("missing branch name; try -%c"), cb_option);
1583 opts->new_branch = argv0 + 1;
1584 }
1585
@@ -1766,6 +1770,8 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
1770 options = add_common_options(&opts, options);
1771 options = add_common_switch_branch_options(&opts, options);
1772
1773 + cb_option = 'c';
1774 +
1775 ret = checkout_main(argc, argv, prefix, &opts,
1776 options, switch_branch_usage);
1777 FREE_AND_NULL(options);