git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Allow tags as upstreams for --track
@ 2009-05-11 14:42 Michael J Gruber
  2009-05-11 14:42 ` [PATCH 1/2] Test tracking of non-commit upstreams Michael J Gruber
  0 siblings, 1 reply; 4+ messages in thread
From: Michael J Gruber @ 2009-05-11 14:42 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

I sent this patch during rc without a test and it received the
appropriate reaction ;)

Now, comes with test and all that...

This is about using tags as the upstream for --track (checkout,
branch). Currently, git allows to do that but all status generating
commands (status, checkout, branch -v) barf when the upstream is not a
commit, such as an annotated tag. So, either we should disallow this or
deal with it. The latter is actually easier, sometimes useful and does
not harm any living creatures.

The first patch exposes the issue by 2 tests: lightweight tags are OK,
annotated tags are not.

The second patch teaches stat_tracking_info() to resolve a reference to
a commit before using it.

Tags as upstreams can be useful because then branch -vv gives you concise
information about how much work you have done say on top of a released
version, in case where the "behind" information with respect to a branch
would be less informative (Where did I fork?) and confusing (Behind?
What do you mean behind for a branch on top of a released version?).

Michael J Gruber (2):
  Test tracking of non-commit upstreams
  Fix behavior with non-committish upstream references

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] Test tracking of non-commit upstreams
  2009-05-11 14:42 [PATCH 0/2] Allow tags as upstreams for --track Michael J Gruber
@ 2009-05-11 14:42 ` Michael J Gruber
  2009-05-11 14:42   ` [PATCH 2/2] Fix behavior with non-committish upstream references Michael J Gruber
  0 siblings, 1 reply; 4+ messages in thread
From: Michael J Gruber @ 2009-05-11 14:42 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

git-checkout and git-branch allow setting up an arbitrary committish as
the upstream reference for --track. In particular, tags are allowed. But
they and git-status barf on non-commit upstreams as soon as they are
asked for trackings stats.

Expose this shortcoming by adding two tests: annotated tags are affected
but lightweight tags are OK.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 t/t6040-tracking-info.sh |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index 3d6db4d..2397774 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -74,5 +74,19 @@ test_expect_success 'status' '
 	grep "have 1 and 1 different" actual
 '
 
+test_expect_success 'status when tracking lightweight tags' '
+	git checkout master &&
+	git tag light && 
+	git branch --track lighttrack light >actual &&
+	grep "set up to track" actual &&
+	git checkout lighttrack
+'
 
+test_expect_failure 'status when tracking annotated tags' '
+	git checkout master &&
+	git tag -m heavy heavy && 
+	git branch --track heavytrack heavy >actual &&
+	grep "set up to track" actual &&
+	git checkout heavytrack
+'
 test_done
-- 
1.6.3.195.gad816

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] Fix behavior with non-committish upstream references
  2009-05-11 14:42 ` [PATCH 1/2] Test tracking of non-commit upstreams Michael J Gruber
@ 2009-05-11 14:42   ` Michael J Gruber
  2009-05-14  7:51     ` Michael J Gruber
  0 siblings, 1 reply; 4+ messages in thread
From: Michael J Gruber @ 2009-05-11 14:42 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

stat_tracking_info() assumes that upstream references (as specified by
--track or set up automatically) are commits. By calling lookup_commit()
on them, create_objects() creates objects for them with type commit no
matter what their real type is; this disturbs lookup_tag() later on in the
call sequence, leading to git status, git branch -v  and git checkout
erroring out.

Fix this by using lookup_commit_reference() instead so that (annotated)
tags can be used as upstream references.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 remote.c                 |    4 ++--
 t/t6040-tracking-info.sh |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/remote.c b/remote.c
index d66e2f3..2c3e905 100644
--- a/remote.c
+++ b/remote.c
@@ -1399,13 +1399,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs)
 	base = branch->merge[0]->dst;
 	if (!resolve_ref(base, sha1, 1, NULL))
 		return 0;
-	theirs = lookup_commit(sha1);
+	theirs = lookup_commit_reference(sha1);
 	if (!theirs)
 		return 0;
 
 	if (!resolve_ref(branch->refname, sha1, 1, NULL))
 		return 0;
-	ours = lookup_commit(sha1);
+	ours = lookup_commit_reference(sha1);
 	if (!ours)
 		return 0;
 
diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh
index 2397774..e38c597 100755
--- a/t/t6040-tracking-info.sh
+++ b/t/t6040-tracking-info.sh
@@ -82,7 +82,7 @@ test_expect_success 'status when tracking lightweight tags' '
 	git checkout lighttrack
 '
 
-test_expect_failure 'status when tracking annotated tags' '
+test_expect_success 'status when tracking annotated tags' '
 	git checkout master &&
 	git tag -m heavy heavy && 
 	git branch --track heavytrack heavy >actual &&
-- 
1.6.3.195.gad816

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] Fix behavior with non-committish upstream references
  2009-05-11 14:42   ` [PATCH 2/2] Fix behavior with non-committish upstream references Michael J Gruber
@ 2009-05-14  7:51     ` Michael J Gruber
  0 siblings, 0 replies; 4+ messages in thread
From: Michael J Gruber @ 2009-05-14  7:51 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

Junio,

I'm sorry: While checking pu I noticed that I failed to rewrite the
subject as intended (I did rewrite the commit message body).
"non-committish" should be "non-commit". Feel free to amend or leave as
is, whatever you prefer.

Michael

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-05-14  7:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-11 14:42 [PATCH 0/2] Allow tags as upstreams for --track Michael J Gruber
2009-05-11 14:42 ` [PATCH 1/2] Test tracking of non-commit upstreams Michael J Gruber
2009-05-11 14:42   ` [PATCH 2/2] Fix behavior with non-committish upstream references Michael J Gruber
2009-05-14  7:51     ` Michael J Gruber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).