1286
1287
static char *parse_remote_branch(const char *arg,
1288
struct object_id *rev,
1289
- int could_be_checkout_paths)
1289
+ int could_be_checkout_paths,
1290
+ enum checkout_command which_command)
1291
{
1292
int num_matches = 0;
1293
char *remote = unique_tracking_name(arg, rev, &num_matches);
1300
1301
if (!remote && num_matches > 1) {
1302
if (advice_enabled(ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME)) {
1303
+ const char *cmdname;
1304
+
1305
+ switch (which_command) {
1306
+ case CHECKOUT_CHECKOUT:
1307
+ cmdname = "checkout";
1308
+ break;
1309
+ case CHECKOUT_SWITCH:
1310
+ cmdname = "switch";
1311
+ break;
1312
+ default:
1313
+ BUG("command <%d> should not reach parse_remote_branch",
1314
+ which_command);
1315
+ break;
1316
+ }
1317
+
1318
advise(_("If you meant to check out a remote tracking branch on, e.g. 'origin',\n"
1319
"you can do so by fully qualifying the name with the --track option:\n"
1320
"\n"
1305
- " git checkout --track origin/<name>\n"
1321
+ " git %s --track origin/<name>\n"
1322
"\n"
1323
"If you'd like to always have checkouts of an ambiguous <name> prefer\n"
1324
"one remote, e.g. the 'origin' remote, consider setting\n"
1309
- "checkout.defaultRemote=origin in your config."));
1325
+ "checkout.defaultRemote=origin in your config."),
1326
+ cmdname);
1327
}
1328
1329
die(_("'%s' matched multiple (%d) remote tracking branches"),
1335
1336
static int parse_branchname_arg(int argc, const char **argv,
1337
int dwim_new_local_branch_ok,
1338
+ enum checkout_command which_command,
1339
struct branch_info *new_branch_info,
1340
struct checkout_opts *opts,
1341
struct object_id *rev)
1445
1446
if (recover_with_dwim) {
1447
remote = parse_remote_branch(arg, rev,
1430
- could_be_checkout_paths);
1448
+ could_be_checkout_paths,
1449
+ which_command);
1450
if (remote) {
1451
*new_branch = arg;
1452
arg = remote;
1935
opts->dwim_new_local_branch &&
1936
opts->track == BRANCH_TRACK_UNSPECIFIED &&
1937
!opts->new_branch;
1919
- int n = parse_branchname_arg(argc, argv, dwim_ok,
1938
+ int n = parse_branchname_arg(argc, argv, dwim_ok, which_command,
1939
&new_branch_info, opts, &rev);
1940
argv += n;
1941
argc -= n;