Skip to content

Instantly share code, notes, and snippets.

@2no
Last active December 11, 2016 12:08
Show Gist options
  • Save 2no/07834128f69cbf7bf71c5ca1e0aec29e to your computer and use it in GitHub Desktop.
Save 2no/07834128f69cbf7bf71c5ca1e0aec29e to your computer and use it in GitHub Desktop.
git2go で `git log`
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/libgit2/git2go"
)
func main() {
pwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
repo, err := git.OpenRepository(pwd)
if err != nil {
log.Fatal(err)
}
odb, err := repo.Odb()
if err != nil {
log.Fatal(err)
}
err = odb.ForEach(func(oid *git.Oid) error {
obj, err := repo.Lookup(oid)
if err != nil {
return err
}
if obj.Type() != git.ObjectCommit {
return nil
}
commit, err := obj.AsCommit()
if err != nil {
return err
}
committer := commit.Committer()
message := strings.Replace(commit.Message(), "\n", "", -1)
fmt.Printf("%s\t%s\t%s\n", committer.When, committer.Name, message)
return nil
})
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment