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.
Give the --merges
option.
Give the --no-merges
option.
Give the --reverse
option.
Specification of revisionrange
can be realized by giving a RevArgs interface.
commits, err := git.Log(&gitlog.Rev{"5e312d5"}, nil)
For double dot notation use RevRange.
commits, err := git.Log(&gitlog.RevRange{
Old: "v0.1.7",
New: "v1.2.3",
}, nil)
Use RevNumber to get the specified number of commits.
commits, err := git.Log(&gitlog.RevNumber{10}, nil)
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.
- Fork (https://github.com/tsuyoshiwada/go-gitlog)
- Create a feature branch
- Commit your changes
- Rebase your local changes against the master branch
- Run test suite with the
go test
command and confirm that it passes - Create new Pull Request 💪
Bugs, feature requests and comments are more than welcome in the issues.