Skip to content

rawnly/gitgud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gitgud

A tiny library to run git commands.

Sometimes working with exec.Cmd might not be easy as expected. Here gitgud comes to help you. Every command has a standard Runnable output. It is similar to the exec.Cmd interface but with some tweaking. If you need more customisation you can always use the original exec.Cmd instance and tweak it yourself.

Features

  • Ease of use
  • Handle command errors
  • Supports custom stderr, stdout and stdin
  • Run directly in the terminal with RunInTerminal

Usage

go get -u github.com/rawnly/gitgud
package main

import (
	"fmt"
	"github.com/rawnly/gitgud/git"
)

func main() {
	// equivalent to "git status -s" 
	status, err := git.Status(&git.StatusOptions{
		Short: true,
	}).Output()

	if err != nil {
		panic(err.Error())
	}
	
	fmt.Println(status)
} 

Advanced Example

package main 

import "github.com/rawnly/gitgud/git"
import "os"

func main() {
	diffCmd := git.Commit("docs(readme): updated example", nil)
	
	stdout := &bytes.Buffer{}
	stderr := &bytes.Buffer{}
	
	diffCmd.Cmd.Stdout = stdout
	diffCmd.Cmd.Stderr = stderr
	
	if err := diffCmd.Run(); err != nil {
		panic(err)
	}
}

Missing Something?

If you're missing some commands you can always use run.Git to manually run git commands.

package main

import (
	"fmt"
	"github.com/rawnly/gitgud/run"
)

func main() {
	// equivalent to "git status -s" 
	status, err := run.Git("status", "-s").Output()

	if err != nil {
		panic(err.Error())
	}
	
	fmt.Println(status)
}

Available Commands

Start a working area

  • Clone
  • Init

Work on the current change

  • Add (partially done)
  • Mv
  • Restore
  • Rm

Examine the history and state

  • Bisect
  • Diff
  • Grep
  • Log
  • Show
  • Status

Grow, mark and tweak your common history

  • Branch
  • Checkout
  • Commit
  • Merge
  • Rebase
  • Reset
  • Switch
  • Tag

Collaborate

  • Fetch
  • Push
  • Pull

Others

  • Config, SetConfig

About

Git library with DX in mind

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages