go-gitlog
Go (golang) package for providing a means to handle git-log.
Installation
To install go-gitlog
, simply run:
$ go get -u github.com/tsuyoshiwada/go-gitlog
Usage
It is the simplest example.
package main
import (
"log"
"github.com/tsuyoshiwada/go-gitlog"
)
func main() {
// New gitlog
git := gitlog.New(&gitlog.Config{
GitBin: "/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 👍
Options
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.
Examples
$ 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)
How it works
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.
Contribute
- 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.
License
MIT © tsuyoshiwada