Documentation
¶
Overview ¶
Package gitwrap is library warp git commands. some code is refer from github/hub
Index ¶
- Constants
- Variables
- func Alias(name string) string
- func AllVars() string
- func CommentChar(text string) (string, error)
- func Config(name string) string
- func ConfigAll(name string) ([]string, error)
- func Dir() (string, error)
- func EditText(data string) string
- func Editor() string
- func GlobalConfig(name string) (string, error)
- func HasFile(segments ...string) bool
- func Head() (string, error)
- func IsGitCmd(command string) bool
- func IsGitCommand(command string) bool
- func IsGitDir(dir string) bool
- func LocalBranches() ([]string, error)
- func Log(sha1, sha2 string) (string, error)
- func MustString(s string, err error) string
- func MustStrings(ss []string, err error) []string
- func PrintCmdline(gw *GitWrap)
- func Quiet(args ...string) bool
- func Ref(ref string) (string, error)
- func RefList(a, b string) ([]string, error)
- func Remotes() ([]string, error)
- func Run(args ...string) error
- func SetDebug()
- func SetGlobalConfig(name, value string) error
- func Show(sha string) (string, error)
- func Spawn(args ...string) error
- func SymbolicFullName(name string) (string, error)
- func SymbolicRef(ref string) (string, error)
- func Var(name string) string
- func Version() (string, error)
- func Workdir() (string, error)
- func WorkdirName() (string, error)
- type CmdBuilder
- type GitWrap
- func (gw *GitWrap) Add(args ...string) *GitWrap
- func (gw *GitWrap) AddIf(arg string, exprOk bool) *GitWrap
- func (gw *GitWrap) Addf(format string, args ...interface{}) *GitWrap
- func (gw *GitWrap) Cmdline() string
- func (gw *GitWrap) CombinedOutput() (string, error)
- func (gw *GitWrap) CurrentBranch() string
- func (gw *GitWrap) Exec() error
- func (gw *GitWrap) GitDir() string
- func (gw *GitWrap) IsGitRepo() bool
- func (gw *GitWrap) MustRun()
- func (gw *GitWrap) NewExecCmd() *exec.Cmd
- func (gw *GitWrap) OnBeforeExec(fn func(gw *GitWrap)) *GitWrap
- func (gw *GitWrap) Output() (string, error)
- func (gw *GitWrap) Run() error
- func (gw *GitWrap) SafeOutput() string
- func (gw *GitWrap) Spawn() error
- func (gw *GitWrap) String() string
- func (gw *GitWrap) SubCmd(cmd string) *GitWrap
- func (gw *GitWrap) Success() bool
- func (gw *GitWrap) WithArg(args ...string) *GitWrap
- func (gw *GitWrap) WithArgIf(arg string, exprOk bool) *GitWrap
- func (gw *GitWrap) WithArgf(format string, args ...interface{}) *GitWrap
- func (gw *GitWrap) WithArgs(args []string) *GitWrap
- func (gw *GitWrap) WithOutput(out *os.File, errOut *os.File) *GitWrap
- func (gw *GitWrap) WithStdin(in *os.File) *GitWrap
- func (gw *GitWrap) WithWorkDir(dir string) *GitWrap
- type Range
- type RemoteInfo
- type Repo
- type RepoConfig
- type RepoInfo
Constants ¶
const ( ProtoSsh = "ssh" ProtoHttp = "http" DefaultRemoteName = "origin" )
Variables ¶
var ( DefaultBin = "git" GitDir = ".git" )
var GlobalFlags []string
GlobalFlags for run git command
Functions ¶
func CommentChar ¶
func Editor ¶
func Editor() string
Editor returns program name of the editor. from https://github.com/alibaba/git-repo-go/blob/master/editor/editor.go
func GlobalConfig ¶
GlobalConfig get git global config by name
func Log ¶
Log show git log between sha1 to sha2
Usage:
gitwrap.Log("v1.0.2", "v1.0.3") gitwrap.Log("commit id 1", "commit id 2")
func MustString ¶ added in v0.1.1
MustString must return string, will panic on error
func MustStrings ¶ added in v0.1.1
MustStrings must return strings, will panic on error
func SymbolicFullName ¶
SymbolicFullName reads a branch name from a ref such as "@{upstream}"
func SymbolicRef ¶
SymbolicRef reads a branch name from a ref such as "HEAD"
Types ¶
type GitWrap ¶
type GitWrap struct { // Bin git bin name. default is "git" Bin string // Cmd sub command name of git // Cmd string Args []string // extra WorkDir string Stdin *os.File Stdout *os.File Stderr *os.File // BeforeExec command BeforeExec func(gw *GitWrap) // contains filtered or unexported fields }
GitWrap is a project-wide struct that represents a command to be run in the console.
func NewWithArgs ¶ added in v0.1.1
NewWithArgs create instance with git cmd and args
func (*GitWrap) CombinedOutput ¶
CombinedOutput run and return output, will combine stderr and stdout output
func (*GitWrap) CurrentBranch ¶
CurrentBranch return current branch name
func (*GitWrap) Exec ¶
Exec runs command with exec(3) Note that Windows doesn't support exec(3): http://golang.org/src/pkg/syscall/exec_windows.go#L339
func (*GitWrap) NewExecCmd ¶
NewExecCmd create exec.Cmd from current cmd
func (*GitWrap) OnBeforeExec ¶ added in v0.1.2
OnBeforeExec add hook
func (*GitWrap) Run ¶
Run runs command with `Exec` on platforms except Windows which only supports `Spawn`
func (*GitWrap) SafeOutput ¶
SafeOutput run and return output
func (*GitWrap) WithArgf ¶ added in v0.1.1
WithArgf add arg and returns the current object. alias of the Addf()
func (*GitWrap) WithOutput ¶
WithOutput returns the current argument
func (*GitWrap) WithWorkDir ¶
WithWorkDir returns the current object
type RemoteInfo ¶
type RemoteInfo struct {
// the repo remote name and URL address
Name, URL string
// Scheme the url scheme. eg: git, http, https
Scheme string
// Host name. eg: "github.com"
Host string
// the group, repo name
Group, Repo string
// Proto the type 'ssh' OR 'http'
Proto string
}
RemoteInfo struct - http: "https://github.com/gookit/gitwrap.git" - git: "git@github.com:gookit/gitwrap.git"
func (*RemoteInfo) GitUrl ¶
func (r *RemoteInfo) GitUrl() string
func (*RemoteInfo) HttpUrl ¶
func (r *RemoteInfo) HttpUrl() string
func (*RemoteInfo) HttpsUrl ¶
func (r *RemoteInfo) HttpsUrl() string
func (*RemoteInfo) Invalid ¶
func (r *RemoteInfo) Invalid() bool
func (*RemoteInfo) Path ¶
func (r *RemoteInfo) Path() string
func (*RemoteInfo) String ¶
func (r *RemoteInfo) String() string
func (*RemoteInfo) Valid ¶
func (r *RemoteInfo) Valid() bool
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo struct
func (*Repo) DefaultRemoteInfo ¶
func (r *Repo) DefaultRemoteInfo() *RemoteInfo
func (*Repo) RemoteInfo ¶
func (r *Repo) RemoteInfo(name string) *RemoteInfo
func (*Repo) RemoteInfos ¶
func (r *Repo) RemoteInfos()
type RepoConfig ¶
RepoConfig struct