Documentation ¶
Index ¶
- Constants
- func Clone(repoPath string, url string, branch string, depth int) error
- func FetchOrClone(repoPath string, url string, branch string, depth int, tagPattern string, ...) (isNewClone bool, err error)
- func FindGitDirs(searchDir string) (all []string, err error)
- func GetCommitSHA(gitx *Context, ref string) (string, error)
- func GetDefaultTemplateDir() string
- func GetLFSConfigFile(repoDir string) (string, bool)
- func GetTags(gitx *Context, commitSHA string) ([]string, error)
- func GetVersion(gitx *Context, commitSHA string, matchPattern string) (v *version.Version, tag string, err error)
- func GetVersionAt(gitx *Context, commitSHA string) (*version.Version, string, error)
- func IsCloneURLALocalPath(url string) bool
- func IsCloneURLALocalURL(url string) bool
- func IsCloneURLANormalURL(url string) bool
- func IsCloneURLARemoteHelperSyntax(url string) bool
- func IsLFSAvailable() bool
- func IsRefReachable(gitx *Context, startRef string, ref string) (bool, error)
- func ParseRemoteHelperSyntax(url string) []string
- func PullOrClone(repoPath string, url string, branch string, depth int, ...) (isNewClone bool, err error)
- func SanitizeEnv(env []string) []string
- type ConfigScope
- type Context
- func (c *Context) AddConfig(key string, value interface{}, scope ConfigScope) error
- func (c *Context) FetchBranch(remote string, branch string, tagPattern string) error
- func (c *Context) GetAllWorktrees() (list []string, err error)
- func (c *Context) GetCommitLog(commitSHA string, format string) (string, error)
- func (c *Context) GetCommits(firstSHA string, lastSHA string) ([]string, error)
- func (c *Context) GetConfig(key string, scope ConfigScope) string
- func (c *Context) GetConfigAll(key string, scope ConfigScope) []string
- func (c *Context) GetConfigAllU(key string, scope ConfigScope) string
- func (c *Context) GetConfigRegex(regex string, scope ConfigScope) (res [][]string)
- func (c *Context) GetCurrentBranch() (string, error)
- func (c *Context) GetGitDirCommon() (gitDir string, err error)
- func (c *Context) GetGitDirWorktree() (gitDir string, err error)
- func (c *Context) GetMainWorktree() (string, error)
- func (c *Context) GetRemoteURLAndBranch(remote string) (currentURL string, currentBranch string, err error)
- func (c *Context) GetRepoRoot() (topLevel string, gitDir string, gitDirWorktree string, err error)
- func (c *Context) IsBareRepo() bool
- func (c *Context) IsConfigSet(key string, scope ConfigScope) bool
- func (c *Context) IsGitDir() bool
- func (c *Context) IsGitRepo() bool
- func (c *Context) LookupConfig(key string, scope ConfigScope) (string, bool)
- func (c *Context) Pull(remote string) error
- func (c *Context) SetConfig(key string, value interface{}, scope ConfigScope) error
- func (c *Context) UnsetConfig(key string, scope ConfigScope) (err error)
- type RepoCheck
- type ShortSCP
Constants ¶
const ( LocalScope ConfigScope = "--local" GlobalScope ConfigScope = "--global" System ConfigScope = "--system" Traverse ConfigScope = "" HEAD string = "HEAD" )
Available ConfigScope's.
const ( // GitCKInitTemplateDir is the Git template dir config key. GitCKInitTemplateDir = "init.templateDir" // GitCKCoreHooksPath is the Git global hooks path config key. GitCKCoreHooksPath = "core.hooksPath" GitCVTrue = "true" GitCVFalse = "false" )
const (
// NullRef is the null reference used by git during certain hook execution.
NullRef = "0000000000000000000000000000000000000000"
)
Variables ¶
This section is empty.
Functions ¶
func FetchOrClone ¶
func FetchOrClone( repoPath string, url string, branch string, depth int, tagPattern string, repoCheck RepoCheck) (isNewClone bool, err error)
FetchOrClone either executes a fetch in `repoPath` or if not existing, clones to this path. The callback `repoCheck` before a fetch can trigger a reclone.
func FindGitDirs ¶
FindGitDirs returns Git directories inside `searchDir`. Paths relative to `searchDir` containing `.dotfiles` (hidden files) will never be reported. Optionally the output can be sorted.
func GetCommitSHA ¶
GetCommitSHA gets the commit SHA1 of the ref.
func GetDefaultTemplateDir ¶
func GetDefaultTemplateDir() string
GetDefaultTemplateDir gets the default Git template dir.
func GetLFSConfigFile ¶
GetLFSRequiredFile gets the LFS config file inside the repository and `true` if existing.
func GetVersion ¶
func GetVersion(gitx *Context, commitSHA string, matchPattern string) (v *version.Version, tag string, err error)
GetVersion gets the semantic version and its tag.
func GetVersionAt ¶
GetVersionAt gets the version & tag from the tags at `commitSHA`.
func IsCloneURLALocalPath ¶
IsCloneURLALocalPath checks if the clone url is a local path. Thats the case if its not a URL Scheme, not a short SCP syntax and not a remote transport helper syntax. The problem arises on Windows with drive letters, since `C:/a/b` can technically be a short SCP syntax, we require at least 2 letters for the host name.
func IsCloneURLALocalURL ¶
IsCloneURLALocalURL checks if the clone url is a url to a local directory. Thats the case only for `file://`.
func IsCloneURLANormalURL ¶
IsCloneURLANormalURL checks if `url` is a normal url. Containing `<scheme>://` at the beginning.
func IsCloneURLARemoteHelperSyntax ¶
IsRemoteHelperSyntax checks if `url` is a remote helper syntax. https://git-scm.com/docs/gitremote-helpers
func IsLFSAvailable ¶
func IsLFSAvailable() bool
IsLFSAvailable tells if git-lfs is available in the path.
func IsRefReachable ¶
IsRefReachable reports if `ref` (can be branch/tag/commit) is contained starting from `startRef`.
func ParseRemoteHelperSyntax ¶
ParseRemoteHelperSyntax parses the url as a remote helper syntax and reporting the transport and address string if not nil. https://git-scm.com/docs/gitremote-helpers
func PullOrClone ¶
func PullOrClone( repoPath string, url string, branch string, depth int, repoCheck func(*Context) error) (isNewClone bool, err error)
PullOrClone either executes a pull in `repoPath` or if not existing, clones to this path.
func SanitizeEnv ¶
SanitizeEnv santizes the environement from unwanted Git (possibly leaking) Git variables which might interfere with certain buggy Git commands.
Types ¶
type ConfigScope ¶
type ConfigScope string
ConfigScope Defines the scope of a config file, such as local, global or system.
type Context ¶
type Context struct {
cm.CmdContext
}
Context defines the context to execute it commands.
func Ctx ¶
func Ctx() *Context
Ctx creates a git command execution context with current working dir.
func CtxCSanitized ¶
CtxCSanitized creates a git command execution context with working dir `cwd` and sanitized environement.
func CtxSanitized ¶
func CtxSanitized() *Context
CtxSanitized creates a git command execution context with current working dir and sanitized environement.
func (*Context) AddConfig ¶
func (c *Context) AddConfig(key string, value interface{}, scope ConfigScope) error
AddConfig adds a Git configuration values with key `key`.
func (*Context) FetchBranch ¶
FetchBranch executes a fetch of a `branch` from the `remote` in `repoPath`. This command sadly does not automatically (git 2.30) fetch the tags on this branch automatically. Use `tagPattern` to specify explicitly which tags to fetch.
func (*Context) GetAllWorktrees ¶
GetAllWorktrees returns all worktrees based on the current context's working directory.
func (*Context) GetCommitLog ¶
GetCommitLog gets all commits in the ancestry path starting from `firstSHA` (excluded in the result) up to and including `lastSHA`.
func (*Context) GetCommits ¶
GetCommits gets all commits in the ancestry path starting from `firstSHA` (excluded in the result) up to and including `lastSHA`.
func (*Context) GetConfig ¶
func (c *Context) GetConfig(key string, scope ConfigScope) string
GetConfig gets a Git configuration value for key `key`.
func (*Context) GetConfigAll ¶
func (c *Context) GetConfigAll(key string, scope ConfigScope) []string
GetConfigAll gets a all Git configuration values for key `key`.
func (*Context) GetConfigAllU ¶
func (c *Context) GetConfigAllU(key string, scope ConfigScope) string
GetConfigAllU gets a all Git configuration values unsplitted for key `key`.
func (*Context) GetConfigRegex ¶
func (c *Context) GetConfigRegex(regex string, scope ConfigScope) (res [][]string)
GetConfigRegex gets all Git configuration values for regex `regex`. Returns a list of pairs.
func (*Context) GetCurrentBranch ¶
GetCurrentBranch gets the current branch in repository.
func (*Context) GetGitDirCommon ¶
GetGitDirCommon returns the common Git directory. For normal repos this points to the `.git` directory. For worktrees this points to the main worktrees git dir. The env. variable GIT_COMMON_DIR has especiall be introduced for multiple worktrees, see: https://github.com/git/git/commit/c7b3a3d2fe2688a30ddb8d516ed000eeda13c24e
func (*Context) GetGitDirWorktree ¶
GetGitDirWorktree returns the Git directory. For normal repos this points to the `.git` directory. For worktrees this points to the actual worktrees git dir `.git/worktrees/<....>/`.
func (*Context) GetMainWorktree ¶
GetMainWorktree returns the main worktree based on the current context's working directory.
func (*Context) GetRemoteURLAndBranch ¶
func (c *Context) GetRemoteURLAndBranch(remote string) (currentURL string, currentBranch string, err error)
GetRemoteURLAndBranch reports the `remote`s `url` and the current `branch` of HEAD.
func (*Context) GetRepoRoot ¶
GetRepoRoot returns the top level directory in a non-bare repository or the absolute Git directory in a bare repository for `topLevel`. This is the root level for Githooks. The `gitDir` is the common Git directory (main Git dir for worktrees).
func (*Context) IsBareRepo ¶
IsBareRepo returns `true` if `c.Cwd` is a bare repository.
func (*Context) IsConfigSet ¶
func (c *Context) IsConfigSet(key string, scope ConfigScope) bool
IsConfigSet tells if a git config is set.
func (*Context) IsGitDir ¶
IsGitDir returns `true` if `c.Cwd` is a git repository (bare or non-bare).
func (*Context) IsGitRepo ¶
IsGitRepo returns `true` if `path` is a git repository (bare or non-bare).
func (*Context) LookupConfig ¶
func (c *Context) LookupConfig(key string, scope ConfigScope) (string, bool)
LookupConfig gets a Git configuration value and reports if it exists or not.
func (*Context) SetConfig ¶
func (c *Context) SetConfig(key string, value interface{}, scope ConfigScope) error
SetConfig sets a Git configuration values with key `key`.
func (*Context) UnsetConfig ¶
func (c *Context) UnsetConfig(key string, scope ConfigScope) (err error)
UnsetConfig unsets all Git configuration values with key `key`.
type RepoCheck ¶
RepoCheck is the function which is executed before a fetch. Arguments 1 and 2 are `url`, `branch`. Return an error to abort the action. Return `true` to trigger a complete reclone. Available ConfigScope's.
type ShortSCP ¶
type ShortSCP []string
ShortSCP represents a short SCP syntax and corresponds to regex `reShortSCPSyntax`.
func ParseSCPSyntax ¶
ParseSCPSyntax parses the url as a short SCP syntax and reporting the user, host and path if not nil.