3

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

9 Comments

thanks for your help so far. I Read the links you passed but can't seem to set the right refspec: And what should i put in here? I use remote.Fetch([]string{"refs/tags/*:refs/tags/*"}, nil, "") but this gives me an error: 'refs/remotes/origin/master' doesn't match the destination.
@user1979738 "+refs/heads/*:refs/remotes/origin/*", "refs/tags/*:refs/tags/*". I have edited the answer.
Still getting the error: ref 'refs/remotes/origin/master' doesn't match the destination. I've added my cloned repo config, but it does look the same as these refspecs..
@user1979738 could you try, just to check, "+refs/heads/*:refs/heads/*", "refs/tags/*:refs/tags/*"? Also that might mean the remote 'origin' isn't properly defined.
It still gives me the same: 'refs/remotes/origin/master' doesn't match the destination.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.