Skip to content

Commit

Permalink
Make local branches behave like remote branches when --tracked
Browse files Browse the repository at this point in the history
This makes sure that local branches, when followed using --track, behave
the same as remote ones (e.g. differences being reported by git status
and git checkout). This fixes 1 known failure.

The fix is done within branch_get(): The first natural candidate,
namely remote_find_tracking(), does not have all the necessary info
because in general there is no remote struct for '.', and we don't want
one because it would show up in other places as well.

branch_get(), on the other hand, has access to merge_names[] (in
addition to merge[]) and therefore can set up the followed branch
easily.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael J Gruber authored and Junio C Hamano committed Apr 1, 2009
1 parent 57dac0b commit 5e6e2b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,8 +1170,9 @@ struct branch *branch_get(const char *name)
for (i = 0; i < ret->merge_nr; i++) {
ret->merge[i] = xcalloc(1, sizeof(**ret->merge));
ret->merge[i]->src = xstrdup(ret->merge_name[i]);
remote_find_tracking(ret->remote,
ret->merge[i]);
if (remote_find_tracking(ret->remote, ret->merge[i])
&& !strcmp(ret->remote_name, "."))
ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
}
}
}
Expand Down Expand Up @@ -1450,6 +1451,8 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
base = branch->merge[0]->dst;
if (!prefixcmp(base, "refs/remotes/")) {
base += strlen("refs/remotes/");
} else if (!prefixcmp(base, "refs/heads/")) {
base += strlen("refs/heads/");
}
if (!num_theirs)
strbuf_addf(sb, "Your branch is ahead of '%s' "
Expand Down
2 changes: 1 addition & 1 deletion t/t6040-tracking-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test_expect_success 'checkout' '
grep "have 1 and 1 different" actual
'

test_expect_failure 'checkout with local tracked branch' '
test_expect_success 'checkout with local tracked branch' '
git checkout master &&
git checkout follower >actual
grep "is ahead of" actual
Expand Down

0 comments on commit 5e6e2b4

Please sign in to comment.