Comments (4)
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 CheckoutTree()
and SetHeadDetached()
.
from git2go.
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 Peel
the tag reference ? Every time I call ref.Peel(git.ObjectTag)
I get the following error:
The git_object of id 'abe8b968b0607f92ddeac31b062208b7ee5fd475' can not be successfully peeled into a tag (git_otype=4).
I had the look at the actual tag hash and it's the same as reported by the error above:
$ cat repo/.git/refs/tags/my_tag
abe8b968b0607f92ddeac31b062208b7ee5fd475
So the tag actually exists. Am I missing something important here ?
Thanks!
from git2go.
The tag reference exists, that doesn't mean there's a tag object underneath. If you look at that ref with git show
or git cat-file -t
, it should show that there is no tag object there.
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 Repository.DwimReference()
which will perform this shortname-to-reference conversion that you're doing manually in this code.
from git2go.
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 👍
from git2go.
Related Issues (20)
- Allow libgit2 1.4.0 HOT 9
- Random `invalid pointer handle` using Managed Transport HOT 1
- Clone repo success but has uncorrect status
- Segfault when calling `index.AddAll`
- anyone tried to use bazel to build?
- Can I get the result of git show via git2go? HOT 1
- Push equivalent to clone mirror? HOT 1
- `fatal error: unexpected signal during runtime execution` in `Clone(...)` HOT 1
- build fail undefined: xxxx ... HOT 1
- Files are deleted after cloning HOT 2
- Missing v34 blocks the use of v35 HOT 1
- Is this repository still active? HOT 4
- Mapping examples between libgit2 and git2go in README need to be updated
- Multi architecture support
- How do I checkout a branch in a similar way than the CLI does? HOT 1
- Support for LibGit2 v1.6 HOT 4
- How to pass the equivalent of git push -o <string>?
- TestRemoteSSH fails with libgit2 1.5 with built in SSH support
- libgit.Clone produces empty directory, fails with `failed to stat path/to/repo/.git` HOT 1
- Library constantly increases memory usage in long-running applications HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from git2go.