Go (golang) package for providing a means to handle git-log.
MIT License
Go (golang) package for providing a means to handle git-log.
To install go-gitlog
, simply run:
$ go get -u github.com/tsuyoshiwada/go-gitlog
It is the simplest example.
package main
import (
"log"
"github.com/tsuyoshiwada/go-gitlog"
)
func main() {
// New gitlog
git := gitlog.New(&gitlog.Config{
Bin: "/your/custom/git/bin", // default "git"
Path: "/repo/path/to", // default "."
})
// List git-log
commits, err := git.Log(nil, nil)
if err != nil {
log.Fatalln(err)
}
// Output
for _, commit := range commits {
fmt.Printf(
"%s %s %s\n",
commit.Hash.Short,
commit.Author.Name,
commit.Subject,
)
}
}
See godoc for API detail of Log 👍
By using Params you can customize the log retrieval.
MergesOnly
Give the --merges
option.
IgnoreMerges
Give the --no-merges
option.
Reverse
Give the --reverse
option.
$ git log <sha1|tag|ref>
Specification of revisionrange
can be realized by giving a RevArgs interface.
commits, err := git.Log(&gitlog.Rev{"5e312d5"}, nil)
$ git log <sha1|tag|ref>..<sha1|tag|ref>
For double dot notation use RevRange.
commits, err := git.Log(&gitlog.RevRange{
Old: "v0.1.7",
New: "v1.2.3",
}, nil)
$ git log -n <n>
Use RevNumber to get the specified number of commits.
commits, err := git.Log(&gitlog.RevNumber{10}, nil)
$ git log --since <time> --until <time>
By using RevTime you can specify the range by time.
Since and Until:
commits, err := git.Log(&gitlog.RevTime{
Since: time.Date(2018, 3, 4, 23, 0, 0, time.UTC),
Until: time.Date(2018, 1, 2, 12, 0, 0, time.UTC),
}, nil)
Only since:
commits, err := git.Log(&gitlog.RevTime{
Since: time.Date(2018, 1, 2, 12, 0, 0, time.UTC),
}, nil)
Only until:
commits, err := git.Log(&gitlog.RevTime{
Until: time.Date(2018, 1, 2, 12, 0, 0, time.UTC),
}, nil)
Internally we use the git command to format it with the --pretty
option of log and parse the standard output.
So, only local git repositories are eligible for acquisition.
go test
command and confirm that it passesBugs, feature requests and comments are more than welcome in the issues.