Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wadackel/go-gitlog
Go (golang) package for providing a means to handle git-log.
https://github.com/wadackel/go-gitlog
git go golang golang-package
Last synced: 11 days ago
JSON representation
Go (golang) package for providing a means to handle git-log.
- Host: GitHub
- URL: https://github.com/wadackel/go-gitlog
- Owner: wadackel
- License: mit
- Created: 2018-01-28T15:45:35.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-06T17:50:14.000Z (7 months ago)
- Last Synced: 2024-10-11T20:17:55.122Z (27 days ago)
- Topics: git, go, golang, golang-package
- Language: Go
- Homepage: https://godoc.org/github.com/tsuyoshiwada/go-gitlog
- Size: 147 KB
- Stars: 12
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# go-gitlog
[![godoc.org](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/tsuyoshiwada/go-gitlog)
[![Travis](https://img.shields.io/travis/tsuyoshiwada/go-gitlog.svg?style=flat-square)](https://travis-ci.org/tsuyoshiwada/go-gitlog)
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/tsuyoshiwada/go-gitlog/blob/master/LICENSE)> Go (golang) package for providing a means to handle git-log.
## Installation
To install `go-gitlog`, simply run:
```bash
$ go get -u github.com/tsuyoshiwada/go-gitlog
```## Usage
It is the simplest example.
```go
package mainimport (
"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](https://godoc.org/github.com/tsuyoshiwada/go-gitlog) for API detail of [Log](https://godoc.org/github.com/tsuyoshiwada/go-gitlog#GitLog) :+1:
## Options
By using [Params](https://godoc.org/github.com/tsuyoshiwada/go-gitlog#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 `
Specification of `revisionrange` can be realized by giving a [RevArgs](https://godoc.org/github.com/tsuyoshiwada/go-gitlog#RevArgs) interface.
```go
commits, err := git.Log(&gitlog.Rev{"5e312d5"}, nil)
```### `$ git log ..`
For double dot notation use [RevRange](https://godoc.org/github.com/tsuyoshiwada/go-gitlog#RevRange).
```go
commits, err := git.Log(&gitlog.RevRange{
Old: "v0.1.7",
New: "v1.2.3",
}, nil)
```### `$ git log -n `
Use [RevNumber](https://godoc.org/github.com/tsuyoshiwada/go-gitlog#RevNumber) to get the specified number of commits.
```go
commits, err := git.Log(&gitlog.RevNumber{10}, nil)
```### `$ git log --since
By using [RevTime](https://godoc.org/github.com/tsuyoshiwada/go-gitlog#RevTime) you can specify the range by time.
**Since and Until:**
```go
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:**
```go
commits, err := git.Log(&gitlog.RevTime{
Since: time.Date(2018, 1, 2, 12, 0, 0, time.UTC),
}, nil)
```**Only until:**
```go
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
1. Fork (https://github.com/tsuyoshiwada/go-gitlog)
1. Create a feature branch
1. Commit your changes
1. Rebase your local changes against the master branch
1. Run test suite with the `go test` command and confirm that it passes
1. Create new Pull Request :muscle:Bugs, feature requests and comments are more than welcome in the [issues](https://github.com/tsuyoshiwada/go-gitlog/issues).
## License
[MIT © tsuyoshiwada](./LICENSE)