Skip to content

wadackel/go-gitcmd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-gitcmd

godoc.org Travis MIT License

Go (golang) package providing for tiny git command wrapper.

Installation

To install go-gitcmd, simply run:

$ go get -u github.com/tsuyoshiwada/go-gitcmd

Usage

It is the simplest example.

package main

import (
	"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 for API detail 👍

How to Mock

Since Client is an interface, it can easily be Mocked.

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)
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the go test command and confirm that it passes
  6. Create new Pull Request 💪

Bugs, feature requests and comments are more than welcome in the issues.

License

MIT © tsuyoshiwada

About

Go (golang) package providing for tiny git command wrapper.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages