git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* missing tags from "git fetch"
@ 2019-10-02 13:10 Martin Nicolay
  2019-10-02 13:55 ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Nicolay @ 2019-10-02 13:10 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 3059 bytes --]

Hi!

I don't know if this is a lack of understanding or a software or 
documentation bug.

man git-fetch says about tags:
        By default, any tag that points into the histories being fetched is
        also fetched; the effect is to fetch tags that point at branches that
        you are interested in.

If I fetch without --tags the tags that point to the commits of the 
fetched branch are not fetched. If I fetch with --tags than all tags are 
fetched but I only wish to fetch tags pointing to something in the 
branch fetched.

Here is a self contained example:
--------------------------
$ cd /tmp
$ git init r1 && cd r1
Initialized empty Git repository in /tmp/r1/.git/
$ date >f1
$ git add f1
$ git commit -minitial f1
[master (root-commit) 61753c60ac] initial
  1 file changed, 1 insertion(+)
  create mode 100644 f1
$ git tag -mt1 t1
$ git tag t2
$ git init ../r2 && cd ../r2
Initialized empty Git repository in /tmp/r2/.git/
$ git remote add origin $(cd ../r1; pwd)
$ git fetch origin master
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /tmp/r1
  * branch                  master     -> FETCH_HEAD
  * [new branch]            master     -> origin/master
$ git tag | wc
       0       0       0
$ git fetch --tags origin master
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 1 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (1/1), done.
From /tmp/r1
  * branch                  master     -> FETCH_HEAD
  * [new tag]               t1         -> t1
  * [new tag]               t2         -> t2
$ git tag | wc
       2       2       6
$ git rev-parse FETCH_HEAD
61753c60ac550a5315b7c930a701b94f36e08e4f
$ git rev-parse t1^{commit}
61753c60ac550a5315b7c930a701b94f36e08e4f
$ git rev-parse t2^{commit}
61753c60ac550a5315b7c930a701b94f36e08e4f
--------------------------

Obviously the two tags point to the fetched commit but without --tags 
they are not fetched. The behavior is identical for lightweight and 
annotated tags.

Best regards
Martin Nicolay

-- 

No MS-Word attachments (http://www.gnu.org/philosophy/no-word-attachments.html)
_______________________________________________________________________________
OSM AG | Ruhrallee 191 | 45136 Essen | Fon: 0201-89 555 | Fax: 0201-89 55 400
web: www.osm-ag.de | e-mail: info@osm-ag.de
IBAN: DE67 4325 0030 0001 0059 82 | BIC: WELADED1HRN
USt-ldNr.: DE163337313 | HRB: 28171 Essen
Aufsichtsratsvorsitzende: Dipl.-Kff. Sabine Elsas
Vorstand: Johannes Kuhn (Vorsitzender), Christian Damsky, Axel Roland

--
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen.
Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten
haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail.
Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht
gestattet.
_______________________________________________________________________________

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

* Re: missing tags from "git fetch"
  2019-10-02 13:10 missing tags from "git fetch" Martin Nicolay
@ 2019-10-02 13:55 ` Jeff King
  2019-10-02 15:24   ` Martin Nicolay
  2019-10-25 10:17   ` Martin Nicolay
  0 siblings, 2 replies; 5+ messages in thread
From: Jeff King @ 2019-10-02 13:55 UTC (permalink / raw)
  To: Martin Nicolay; +Cc: git

On Wed, Oct 02, 2019 at 03:10:12PM +0200, Martin Nicolay wrote:

> I don't know if this is a lack of understanding or a software or
> documentation bug.
> 
> man git-fetch says about tags:
>        By default, any tag that points into the histories being fetched is
>        also fetched; the effect is to fetch tags that point at branches that
>        you are interested in.
> 
> If I fetch without --tags the tags that point to the commits of the fetched
> branch are not fetched. If I fetch with --tags than all tags are fetched but
> I only wish to fetch tags pointing to something in the branch fetched.

It's a documentation bug, I think. We won't auto-follow tags when
fetching into FETCH_HEAD (but this is further confused by the fact that
fetching into FETCH_HEAD will auto-update a tracking ref).

So instead of this:

> $ git fetch origin master

try this:

  $ git fetch origin

or even this:

  $ git fetch origin master:refs/remotes/origin/master

There's more discussion in this thread (but it looks like no patches
ever came out of it):

  https://public-inbox.org/git/20170817092853.hteuzni5lxia4ejf@sigill.intra.peff.net/

-Peff

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

* Re: missing tags from "git fetch"
  2019-10-02 13:55 ` Jeff King
@ 2019-10-02 15:24   ` Martin Nicolay
  2019-10-25 10:17   ` Martin Nicolay
  1 sibling, 0 replies; 5+ messages in thread
From: Martin Nicolay @ 2019-10-02 15:24 UTC (permalink / raw)
  To: Jeff King; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1783 bytes --]

On Wednesday 2019-10-02 15:55, Jeff King wrote:
> So instead of this:
>
>> $ git fetch origin master
>
> try this:
>
>  $ git fetch origin

It creates the master branch. This is what I'm trying to avoid.

> or even this:
>
>  $ git fetch origin master:refs/remotes/origin/master

Bingo. It's ugly but it works. Problem solved :-).

