Documentation
¶
Overview ¶
Package gitw git command wrapper, git changelog, repo information and some git tools.
Index ¶
- Constants
- Variables
- func Alias(name string) string
- func AllVars() string
- func Branches() ([]string, error)
- func CommentChar(text string) (string, error)
- func Config(name string) string
- func ConfigAll(name string) ([]string, error)
- func DataDir() (string, error)
- func EditText(data string) string
- func Editor() string
- func FirstLine(output string) string
- func GlobalConfig(name string) (string, error)
- func HasDotGitDir(path string) bool
- func HasFile(segments ...string) bool
- func Head() (string, error)
- func IsDebug() bool
- func IsGitCmd(command string) bool
- func IsGitCommand(command string) bool
- func IsGitDir(dir string) bool
- func MustString(s string, err error) string
- func MustStrings(ss []string, err error) []string
- func OutputLines(output string) []string
- func ParseRemoteURL(URL string, r *RemoteInfo) (err error)
- 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 RestStd()
- func Run(args ...string) error
- func SetDebug(open bool)
- func SetGlobalConfig(name, value string) error
- func SetWorkdir(dir string)
- func ShowDiff(sha string) (string, error)
- func ShowLogs(sha1, sha2 string) (string, error)
- func Spawn(args ...string) error
- func SymbolicFullName(name string) (string, error)
- func SymbolicRef(ref string) (string, error)
- func Tags(args ...string) ([]string, error)
- func Var(name string) string
- func Version() (string, error)
- func Workdir() (string, error)
- func WorkdirName() (string, error)
- type GitWrap
- func Branch(args ...string) *GitWrap
- func Cmd(cmd string, args ...string) *GitWrap
- func Log(args ...string) *GitWrap
- func New(args ...string) *GitWrap
- func NewWithArgs(cmd string, args ...string) *GitWrap
- func NewWithWorkdir(workdir string, args ...string) *GitWrap
- func Remote(args ...string) *GitWrap
- func RevList(args ...string) *GitWrap
- func Show(args ...string) *GitWrap
- func Std() *GitWrap
- func Tag(args ...string) *GitWrap
- func (gw *GitWrap) Add(args ...string) *GitWrap
- func (gw *GitWrap) AddArg(args ...string) *GitWrap
- func (gw *GitWrap) AddArgs(args []string) *GitWrap
- func (gw *GitWrap) Annotate(args ...string) *GitWrap
- func (gw *GitWrap) Apply(args ...string) *GitWrap
- func (gw *GitWrap) ArgIf(arg string, exprOk bool) *GitWrap
- func (gw *GitWrap) Argf(format string, args ...interface{}) *GitWrap
- func (gw *GitWrap) Bisect(args ...string) *GitWrap
- func (gw *GitWrap) Blame(args ...string) *GitWrap
- func (gw *GitWrap) Branch(args ...string) *GitWrap
- func (gw *GitWrap) Checkout(args ...string) *GitWrap
- func (gw *GitWrap) CherryPick(args ...string) *GitWrap
- func (gw *GitWrap) Clean(args ...string) *GitWrap
- func (gw *GitWrap) Clone(args ...string) *GitWrap
- func (gw *GitWrap) Cmd(cmd string, args ...string) *GitWrap
- func (gw *GitWrap) Cmdline() string
- func (gw *GitWrap) CombinedOutput() (string, error)
- func (gw *GitWrap) Commit(args ...string) *GitWrap
- func (gw *GitWrap) Config(args ...string) *GitWrap
- func (gw *GitWrap) Describe(args ...string) *GitWrap
- func (gw *GitWrap) Diff(args ...string) *GitWrap
- func (gw *GitWrap) Exec() error
- func (gw *GitWrap) Fetch(args ...string) *GitWrap
- func (gw *GitWrap) GitDir() string
- func (gw *GitWrap) Grep(args ...string) *GitWrap
- func (gw *GitWrap) Init(args ...string) *GitWrap
- func (gw *GitWrap) IsGitRepo() bool
- func (gw *GitWrap) Log(args ...string) *GitWrap
- func (gw *GitWrap) Merge(args ...string) *GitWrap
- func (gw *GitWrap) MustRun()
- func (gw *GitWrap) Mv(args ...string) *GitWrap
- func (gw *GitWrap) New(args ...string) *GitWrap
- func (gw *GitWrap) NewExecCmd() *exec.Cmd
- func (gw *GitWrap) OnBeforeExec(fn func(gw *GitWrap)) *GitWrap
- func (gw *GitWrap) Output() (string, error)
- func (gw *GitWrap) OutputLines() ([]string, error)
- func (gw *GitWrap) Pull(args ...string) *GitWrap
- func (gw *GitWrap) Push(args ...string) *GitWrap
- func (gw *GitWrap) Rebase(args ...string) *GitWrap
- func (gw *GitWrap) Reflog(args ...string) *GitWrap
- func (gw *GitWrap) Remote(args ...string) *GitWrap
- func (gw *GitWrap) Reset(args ...string) *GitWrap
- func (gw *GitWrap) ResetArgs()
- func (gw *GitWrap) Restore(args ...string) *GitWrap
- func (gw *GitWrap) RevList(args ...string) *GitWrap
- func (gw *GitWrap) RevParse(args ...string) *GitWrap
- func (gw *GitWrap) Revert(args ...string) *GitWrap
- func (gw *GitWrap) Rm(args ...string) *GitWrap
- func (gw *GitWrap) Run() error
- func (gw *GitWrap) SafeLines() []string
- func (gw *GitWrap) SafeOutput() string
- func (gw *GitWrap) ShortLog(args ...string) *GitWrap
- func (gw *GitWrap) Show(args ...string) *GitWrap
- func (gw *GitWrap) Spawn() error
- func (gw *GitWrap) Stash(args ...string) *GitWrap
- func (gw *GitWrap) Status(args ...string) *GitWrap
- func (gw *GitWrap) String() string
- func (gw *GitWrap) Sub(cmd string, args ...string) *GitWrap
- func (gw *GitWrap) Success() bool
- func (gw *GitWrap) Switch(args ...string) *GitWrap
- func (gw *GitWrap) Tag(args ...string) *GitWrap
- func (gw *GitWrap) Var(args ...string) *GitWrap
- 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) WithArgsIf(args []string, exprOk bool) *GitWrap
- func (gw *GitWrap) WithFn(fn func(gw *GitWrap)) *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
- func (gw *GitWrap) Worktree(args ...string) *GitWrap
- type Range
- type RemoteInfo
- func (r *RemoteInfo) GitURL() string
- func (r *RemoteInfo) Invalid() bool
- func (r *RemoteInfo) Path() string
- func (r *RemoteInfo) RawURLOfHTTP() string
- func (r *RemoteInfo) RepoPath() string
- func (r *RemoteInfo) String() string
- func (r *RemoteInfo) URLOfHTTP() string
- func (r *RemoteInfo) URLOfHTTPS() string
- func (r *RemoteInfo) Valid() bool
- type RemoteInfos
- type Repo
- func (r *Repo) AllRemoteInfos() map[string]RemoteInfos
- func (r *Repo) Cmd(name string, args ...string) *GitWrap
- func (r *Repo) CurrentBranch() string
- func (r *Repo) DefaultRemoteInfo(typ ...string) *RemoteInfo
- func (r *Repo) Dir() string
- func (r *Repo) Err() error
- func (r *Repo) Git() *GitWrap
- func (r *Repo) HasRemote(name string) bool
- func (r *Repo) Info() *RepoInfo
- func (r *Repo) Init() error
- func (r *Repo) IsInited() bool
- func (r *Repo) LargestTag() string
- func (r *Repo) LastAbbrevID() string
- func (r *Repo) LastCommitID() string
- func (r *Repo) MaxTag() string
- func (r *Repo) PrevMaxTag() string
- func (r *Repo) RandomRemoteInfo(typ ...string) *RemoteInfo
- func (r *Repo) RemoteInfo(remote string, typ ...string) *RemoteInfo
- func (r *Repo) RemoteInfos(remote string) RemoteInfos
- func (r *Repo) RemoteNames() []string
- func (r *Repo) TagSecondMax() string
- func (r *Repo) Tags() []string
- func (r *Repo) TagsSortedByRefName() []string
- func (r *Repo) WithConfig(cfg *RepoConfig) *Repo
- func (r *Repo) WithConfigFn(fn func(cfg *RepoConfig)) *Repo
- func (r *Repo) WithFn(fn func(r *Repo)) *Repo
- type RepoConfig
- type RepoInfo
Constants ¶
const ( ProtoSSH = "ssh" ProtoHTTP = "http" SchemeGIT = "git" SchemeHTTP = "http" SchemeHTTPS = "https" )
some consts for remote info
const ( RemoteTypePush = "push" RemoteTypeFetch = "fetch" )
remote type names
const GitDir = ".git"
GitDir name
Variables ¶
var ( // DefaultBin name DefaultBin = "git" // DefaultBranchName value DefaultBranchName = "master" // DefaultRemoteName value DefaultRemoteName = "origin" )
var ErrRemoteInfoNil = errorx.Raw("the remote info data cannot be nil")
ErrRemoteInfoNil error
var GlobalFlags []string
GlobalFlags for run git command
Functions ¶
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 MustString ¶
MustString must return string, will panic on error
func MustStrings ¶
MustStrings must return strings, will panic on error
func ParseRemoteURL ¶
func ParseRemoteURL(URL string, r *RemoteInfo) (err error)
ParseRemoteURL info to the RemoteInfo object.
func ShowLogs ¶
ShowLogs show git log between sha1 to sha2
Usage:
gitw.ShowLogs("v1.0.2", "v1.0.3") gitw.ShowLogs("commit id 1", "commit id 2")
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"
func Tags ¶
Tags list
something:
`git tag -l` == `git tag --format '%(refname:strip=2)'`
more e.g:
// refname - sorts in a lexicographic order // version:refname or v:refname - this sorts based on version git tag --sort=-version:refname git tag -l --sort version:refname git tag --format '%(refname:strip=2)' --sort=-taggerdate git tag --format '%(refname:strip=2) %(objectname)' --sort=-taggerdate git log --tags --simplify-by-decoration --pretty="format:%d - %cr"
Types ¶
type GitWrap ¶
type GitWrap struct { // Workdir for run git Workdir string // Bin git bin name. default is "git" Bin string // Args for run git. contains git command name. Args []string // Stdin more settings Stdin io.Reader Stdout io.Writer Stderr io.Writer // BeforeExec command hook. // // Usage: gw.BeforeExec = gitw.PrintCmdline BeforeExec func(gw *GitWrap) }
GitWrap is a project-wide struct that represents a command to be run in the console.
func NewWithArgs ¶
NewWithArgs create instance with git cmd and args
func NewWithWorkdir ¶
NewWithWorkdir create instance with workdir and args
func (*GitWrap) CherryPick ¶
CherryPick command for git
func (*GitWrap) CombinedOutput ¶
CombinedOutput run and return output, will combine stderr and stdout output
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 ¶
OnBeforeExec add hook
func (*GitWrap) OutputLines ¶
OutputLines run and return output as lines
func (*GitWrap) RevParse ¶
RevParse command for git
rev-parse usage:
git rev-parse --show-toplevel // get git workdir, repo dir. git rev-parse -q --git-dir // get git data dir name. eg: .git
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) WithArgsIf ¶
WithArgsIf add arg and returns the current object
func (*GitWrap) WithOutput ¶
WithOutput returns the current argument
func (*GitWrap) WithWorkDir ¶
WithWorkDir returns the current object
type RemoteInfo ¶
type RemoteInfo struct { // Name the repo remote name, default see DefaultRemoteName Name string // Type remote type. allow: push, fetch Type string // URL full git remote URL string. // // eg: // - http: "https://github.com/gookit/gitw.git" // - git: "git@github.com:gookit/gitw.git" 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/gitw.git" - git: "git@github.com:gookit/gitw.git"
func NewEmptyRemoteInfo ¶
func NewEmptyRemoteInfo(URL string) *RemoteInfo
NewEmptyRemoteInfo only with URL string.
func NewRemoteInfo ¶
func NewRemoteInfo(name, url, typ string) (*RemoteInfo, error)
NewRemoteInfo create
func (*RemoteInfo) GitURL ¶
func (r *RemoteInfo) GitURL() string
GitURL build. eg: "git@github.com:gookit/gitw.git"
func (*RemoteInfo) RawURLOfHTTP ¶
func (r *RemoteInfo) RawURLOfHTTP() string
RawURLOfHTTP get, if RemoteInfo.URL is git proto, build an https url.
type RemoteInfos ¶
type RemoteInfos map[string]*RemoteInfo
RemoteInfos map. key is type name(see RemoteTypePush)
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo struct
func (*Repo) AllRemoteInfos ¶
func (r *Repo) AllRemoteInfos() map[string]RemoteInfos
AllRemoteInfos get
func (*Repo) CurrentBranch ¶
CurrentBranch return current branch name
func (*Repo) DefaultRemoteInfo ¶
func (r *Repo) DefaultRemoteInfo(typ ...string) *RemoteInfo
DefaultRemoteInfo get
func (*Repo) LargestTag ¶
LargestTag get max tag version of the repo
func (*Repo) LastAbbrevID ¶
LastAbbrevID get last abbrev commit ID, len is 7
func (*Repo) PrevMaxTag ¶
PrevMaxTag get second-largest tag of the repo
func (*Repo) RandomRemoteInfo ¶
func (r *Repo) RandomRemoteInfo(typ ...string) *RemoteInfo
RandomRemoteInfo get
func (*Repo) RemoteInfo ¶
func (r *Repo) RemoteInfo(remote string, typ ...string) *RemoteInfo
RemoteInfo get. if typ is empty, will return random type info.
func (*Repo) RemoteInfos ¶
func (r *Repo) RemoteInfos(remote string) RemoteInfos
RemoteInfos get by remote name
func (*Repo) TagSecondMax ¶
TagSecondMax get second-largest tag of the repo
func (*Repo) TagsSortedByRefName ¶
TagsSortedByRefName get repo tags list
func (*Repo) WithConfig ¶
func (r *Repo) WithConfig(cfg *RepoConfig) *Repo
WithConfig new repo config
func (*Repo) WithConfigFn ¶
func (r *Repo) WithConfigFn(fn func(cfg *RepoConfig)) *Repo
WithConfigFn new repo config func
type RepoConfig ¶
RepoConfig struct