简体   繁体   中英

git2go fetch remote tags

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

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:


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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM