Re: Tracking of local branches

6 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: Tracking of local branches

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:46:26

Michael J Gruber [off-list ref] writes:
I semi-successfully messed around in remote.c (format_tracking_info(),
stat_tracking_info()) to make it use branch->merge_name rather than
branch->merge. This makes "git status" work as expected ("Your branch
is... severely screwed.") for tracked local branches. (It's messed up
for remote ones but hey it was a first shot; merge[0]->dst is really
needed here I guess.)

Now I could go after sha1_name.c and do the same,

OR

make it so that all branches have their merge member set up, uhm. Any
possible side effects?
My gut feeling is that the latter if works should be preferable for
consistency if nothing else.

The "struct branch" hasn't changed ever since it was introduced by cf81834
(Report information on branches from remote.h, 2007-09-10) and Daniel
might know about some corner cases that rely on branch.merge not being set
up for local ones, but honestly, I would think it would be a bug in the
existing code if there were such cases.

Re: Tracking of local branches

From: Daniel Barkalow <hidden>
Date: 2016-06-15 22:46:26

On Fri, 20 Mar 2009, Junio C Hamano wrote:
Michael J Gruber [off-list ref] writes:
quoted
I semi-successfully messed around in remote.c (format_tracking_info(),
stat_tracking_info()) to make it use branch->merge_name rather than
branch->merge. This makes "git status" work as expected ("Your branch
is... severely screwed.") for tracked local branches. (It's messed up
for remote ones but hey it was a first shot; merge[0]->dst is really
needed here I guess.)

Now I could go after sha1_name.c and do the same,

OR

make it so that all branches have their merge member set up, uhm. Any
possible side effects?
My gut feeling is that the latter if works should be preferable for
consistency if nothing else.

The "struct branch" hasn't changed ever since it was introduced by cf81834
(Report information on branches from remote.h, 2007-09-10) and Daniel
might know about some corner cases that rely on branch.merge not being set
up for local ones, but honestly, I would think it would be a bug in the
existing code if there were such cases.
As long as the semantics for tracking local branches are the same as for 
tracking remote ones, I'm pretty sure there's nothing that relies on 
branch.merge not being something local.

	-Daniel
*This .sig left intentionally blank*

[PATCH 0/2] Make local branches behave like remote branches when --tracked

From: Michael J Gruber <hidden>
Date: 2016-06-15 22:46:29

[Sorry it took so long to finish... This is from my "sick bed", I hope
it doesn't show ;)]

This mini series makes local branches behave the same as remote ones
when they are used as --tracked branches. This means differences are
reported by git status and git checkout, and also that the soon to be
released tracking branch short cut (aka BEL) will work.

Michael J Gruber (2):
  Test for local branches being followed with --track
  Make local branches behave like remote branches when --tracked

 remote.c                 |    9 +++++----
 t/t6040-tracking-info.sh |   10 +++++++++-
 2 files changed, 14 insertions(+), 5 deletions(-)

[PATCH 1/2] Test for local branches being followed with --track

From: Michael J Gruber <hidden>
Date: 2016-06-15 22:46:29

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 1 test fails.

Signed-off-by: Michael J Gruber <redacted>
---
 t/t6040-tracking-info.sh |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
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 &&
-- 
1.6.2.1.507.g0e68d

[PATCH 2/2] Make local branches behave like remote branches when --tracked

From: Michael J Gruber <hidden>
Date: 2016-06-15 22:46:29

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.

Signed-off-by: Michael J Gruber <redacted>
---
 remote.c                 |    9 +++++----
 t/t6040-tracking-info.sh |    2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/remote.c b/remote.c
index 2b037f1..5d2d7a1 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]);
 			}
 		}
 	}
@@ -1449,8 +1450,8 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
 		return 0;
 
 	base = branch->merge[0]->dst;
-	if (!prefixcmp(base, "refs/remotes/")) {
-		base += strlen("refs/remotes/");
+	if (!prefixcmp(base, "refs/")) {
+		base += strlen("refs/");
 	}
 	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
-- 
1.6.2.1.507.g0e68d

Re: [PATCH 0/2] Make local branches behave like remote branches when --tracked

From: Michael J Gruber <hidden>
Date: 2016-06-15 22:46:29

Michael J Gruber venit, vidit, dixit 26.03.2009 21:53:
[Sorry it took so long to finish... This is from my "sick bed", I hope
it doesn't show ;)]

This mini series makes local branches behave the same as remote ones
when they are used as --tracked branches. This means differences are
reported by git status and git checkout, and also that the soon to be
released tracking branch short cut (aka BEL) will work.

Michael J Gruber (2):
  Test for local branches being followed with --track
  Make local branches behave like remote branches when --tracked

 remote.c                 |    9 +++++----
 t/t6040-tracking-info.sh |   10 +++++++++-
 2 files changed, 14 insertions(+), 5 deletions(-)
Sorry, I meant to point out also that 2/2 changes the display format of
the branch: refs/ is removed rather than refs/remotes/, if present. This
makes for unique branch names ready to copy&paste (they were not
necessarily unique before).

Michael
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help