From: Michael J Gruber <hidden> Date: 2016-06-15 22:46:44
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(-)
From: Michael J Gruber <hidden> Date: 2016-06-15 22:46:44
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 <redacted>
---
t/t6040-tracking-info.sh | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
@@ -74,5 +74,19 @@ test_expect_success 'status' 'grep"have 1 and 1 different"actual'+test_expect_success'status when tracking lightweight tags''+gitcheckoutmaster&&+gittaglight&&+gitbranch--tracklighttracklight>actual&&+grep"set up to track"actual&&+gitcheckoutlighttrack+'+test_expect_failure'status when tracking annotated tags''+gitcheckoutmaster&&+gittag-mheavyheavy&&+gitbranch--trackheavytrackheavy>actual&&+grep"set up to track"actual&&+gitcheckoutheavytrack+' test_done
From: Michael J Gruber <hidden> Date: 2016-06-15 22:46:44
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 <redacted>
---
remote.c | 4 ++--
t/t6040-tracking-info.sh | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
@@ -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))return0;-theirs=lookup_commit(sha1);+theirs=lookup_commit_reference(sha1);if(!theirs)return0;if(!resolve_ref(branch->refname,sha1,1,NULL))return0;-ours=lookup_commit(sha1);+ours=lookup_commit_reference(sha1);if(!ours)return0;
From: Michael J Gruber <hidden> Date: 2016-06-15 22:46:46
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