Skip to content

Instantly share code, notes, and snippets.

@tiborvass
Last active November 16, 2018 00:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tiborvass/bf14c3fcf090e9d2e9a7ff5d3330021a to your computer and use it in GitHub Desktop.
Save tiborvass/bf14c3fcf090e9d2e9a7ff5d3330021a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
git "gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/utils/ioutil"
)
func main() {
r, err := git.PlainOpen(".")
if err != nil {
panic(err)
}
cfg, err := r.Config()
if err != nil {
panic(err)
}
remote := cfg.Remotes["tibor"]
s, err := git.NewSendPackSession(remote.URL, nil)
if err != nil {
panic(err)
}
defer ioutil.CheckClose(s, &err)
ar, err := s.AdvertisedReferences()
if err != nil {
panic(err)
}
for name, hash := range ar.References {
if name == "refs/heads/master" {
fmt.Println(name, hash.String())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment