Last active
December 11, 2016 12:08
-
-
Save 2no/07834128f69cbf7bf71c5ca1e0aec29e to your computer and use it in GitHub Desktop.
git2go で `git log`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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