Skip to content

Instantly share code, notes, and snippets.

@calvn
Created May 25, 2016 20:23
Show Gist options
  • Save calvn/2d483971f64dd0db1e6c6bd314356a19 to your computer and use it in GitHub Desktop.
Save calvn/2d483971f64dd0db1e6c6bd314356a19 to your computer and use it in GitHub Desktop.
git2go BranchIterator ForEach() bug
package main
import (
"fmt"
"os"
"path/filepath"
"gopkg.in/libgit2/git2go.v24"
)
func main() {
p := filepath.Join(os.TempDir(), "sample-data")
err := os.Mkdir(p, 0777)
if err != nil {
panic(err)
}
repo, err := git.Clone("https://github.com/libgit2/TestGitRepository", p, &git.CloneOptions{})
if err != nil {
panic(err)
}
itr, err := repo.NewBranchIterator(git.BranchLocal)
if err != nil {
panic(err)
}
defer itr.Free()
var f = func(_ *git.Branch, _ git.BranchType) error {
return nil
}
err = itr.ForEach(f) // This doesn't return nil, but instead an empty string
if err != nil {
fmt.Printf("Error: %s Length: %d", err.Error(), len(err.Error()))
}
defer func() {
os.RemoveAll(p)
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment