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) stringdeprecated
- 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) []stringdeprecated
- 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 BranchInfo
- type BranchInfos
- func (bs *BranchInfos) BrLines() []string
- func (bs *BranchInfos) Current() *BranchInfo
- func (bs *BranchInfos) GetByName(branch string, remote ...string) *BranchInfo
- func (bs *BranchInfos) HasLocal(branch string) bool
- func (bs *BranchInfos) HasRemote(branch, remote string) bool
- func (bs *BranchInfos) IsExists(branch string, remote ...string) bool
- func (bs *BranchInfos) LastErr() error
- func (bs *BranchInfos) Locales() map[string]*BranchInfo
- func (bs *BranchInfos) Parse() *BranchInfos
- func (bs *BranchInfos) Remotes(remote string) map[string]*BranchInfo
- func (bs *BranchInfos) Search(name string, flag int) []*BranchInfo
- func (bs *BranchInfos) SetBrLines(brLines []string)
- 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) PrintCmdline() *GitWrap
- 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) WithDryRun(dryRun bool) *GitWrap
- func (gw *GitWrap) WithFn(fn func(gw *GitWrap)) *GitWrap
- func (gw *GitWrap) WithOutput(out, errOut io.Writer) *GitWrap
- func (gw *GitWrap) WithStdin(in io.Reader) *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) HTTPHost() 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) URLOrBuild() string
- func (r *RemoteInfo) Valid() bool
- type RemoteInfos
- type Repo
- func (r *Repo) AllRemoteInfos() map[string]RemoteInfos
- func (r *Repo) AutoMatchTag(sha string) string
- func (r *Repo) AutoMatchTagByType(sha string, tagType int) string
- func (r *Repo) BranchInfo(branch string, remote ...string) *BranchInfo
- func (r *Repo) BranchInfos() *BranchInfos
- func (r *Repo) Cmd(name string, args ...string) *GitWrap
- func (r *Repo) CurBranchInfo() *BranchInfo
- func (r *Repo) CurBranchName() string
- func (r *Repo) DefaultRemoteInfo(typ ...string) *RemoteInfo
- func (r *Repo) Dir() string
- func (r *Repo) Err() error
- func (r *Repo) FirstRemoteInfo(typ ...string) *RemoteInfo
- func (r *Repo) Git() *GitWrap
- func (r *Repo) HasBranch(branch string, remote ...string) bool
- func (r *Repo) HasLocalBranch(branch string) bool
- func (r *Repo) HasRemote(name string) bool
- func (r *Repo) HasRemoteBranch(branch, remote string) bool
- func (r *Repo) HeadBranchName() string
- func (r *Repo) Info() *RepoInfo
- func (r *Repo) Init() error
- func (r *Repo) IsInited() bool
- func (r *Repo) LargestTag() string
- func (r *Repo) LargestTagByTagType(tagType int) string
- func (r *Repo) LastAbbrevID() string
- func (r *Repo) LastCommitID() string
- func (r *Repo) MaxTag() string
- func (r *Repo) PrevMaxTag() string
- func (r *Repo) PrintCmdOnExec() *Repo
- func (r *Repo) QuickRun(cmd string, args ...string) error
- func (r *Repo) RandomRemoteInfo(typ ...string) *RemoteInfo
- func (r *Repo) ReadConfig() []byte
- func (r *Repo) ReadHEAD() []byte
- func (r *Repo) RemoteInfo(remote string, typ ...string) *RemoteInfo
- func (r *Repo) RemoteInfos(remote string) RemoteInfos
- func (r *Repo) RemoteLines() map[string]string
- func (r *Repo) RemoteNames() []string
- func (r *Repo) SearchBranches(name string, flag int) []*BranchInfo
- func (r *Repo) SetDryRun(dr bool) *Repo
- func (r *Repo) SetUpstreamTo(remote, branch string, localBranch ...string) error
- func (r *Repo) StatusInfo() *StatusInfo
- func (r *Repo) TagByDescribe(current string) (ver string)
- func (r *Repo) TagSecondMax() string
- func (r *Repo) TagSecondMaxByTagType(tagType int) string
- func (r *Repo) Tags() []string
- func (r *Repo) TagsSortedByCreatorDate() []string
- func (r *Repo) TagsSortedByRefName() []string
- func (r *Repo) UpstreamBranch() string
- func (r *Repo) UpstreamPath() string
- func (r *Repo) UpstreamRemote() 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
- type StatusInfo
Constants ¶
const ( // GitDir name GitDir = ".git" // HeadFile in .git/ HeadFile = "HEAD" // ConfFile in .git/ ConfFile = "config" // GitHubHost name GitHubHost = "github.com" // GitHubURL string GitHubURL = "https://github.com" // GitHubGit string GitHubGit = "git@github.com" )
const ( TypeGitHub = "github" TypeGitlab = "gitlab" TypeDefault = "git" )
git host type
const ( // DefaultBin name DefaultBin = "git" // DefaultBranchName value DefaultBranchName = "master" // DefaultRemoteName value DefaultRemoteName = "origin" )
const ( ProtoSSH = "ssh" ProtoHTTP = "http" SchemeGIT = "git" SchemeHTTP = "http" SchemeHTTPS = "https" )
some consts for remote info
const ( BranchLocal = "local" BranchRemote = "remote" )
branch types
const ( BrSearchLocal = 1 BrSearchRemote = 1 << 1 BrSearchAll = BrSearchRemote | BrSearchLocal )
flags for search branches
const ( RemoteTypePush = "push" RemoteTypeFetch = "fetch" )
remote type names
const ( TagLast = "last" TagPrev = "prev" TagHead = "head" )
some special keywords for match tag
const ( RefNameTagType int = iota CreatorDateTagType DescribeTagType )
enum type value constants for fetch tags
const RemotePfxOnBranch = "remotes/"
RemotePfxOnBranch prefix keywords
const ShaHead = "HEAD"
ShaHead keywords
const StatusPattern = `^([\w-]+)...([\w-]+)/(\w[\w/-]+)$`
StatusPattern string. eg: master...origin/master
Variables ¶
var ErrInvalidBrLine = errorx.Raw("invalid git branch line text")
ErrInvalidBrLine error
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 OutputLines
deprecated
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 BranchInfo ¶ added in v0.2.3
type BranchInfo struct { // Current active branch Current bool // Name The full branch name. eg: fea_xx, remotes/origin/fea_xx Name string // Hash commit hash ID. Hash string // HashMsg commit hash message. HashMsg string // Alias name Alias string // Remote name. local branch is empty. Remote string // Short only branch name. local branch is equals Name Short string }
BranchInfo for a git branch
func NewBranchInfo ¶ added in v0.2.3
func NewBranchInfo(line string) (*BranchInfo, error)
NewBranchInfo from branch line text
func ParseBranchLine ¶ added in v0.2.3
func ParseBranchLine(line string, verbose bool) (*BranchInfo, error)
ParseBranchLine to BranchInfo data
verbose:
False - only branch name True - get by `git br -v --all` format: * BRANCH_NAME COMMIT_ID COMMIT_MSG
func (*BranchInfo) IsRemoted ¶ added in v0.2.3
func (b *BranchInfo) IsRemoted() bool
IsRemoted branch check
func (*BranchInfo) IsValid ¶ added in v0.2.3
func (b *BranchInfo) IsValid() bool
IsValid branch check
func (*BranchInfo) ParseName ¶ added in v0.2.3
func (b *BranchInfo) ParseName() *BranchInfo
ParseName for get remote and short name.
func (*BranchInfo) SetName ¶ added in v0.2.3
func (b *BranchInfo) SetName(name string)
SetName for branch and parse
type BranchInfos ¶ added in v0.2.3
type BranchInfos struct {
// contains filtered or unexported fields
}
BranchInfos for a git repo
func EmptyBranchInfos ¶ added in v0.2.3
func EmptyBranchInfos() *BranchInfos
EmptyBranchInfos instance
func NewBranchInfos ¶ added in v0.2.3
func NewBranchInfos(gitOut string) *BranchInfos
NewBranchInfos create
func (*BranchInfos) Current ¶ added in v0.2.3
func (bs *BranchInfos) Current() *BranchInfo
Current branch
func (*BranchInfos) GetByName ¶ added in v0.2.3
func (bs *BranchInfos) GetByName(branch string, remote ...string) *BranchInfo
GetByName find branch by name
func (*BranchInfos) HasLocal ¶ added in v0.3.2
func (bs *BranchInfos) HasLocal(branch string) bool
HasLocal branch check
func (*BranchInfos) HasRemote ¶ added in v0.3.2
func (bs *BranchInfos) HasRemote(branch, remote string) bool
HasRemote branch check
func (*BranchInfos) IsExists ¶ added in v0.3.2
func (bs *BranchInfos) IsExists(branch string, remote ...string) bool
IsExists branch check
func (*BranchInfos) Locales ¶ added in v0.2.3
func (bs *BranchInfos) Locales() map[string]*BranchInfo
Locales branches
func (*BranchInfos) Parse ¶ added in v0.2.3
func (bs *BranchInfos) Parse() *BranchInfos
Parse given branch lines
func (*BranchInfos) Remotes ¶ added in v0.2.3
func (bs *BranchInfos) Remotes(remote string) map[string]*BranchInfo
Remotes branch infos get
if remote="", will return all remote branches
func (*BranchInfos) Search ¶ added in v0.2.3
func (bs *BranchInfos) Search(name string, flag int) []*BranchInfo
Search branches by name.
Usage:
Search("fea", BrSearchLocal) Search("fea", BrSearchAll) // search on remotes Search("fea", BrSearchRemote) // search on remotes and remote name must be equals "origin" Search("origin fea", BrSearchRemote)
func (*BranchInfos) SetBrLines ¶ added in v0.2.3
func (bs *BranchInfos) SetBrLines(brLines []string)
SetBrLines for parse.
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 // DryRun if True, not real execute command DryRun bool // 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) PrintCmdline ¶ added in v0.3.3
PrintCmdline on exec command
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) WithDryRun ¶ added in v0.3.3
WithDryRun on exec command
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) HTTPHost ¶ added in v0.3.2
func (r *RemoteInfo) HTTPHost() string
HTTPHost URL build. return like: https://github.com
func (*RemoteInfo) RawURLOfHTTP ¶
func (r *RemoteInfo) RawURLOfHTTP() string
RawURLOfHTTP get remote url, if RemoteInfo.URL is git proto, build an HTTPS url.
func (*RemoteInfo) URLOfHTTPS ¶
func (r *RemoteInfo) URLOfHTTPS() string
URLOfHTTPS build an HTTPS url.
func (*RemoteInfo) URLOrBuild ¶ added in v0.3.2
func (r *RemoteInfo) URLOrBuild() string
URLOrBuild get remote HTTP url, 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)
func (RemoteInfos) FetchInfo ¶ added in v0.3.2
func (rs RemoteInfos) FetchInfo() *RemoteInfo
FetchInfo fetch remote info
func (RemoteInfos) PushInfo ¶ added in v0.3.2
func (rs RemoteInfos) PushInfo() *RemoteInfo
PushInfo push remote info
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) AutoMatchTag ¶ added in v0.2.3
AutoMatchTag by given sha or tag name
func (*Repo) AutoMatchTagByType ¶ added in v0.2.5
AutoMatchTagByType by given sha or tag name.
func (*Repo) BranchInfo ¶ added in v0.2.3
func (r *Repo) BranchInfo(branch string, remote ...string) *BranchInfo
BranchInfo find branch info by name, if remote is empty, find local branch
func (*Repo) BranchInfos ¶ added in v0.2.3
func (r *Repo) BranchInfos() *BranchInfos
BranchInfos get branch infos of the repo
func (*Repo) CurBranchInfo ¶ added in v0.2.3
func (r *Repo) CurBranchInfo() *BranchInfo
CurBranchInfo get current branch info of the repo
func (*Repo) CurBranchName ¶ added in v0.2.3
CurBranchName return current branch name
func (*Repo) DefaultRemoteInfo ¶
func (r *Repo) DefaultRemoteInfo(typ ...string) *RemoteInfo
DefaultRemoteInfo get
func (*Repo) FirstRemoteInfo ¶ added in v0.3.2
func (r *Repo) FirstRemoteInfo(typ ...string) *RemoteInfo
FirstRemoteInfo get
func (*Repo) HasLocalBranch ¶ added in v0.3.2
func (*Repo) HasRemoteBranch ¶ added in v0.3.2
func (*Repo) HeadBranchName ¶ added in v0.3.3
HeadBranchName return current branch name
func (*Repo) LargestTag ¶
LargestTag get max tag version of the repo
func (*Repo) LargestTagByTagType ¶ added in v0.2.5
LargestTagByTagType get max tag version of the repo by tag_type
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) PrintCmdOnExec ¶ added in v0.3.2
PrintCmdOnExec settings.
func (*Repo) RandomRemoteInfo ¶
func (r *Repo) RandomRemoteInfo(typ ...string) *RemoteInfo
RandomRemoteInfo get
func (*Repo) ReadConfig ¶ added in v0.3.2
ReadConfig contents from REPO/.git/config
func (*Repo) RemoteInfo ¶
func (r *Repo) RemoteInfo(remote string, typ ...string) *RemoteInfo
RemoteInfo get by remote name and type.
- If remote is empty, will return default remote - If typ is empty, will return random type info.
Usage:
ri := RemoteInfo("origin") ri = RemoteInfo("origin", "push")
func (*Repo) RemoteInfos ¶
func (r *Repo) RemoteInfos(remote string) RemoteInfos
RemoteInfos get by remote name
func (*Repo) RemoteLines ¶ added in v0.3.3
RemoteLines get like: {origin: url, other: url}
func (*Repo) SearchBranches ¶ added in v0.2.3
func (r *Repo) SearchBranches(name string, flag int) []*BranchInfo
SearchBranches search branch infos by name
func (*Repo) SetUpstreamTo ¶ added in v0.3.2
SetUpstreamTo set the branch upstream remote branch. If `localBranch` is empty, will use `branch` as `localBranch`
CMD:
git branch --set-upstream-to=<remote>/<branch> <local_branch>
func (*Repo) StatusInfo ¶ added in v0.2.7
func (r *Repo) StatusInfo() *StatusInfo
StatusInfo get status info of the repo
func (*Repo) TagByDescribe ¶ added in v0.2.5
TagByDescribe get tag by describe command. if current not empty, will exclude it.
func (*Repo) TagSecondMax ¶
TagSecondMax get second-largest tag of the repo
func (*Repo) TagSecondMaxByTagType ¶ added in v0.2.5
TagSecondMaxByTagType get second-largest tag of the repo by tag_type
func (*Repo) TagsSortedByCreatorDate ¶ added in v0.2.5
TagsSortedByCreatorDate get repo tags list by creator date sort
func (*Repo) TagsSortedByRefName ¶
TagsSortedByRefName get repo tags list
func (*Repo) UpstreamBranch ¶ added in v0.3.2
UpstreamBranch get current upstream branch name.
func (*Repo) UpstreamPath ¶ added in v0.3.2
UpstreamPath get current upstream remote and branch. Returns like: origin/main
CMD:
git rev-parse --abbrev-ref @{u}
func (*Repo) UpstreamRemote ¶ added in v0.3.2
UpstreamRemote get current upstream remote name.
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 ¶
type RepoConfig struct { // DefaultBranch name, default is DefaultBranchName DefaultBranch string // DefaultRemote name, default is DefaultRemoteName DefaultRemote string }
RepoConfig struct
type RepoInfo ¶
type RepoInfo struct { Name string Path string Dir string URL string // LastHash last commit hash value LastHash string Branch string Version string // Upstream remote name Upstream string // Remotes name and url mapping. Remotes map[string]string }
RepoInfo struct
type StatusInfo ¶ added in v0.2.7
type StatusInfo struct { // Branch current branch name. Branch string // UpRemote current upstream remote name. UpRemote string // UpBranch current upstream remote branch name. UpBranch string // Deleted files Deleted []string // Renamed files, contains RM(rename and modify) files Renamed []string // Modified files Modified []string // Unstacked new created files. Unstacked []string // contains filtered or unexported fields }
StatusInfo struct
by run: git status -bs -u
func NewStatusInfo ¶ added in v0.2.7
func NewStatusInfo(str string) *StatusInfo
NewStatusInfo from string.
func (*StatusInfo) FileNum ¶ added in v0.2.7
func (si *StatusInfo) FileNum() int
FileNum in git status
func (*StatusInfo) FromLines ¶ added in v0.2.7
func (si *StatusInfo) FromLines(lines []string) *StatusInfo
FromLines parse and load info
func (*StatusInfo) FromString ¶ added in v0.2.7
func (si *StatusInfo) FromString(str string) *StatusInfo
FromString parse and load info
func (*StatusInfo) IsCleaned ¶ added in v0.2.7
func (si *StatusInfo) IsCleaned() bool
IsCleaned status in workspace