> There's more discussion in this thread (but it looks like no patches
> ever came out of it):
>
>  https://public-inbox.org/git/20170817092853.hteuzni5lxia4ejf@sigill.intra.peff.net/

The explanation makes a kind of sense, but if someone want to avoid 
polluting the tags when fetching into FETCH_HEAD one could get it with 
--no-tags. So this is more of a misguided attempt to get a seemingly 
sensible default while destroying a consistent behaviour.

Sometimes I can see why people say git is confusing ;-).

Thanks
Martin Nicolay

-- 

No MS-Word attachments (http://www.gnu.org/philosophy/no-word-attachments.html)
_______________________________________________________________________________
OSM AG | Ruhrallee 191 | 45136 Essen | Fon: 0201-89 555 | Fax: 0201-89 55 400
web: www.osm-ag.de | e-mail: info@osm-ag.de
IBAN: DE67 4325 0030 0001 0059 82 | BIC: WELADED1HRN
USt-ldNr.: DE163337313 | HRB: 28171 Essen
Aufsichtsratsvorsitzende: Dipl.-Kff. Sabine Elsas
Vorstand: Johannes Kuhn (Vorsitzender), Christian Damsky, Axel Roland

--
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen.
Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten
haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail.
Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht
gestattet.
_______________________________________________________________________________

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

* Re: missing tags from "git fetch"
  2019-10-02 13:55 ` Jeff King
  2019-10-02 15:24   ` Martin Nicolay
@ 2019-10-25 10:17   ` Martin Nicolay
  2019-11-22 13:00     ` Jeff King
  1 sibling, 1 reply; 5+ messages in thread
From: Martin Nicolay @ 2019-10-25 10:17 UTC (permalink / raw)
  To: Jeff King; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 2765 bytes --]

Hi!

On Wednesday 2019-10-02 15:55, Jeff King wrote:
> It's a documentation bug, I think. We won't auto-follow tags when
> fetching into FETCH_HEAD (but this is further confused by the fact that
> fetching into FETCH_HEAD will auto-update a tracking ref).
>
> So instead of this:
>
>> $ git fetch origin master
>
> try this:
>
>  $ git fetch origin
>
> or even this:
>
>  $ git fetch origin master:refs/remotes/origin/master

I thought it would work, but it works only once. On the second time the 
ref for the remote branch is deleted. It seems git is confused by 
specifying a ref it expect to manage itself.

Is there any other way to force auto-follow tags? If there is no sane 
way, I have to create a throwawy branch and delete it immediately.

=====================================================
$ git fetch origin master:refs/remotes/origin/master
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From /tmp/r1
  * [new branch]            master     -> origin/master
  * [new tag]               t1         -> t1
  * [new tag]               t2         -> t2
$ ls .git/refs/remotes/origin
master
$ git fetch origin master:refs/remotes/origin/master
From /tmp/r1
  - [deleted]               (none)     -> origin/master
$ ls .git/refs/remotes/origin
/bin/ls: cannot access .git/refs/remotes/origin: No such file or directory
$ git fetch origin master:refs/remotes/origin/master
From /tmp/r1
  * [new branch]            master     -> origin/master
$ ls .git/refs/remotes/origin
master
$ git --version
git version 2.23.0
=====================================================

Best regards
Martin Nicolay

-- 
_______________________________________________________________________________
No MS-Word attachments (http://www.gnu.org/philosophy/no-word-attachments.html)
_______________________________________________________________________________
OSM AG | Ruhrallee 191 | 45136 Essen | Fon: 0201-89 555 | Fax: 0201-89 55 400
web: www.osm-ag.de | e-mail: info@osm-ag.de
IBAN: DE67 4325 0030 0001 0059 82 | BIC: WELADED1HRN
USt-ldNr.: DE163337313 | HRB: 28171 Essen
Aufsichtsratsvorsitzende: Dipl.-Kff. Sabine Elsas
Vorstand: Johannes Kuhn (Vorsitzender), Christian Damsky, Axel Roland

--
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen.
Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten
haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail.
Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht
gestattet.
_______________________________________________________________________________

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

* Re: missing tags from "git fetch"
  2019-10-25 10:17   ` Martin Nicolay
@ 2019-11-22 13:00     ` Jeff King
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff King @ 2019-11-22 13:00 UTC (permalink / raw)
  To: Martin Nicolay; +Cc: git

On Fri, Oct 25, 2019 at 12:17:26PM +0200, Martin Nicolay wrote:

> >  $ git fetch origin master:refs/remotes/origin/master
> 
> I thought it would work, but it works only once. On the second time the ref
> for the remote branch is deleted. It seems git is confused by specifying a
> ref it expect to manage itself.

It seems like a bad interaction with `fetch.prune` (I don't have it set,
and the problem doesn't appear, but if I set it, I can reproduce your
issue).

I'm not sure why, though. It's true that the ref _is_ mentioned in the
configured refspec for origin, but we shouldn't be looking at that
refspec at all (since we have a refspec on the command line).

-Peff

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

end of thread, other threads:[~2019-11-22 13:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-02 13:10 missing tags from "git fetch" Martin Nicolay
2019-10-02 13:55 ` Jeff King
2019-10-02 15:24   ` Martin Nicolay
2019-10-25 10:17   ` Martin Nicolay
2019-11-22 13:00     ` Jeff King

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).