From 57dac0bfe43a68d55e16def58b8ed305e0676d3f Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Thu, 26 Mar 2009 21:53:24 +0100 Subject: Test for local branches being followed with --track According to the documentation, it is perfectly okay to follow local branches using the --track option. Introduce a test which checks whether they behave the same. Currently one test fails. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh index ba90601..2a2b6b6 100755 --- a/t/t6040-tracking-info.sh +++ b/t/t6040-tracking-info.sh @@ -29,7 +29,9 @@ test_expect_success setup ' git checkout -b b4 origin && advance e && advance f - ) + ) && + git checkout -b follower --track master && + advance g ' script='s/^..\(b.\)[ 0-9a-f]*\[\([^]]*\)\].*/\1 \2/p' @@ -56,6 +58,12 @@ test_expect_success 'checkout' ' grep "have 1 and 1 different" actual ' +test_expect_failure 'checkout with local tracked branch' ' + git checkout master && + git checkout follower >actual + grep "is ahead of" actual +' + test_expect_success 'status' ' ( cd test && -- cgit v0.10.2-6-g49f6 From 5e6e2b487e76066d03b4f5809dc6b44b1234519a Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Wed, 1 Apr 2009 23:42:49 +0200 Subject: 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 Signed-off-by: Junio C Hamano diff --git a/remote.c b/remote.c index e5d6b10..30d7fde 100644 --- a/remote.c +++ b/remote.c @@ -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]); } } } @@ -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' " diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh index 2a2b6b6..3d6db4d 100755 --- a/t/t6040-tracking-info.sh +++ b/t/t6040-tracking-info.sh @@ -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 -- cgit v0.10.2-6-g49f6