Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git2go fetch remote tags

Tags:

git

go

libgit2

Im trying to fetch the tags from a remote with git2go(https://github.com/libgit2/git2go). When i'm cloning the repository I can list all the tags with the following code:

iter, err := repository.NewReferenceIterator()

ref, err := iter.Next()
for err == nil {
    if ref.IsTag() {
        fmt.Println(ref.Name())
    }

    ref, err = iter.Next()
}

But when I fetch the code from the remote it does not update the tags. Im fetching new code from the repository with:

remote, err := p.repository.LoadRemote("origin")
remote.Fetch([]string{}, nil, "")

This is my config:

[core]
    bare = false
    repositoryformatversion = 0
    filemode = true
    logallrefupdates = true
[remote "origin"]
    url = file:///home/testrepo

    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

I've added(Can I specify in .git/config to fetch multiple refspecs?):

fetch = refs/tags/*:refs/tags/*

But that does not do anything.

I also added the tags in the refspec but that gave the error: ref 'refs/remotes/origin/master' doesn't match the destination

like image 619
user1979738 Avatar asked Aug 16 '26 18:08

user1979738


1 Answers

The doc of the Remote.Fetch() method mentions:

use an empty list to use the refspecs from the configuration.

The default refspec does not import tags.
(Even with regular git, you would need a git fetch --tags).
By default:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*

You can either:

  • use a non-empty list of refspecs in the Fetch() method,

    []string{"+refs/heads/*:refs/remotes/origin/*", "refs/tags/*:refs/tags/*"}
    
  • or it is possible to add multiple refspec to a fetch config though, using (with git2go) the (o *Remote) FetchRefspecs() ([]string, error) method.


gyre reports in the comments having this code working up to a point:

up to the point where I need to PEEL the tag: Peel is where git2go somehow returns errors that it can't peel the reference into tag.

like image 90
VonC Avatar answered Aug 18 '26 07:08

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!