Skip to content

Commit 5e6e2b4

Browse files
Michael J Grubergitster
authored andcommitted
Make local branches behave like remote branches when --tracked
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 57dac0b commit 5e6e2b4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

remote.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,9 @@ struct branch *branch_get(const char *name)
11701170
for (i = 0; i < ret->merge_nr; i++) {
11711171
ret->merge[i] = xcalloc(1, sizeof(**ret->merge));
11721172
ret->merge[i]->src = xstrdup(ret->merge_name[i]);
1173-
remote_find_tracking(ret->remote,
1174-
ret->merge[i]);
1173+
if (remote_find_tracking(ret->remote, ret->merge[i])
1174+
&& !strcmp(ret->remote_name, "."))
1175+
ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
11751176
}
11761177
}
11771178
}
@@ -1450,6 +1451,8 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
14501451
base = branch->merge[0]->dst;
14511452
if (!prefixcmp(base, "refs/remotes/")) {
14521453
base += strlen("refs/remotes/");
1454+
} else if (!prefixcmp(base, "refs/heads/")) {
1455+
base += strlen("refs/heads/");
14531456
}
14541457
if (!num_theirs)
14551458
strbuf_addf(sb, "Your branch is ahead of '%s' "

t/t6040-tracking-info.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ test_expect_success 'checkout' '
5858
grep "have 1 and 1 different" actual
5959
'
6060

61-
test_expect_failure 'checkout with local tracked branch' '
61+
test_expect_success 'checkout with local tracked branch' '
6262
git checkout master &&
6363
git checkout follower >actual
6464
grep "is ahead of" actual

0 commit comments

Comments
 (0)