gitcmd

package module
v0.0.0-...-5f1f5f9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2018 License: MIT Imports: 7 Imported by: 30

README

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

Documentation

Overview

Package gitcmd is providing for tiny git command wrapper.

Example
git := New(nil)

out, err := git.Exec("rev-parse", "--git-dir")
if err != nil {
	log.Fatal(err)
}

fmt.Println(out)
Output:

.git

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	CanExec() error
	Exec(string, ...string) (string, error)
	InsideWorkTree() error
}

Client of git command

func New

func New(config *Config) Client

New git command client

type Config

type Config struct {
	Bin string // default "git"
}

Config for git command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL