Re: [PATCH] git fetch one tag only

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

Re: [PATCH] git fetch one tag only

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:54:00

Junio C Hamano [off-list ref] writes:
It is a separate matter if we should add some special case to further
reduce the cases where auto-following happens. I personally do not
think any change is needed.
I do not care too deeply either way, but after doing

	$ git init blank && cd blank

and in an empty repository:

        $ git fetch $over_there v1.0.0

will grab the named tag and drop it in FETCH_HEAD, without adding
anything to your local refs, while

	$ git fetch $over_there tag v1.0.0

will grab the named tag and copy it to your refs/tags/v1.0.0, and
auto-follow all the tags that point at commits that are reachable.

To grab and store _only_ v1.0.0 in the local refs, you need to say
"do not auto-follow" with

	$ git fetch $over_there --no-tags tag v1.0.0

While it may be workable, the user experience could be better in a
couple of different ways.

 * It is not fair to expect anybody to guess that "--no-tags" means
   "--no-auto-follow-tags" without reading documentation.

	$ git fetch $over_there --no-auto-follow-tags tag v1.0.0

   might be an improvement, but of course, it is a bit longer to
   spell ;-).

 * The auto-follow kicks in whenever you tell "fetch" to update some
   refs locally.  Maybe if we tweak the rule and auto-follow kick in
   only when you tell "fetch" to update some refs outside refs/tags
   locally,

	$ git fetch $over_there tag v1.0.0

   will fetch and store _only_ the v1.0.0 tag.

   Of course, any behaviour change is a regression, and if done
   without an escape hatch, such a change robs people one useful
   feature: grab tag v1.0.0 and others older than that tag in one
   go.

I won't be coding any of the above; just thinking aloud. 

Re: [PATCH] git fetch one tag only

From: cheng renquan <hidden>
Date: 2016-06-15 22:54:01

On Thu, Jun 7, 2012 at 10:08 AM, Junio C Hamano [off-list ref] wrote:
 * The auto-follow kicks in whenever you tell "fetch" to update some
  refs locally.  Maybe if we tweak the rule and auto-follow kick in
  only when you tell "fetch" to update some refs outside refs/tags
  locally,

       $ git fetch $over_there tag v1.0.0

  will fetch and store _only_ the v1.0.0 tag.

  Of course, any behaviour change is a regression, and if done
  without an escape hatch, such a change robs people one useful
  feature: grab tag v1.0.0 and others older than that tag in one
  go.

I won't be coding any of the above; just thinking aloud.
Here is the code to implement your 2nd approach,
and I don't think this behaviour change is a regression,
because if someone is really relying this fetch one tag actually fetch
all tags feature
he is relying on a broken feature, and should be corrected:
if one really need to fetch all tags, that's what explicit "--tags"
designed and documented for

diff --git a/builtin/fetch.c b/builtin/fetch.c
index bb9a074..b6d7ef3 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -158,7 +158,8 @@ static struct ref *get_ref_map(struct transport *transport,
 	if (ref_count || tags == TAGS_SET) {
 		for (i = 0; i < ref_count; i++) {
 			get_fetch_map(remote_refs, &refs[i], &tail, 0);
-			if (refs[i].dst && refs[i].dst[0])
+			if (refs[i].dst && refs[i].dst[0]
+			    && prefixcmp(refs[i].dst, "refs/tags/"))
 				*autotags = 1;
 		}
 		/* Merge everything on the command line, but not --tags */
-- 
cheng renquan (程任全)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help