-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
git clone specific tag #126
Comments
The thing here is that the option is called "--branch" so that's what we implemented, checking out a particular branch. But as it happens, what git means here is more like "meh, I'll take whatever", which is a behaviour which we haven't implemented. Until we do accept any string to DWIM, you'd have to perform the switch to the commit in that tag via |
Thanks for the hints! I've eventually done something like below: ref, err := iter.Next()
for err == nil {
if ref.IsTag() {
tagName := strings.TrimPrefix(ref.Name(), "refs/tags/")
if tagName == "my_tag" {
fmt.Println("Found the tag", "my_tag")
obj, err := ref.Peel(git.ObjectTag)
if err != nil {
return fmt.Errorf("Unable to peel the ref: %s\n", err)
}
if err := repo.SetHeadDetached(obj.Id(), nil, ""); err != nil {
return fmt.Errorf("Checking out tag %s failed: %s", tag, err)
}
return nil
}
}
ref, err = iter.Next()
} However, I don't understand why I can't
I had the look at the actual tag hash and it's the same as reported by the error above:
So the tag actually exists. Am I missing something important here ? Thanks! |
The tag reference exists, that doesn't mean there's a tag object underneath. If you look at that ref with But you're not interested in a tag object being there to perform be branch switch. What you need is a commit, so that's what you should be looking for. You also might be interested in |
Thanks @carlosmn Eventually I went with something like this: ref, err := repo.DwimReference(tag)
if err != nil {
return fmt.Errorf("Could not find the %s ref: %s\n", ref.Name(), err)
}
if err := repo.SetHeadDetached(ref.Target(), nil, ""); err != nil {
return fmt.Errorf("Checking out tag %s failed: %s", tag, err)
} I'm not sure if that's the best way to approach this, but it does seem to do the trick 👍 |
When I try to clone a specific tag, I run something like this:
The above command succeeds without any hiccups.
I figured I could write a go func like below.
However, I'm getting the following error:
I'm guessing this is a lack of knowledge on my side, but I'm wondering whether I can accomplish something like this using the git package ?
The text was updated successfully, but these errors were encountered: