Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wadackel/go-gitcmd
Go (golang) package providing for tiny git command wrapper.
https://github.com/wadackel/go-gitcmd
git go golang golang-package
Last synced: 7 days ago
JSON representation
Go (golang) package providing for tiny git command wrapper.
- Host: GitHub
- URL: https://github.com/wadackel/go-gitcmd
- Owner: wadackel
- License: mit
- Created: 2018-02-05T13:00:11.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-05T14:57:42.000Z (almost 7 years ago)
- Last Synced: 2024-10-11T20:17:55.173Z (about 1 month ago)
- Topics: git, go, golang, golang-package
- Language: Go
- Homepage: https://godoc.org/github.com/tsuyoshiwada/go-gitcmd
- Size: 4.88 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# go-gitcmd
[![godoc.org](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/tsuyoshiwada/go-gitcmd)
[![Travis](https://img.shields.io/travis/tsuyoshiwada/go-gitcmd.svg?style=flat-square)](https://travis-ci.org/tsuyoshiwada/go-gitcmd)
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/tsuyoshiwada/go-gitcmd/blob/master/LICENSE)> Go (golang) package providing for tiny git command wrapper.
## Installation
To install `go-gitcmd`, simply run:
```bash
$ go get -u github.com/tsuyoshiwada/go-gitcmd
```## Usage
It is the simplest example.
```go
package mainimport (
"log"
"github.com/tsuyoshiwada/go-gitcmd"
)func main() {
git := gitcmd.New(nil) // or `git := gitcmd.New(&Config{Bin: "/your/custom/git/bin"})`out, err := git.Exec("rev-parse", "--git-dir")
if err != nil {
log.Fatal(err)
}fmt.Println(out) // ".git"
}
```See [godoc](https://godoc.org/github.com/tsuyoshiwada/go-gitcmd) for API detail :+1:
## How to Mock
Since `Client` is an interface, it can easily be Mocked.
```go
type MockClient struct {
gitcmd.Client // Interface embedding
ReturnCanExec func() error
ReturnExec func(string, ...string) (string, error)
ReturnInsideWorkTree func() error
}func (m *MockClient) CanExec() error {
return m.ReturnCanExec()
}func (m *MockClient) Exec(subcmd string, args ...string) (string, error) {
return m.ReturnExec(subcmd, args...)
}func (m *MockClient) InsideWorkTree() error {
return m.ReturnInsideWorkTree()
}func main() {
git := &MockClient{}// Set `InsideWorkTree()` mock function
git.ReturnInsideWorkTree = func() error {
return errors.New("error...")
}err := git.InsideWorkTree()
fmt.Println(err.Error()) // "error..."
}
```## Contribute
1. Fork (https://github.com/tsuyoshiwada/go-gitcmd)
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-gitcmd/issues).
## License
[MIT © tsuyoshiwada](./LICENSE)