Skip to content

Commit b56fca0

Browse files
committed
checkout: updates to tracking report
Ask branch_get() for the new branch explicitly instead of letting it return a potentially stale information. Tighten the logic to find the tracking branch to deal better with misconfigured repositories (i.e. branch.*.merge can exist but it may not have a refspec that fetches to .it) Also fixes grammar in a message, as pointed out by Jeff King. The function is about reporting and not automatically fast-forwarding to the upstream, so stop calling it "adjust-to". Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Daniel Barkalow <barkalow@iabervon.org>
1 parent 75ea38d commit b56fca0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

builtin-checkout.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static int merge_working_tree(struct checkout_opts *opts,
289289
return 0;
290290
}
291291

292-
static void adjust_to_tracking(struct branch_info *new, struct checkout_opts *opts)
292+
static void report_tracking(struct branch_info *new, struct checkout_opts *opts)
293293
{
294294
/*
295295
* We have switched to a new branch; is it building on
@@ -305,13 +305,13 @@ static void adjust_to_tracking(struct branch_info *new, struct checkout_opts *op
305305
int rev_argc;
306306
int num_ours, num_theirs;
307307
const char *remote_msg;
308-
struct branch *branch = branch_get(NULL);
308+
struct branch *branch = branch_get(new->name);
309309

310310
/*
311311
* Nothing to report unless we are marked to build on top of
312312
* somebody else.
313313
*/
314-
if (!branch || !branch->merge)
314+
if (!branch || !branch->merge || !branch->merge[0] || !branch->merge[0]->dst)
315315
return;
316316

317317
/*
@@ -369,7 +369,7 @@ static void adjust_to_tracking(struct branch_info *new, struct checkout_opts *op
369369
remote_msg, base,
370370
num_ours, (num_ours == 1) ? "" : "s");
371371
else if (!num_ours)
372-
printf("Your branch is behind of the tracked%s branch '%s' "
372+
printf("Your branch is behind the tracked%s branch '%s' "
373373
"by %d commit%s,\n"
374374
"and can be fast-forwarded.\n",
375375
remote_msg, base,
@@ -425,7 +425,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
425425
remove_branch_state();
426426
strbuf_release(&msg);
427427
if (!opts->quiet && (new->path || !strcmp(new->name, "HEAD")))
428-
adjust_to_tracking(new, opts);
428+
report_tracking(new, opts);
429429
}
430430

431431
static int switch_branches(struct checkout_opts *opts, struct branch_info *new)

0 commit comments

Comments
 (0)