Documentation
¶
Index ¶
- Constants
- Variables
- func BinVersion() (string, error)
- func Clone(url, dst string, opts ...CloneOptions) error
- func ExecCommandString(dir, name, cmd string) (string, error)
- func Init(path string, opts ...InitOptions) error
- func RepoAdd(repoPath string, opts ...AddOptions) error
- func RepoCheckout(repoPath, branch string, opts ...CheckoutOptions) error
- func RepoFsck(repoPath string, opts ...FsckOptions) error
- func RepoMove(repoPath, src, dst string, opts ...MoveOptions) error
- func RepoPush(repoPath, remote, branch string, opts ...PushOptions) error
- func RepoReset(repoPath, rev string, opts ...ResetOptions) error
- func SetOutput(output io.Writer)
- func SetPrefix(prefix string)
- type AddOptions
- type CheckoutOptions
- type CloneOptions
- type Command
- func (c *Command) AddArgs(args ...string) *Command
- func (c *Command) AddEnvs(envs ...string) *Command
- func (c *Command) Run() ([]byte, error)
- func (c *Command) RunCmd(dir string) (string, error)
- func (c *Command) RunInDir(dir string) ([]byte, error)
- func (c *Command) RunInDirPipeline(stdout, stderr io.Writer, dir string) error
- func (c *Command) RunInDirPipelineWithTimeout(timeout time.Duration, stdout, stderr io.Writer, dir string) (err error)
- func (c *Command) RunInDirWithTimeout(timeout time.Duration, dir string) ([]byte, error)
- func (c *Command) RunWithTimeout(timeout time.Duration) ([]byte, error)
- func (c *Command) String() string
- type CountObject
- type CountObjectsOptions
- type Entry
- type FetchOptions
- type FsckOptions
- type InitOptions
- type MoveOptions
- type NameStatus
- type ObjectType
- type PullOptions
- type PushOptions
- type Repository
- func (r *Repository) Add(opts ...AddOptions) error
- func (r *Repository) Checkout(branch string, opts ...CheckoutOptions) error
- func (r *Repository) CountObjects(opts ...CountObjectsOptions) (*CountObject, error)
- func (r *Repository) Fetch(opts ...FetchOptions) error
- func (r *Repository) Fsck(opts ...FsckOptions) error
- func (r *Repository) Move(src, dst string, opts ...MoveOptions) error
- func (r *Repository) Pull(opts ...PullOptions) error
- func (r *Repository) Push(remote, branch string, opts ...PushOptions) error
- func (r *Repository) Reset(rev string, opts ...ResetOptions) error
- func (r *Repository) RevParse(rev string, opts ...RevParseOptions) (string, error)
- func (r *Repository) ShowNameStatus(rev string, opts ...ShowNameStatusOptions) (*NameStatus, error)
- func (r *Repository) String() string
- type ResetOptions
- type RevParseOptions
- type ShowNameStatusOptions
- type Tree
Constants ¶
const DefaultTimeout = time.Minute
DefaultTimeout is the default timeout duration for all commands.
const LogFormatHashOnly = `format:%H`
Variables ¶
var ( ErrParentNotExist = errors.New("parent does not exist") ErrSubmoduleNotExist = errors.New("submodule does not exist") ErrRevisionNotExist = errors.New("revision does not exist") ErrRemoteNotExist = errors.New("remote does not exist") ErrExecTimeout = errors.New("execution was timed out") ErrNoMergeBase = errors.New("no merge based was found") ErrNotBlob = errors.New("the entry is not a blob") )
Functions ¶
func BinVersion ¶
BinVersion returns current Git binary version that is used by this module.
func Clone ¶
func Clone(url, dst string, opts ...CloneOptions) error
Clone clones the repository from remote URL to the destination.
func ExecCommandString ¶
func Init ¶
func Init(path string, opts ...InitOptions) error
Init initializes a new Git repository.
func RepoAdd ¶
func RepoAdd(repoPath string, opts ...AddOptions) error
RepoAdd adds local changes to index for the repository in given path.
func RepoCheckout ¶
func RepoCheckout(repoPath, branch string, opts ...CheckoutOptions) error
Checkout checks out to given branch for the repository in given path.
func RepoFsck ¶
func RepoFsck(repoPath string, opts ...FsckOptions) error
RepoFsck verifies the connectivity and validity of the objects in the database for the repository in given path.
func RepoMove ¶
func RepoMove(repoPath, src, dst string, opts ...MoveOptions) error
RepoMove moves a file, a directory, or a symlink file or directory from source to destination for the repository in given path.
func RepoPush ¶
func RepoPush(repoPath, remote, branch string, opts ...PushOptions) error
RepoPush pushs local changes to given remote and branch for the repository in given path.
func RepoReset ¶
func RepoReset(repoPath, rev string, opts ...ResetOptions) error
RepoReset resets working tree to given revision for the repository in given path.
Types ¶
type AddOptions ¶
type AddOptions struct { // Indicates whether to add all changes to index. All bool // The specific pathspecs to be added to index. Pathsepcs []string // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
AddOptions contains optional arguments for adding local changes. Docs: https://git-scm.com/docs/git-add
type CheckoutOptions ¶
type CheckoutOptions struct { // The base branch if checks out to a new branch. BaseBranch string // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
CheckoutOptions contains optional arguments for checking out to a branch. Docs: https://git-scm.com/docs/git-checkout
type CloneOptions ¶
type CloneOptions struct { // Indicates whether the repository should be cloned as a mirror. Mirror bool // Indicates whether the repository should be cloned in bare format. Bare bool // Indicates whether to suppress the log output. Quiet bool // The branch to checkout for the working tree when Bare=false. Branch string // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
CloneOptions contains optional arguments for cloning a repository. Docs: https://git-scm.com/docs/git-clone
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command contains the name, arguments and environment variables of a command.
func NewCommand ¶
NewCommand creates and returns a new Command with given arguments for "git".
func (*Command) Run ¶
Run executes the command in working directory and default timeout duration. It returns stdout in string and error (combined with stderr).
func (*Command) RunInDir ¶
RunInDir executes the command in given directory and default timeout duration. It returns stdout and error (combined with stderr).
func (*Command) RunInDirPipeline ¶
RunInDirPipeline executes the command in given directory and default timeout duration. It pipes stdout and stderr to supplied io.Writer.
func (*Command) RunInDirPipelineWithTimeout ¶
func (c *Command) RunInDirPipelineWithTimeout(timeout time.Duration, stdout, stderr io.Writer, dir string) (err error)
RunInDirPipelineWithTimeout executes the command in given directory and timeout duration. It pipes stdout and stderr to supplied io.Writer. DefaultTimeout will be used if the timeout duration is less than time.Nanosecond (i.e. less than or equal to 0). It returns an ErrExecTimeout if the execution was timed out.
func (*Command) RunInDirWithTimeout ¶
RunInDirWithTimeout executes the command in given directory and timeout duration. It returns stdout in []byte and error (combined with stderr).
func (*Command) RunWithTimeout ¶
RunWithTimeout executes the command in working directory and given timeout duration. It returns stdout in string and error (combined with stderr).
type CountObject ¶
type CountObject struct { Count int64 Size int64 InPack int64 Packs int64 SizePack int64 PrunePackable int64 Garbage int64 SizeGarbage int64 }
CountObject contains disk usage report of a repository.
func RepoCountObjects ¶
func RepoCountObjects(repoPath string, opts ...CountObjectsOptions) (*CountObject, error)
RepoCountObjects returns disk usage report of the repository in given path.
type CountObjectsOptions ¶
type CountObjectsOptions struct { // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
CountObjectsOptions contains optional arguments for counting objects. Docs: https://git-scm.com/docs/git-count-objects
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
func NewEntry ¶
git ls-tree -l --full-tree HEAD cmd/|while read filename;do echo "$filename $(git log -1 --format="|%h|%s|%cr|%ai|%an" -- `echo $filename|awk '{print $5}'`)" ;done 100644 blob 206c042ada4cb14d8f068c364b4b623a45038425 1799 cmd/bolt.go |c25d9ea|boltapi|10 months ago|2020-03-20 19:17:37 +0800|yckj0834 100644|blob|8923a8f720912df0810262bfbe74a0ee65f07d1d|3496|cmd/tty.go |c9e64fd|remove local tty|9 months ago|2020-04-08 03:30:17 +0800|yckj0834
type FetchOptions ¶
type FetchOptions struct { // Indicates whether to prune during fetching. Prune bool // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
FetchOptions contains optional arguments for fetching repository updates. Docs: https://git-scm.com/docs/git-fetch
type FsckOptions ¶
type FsckOptions struct { // The additional arguments to be applied. Args []string // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
FsckOptions contains optional arguments for verifying the objects. Docs: https://git-scm.com/docs/git-fsck
type InitOptions ¶
type InitOptions struct { // Indicates whether the repository should be initialized in bare format. Bare bool // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
InitOptions contains optional arguments for initializing a repository. Docs: https://git-scm.com/docs/git-init
type MoveOptions ¶
type MoveOptions struct { // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
MoveOptions contains optional arguments for moving a file, a directory, or a symlink. Docs: https://git-scm.com/docs/git-mv
type NameStatus ¶
NameStatus contains name status of a commit.
func RepoShowNameStatus ¶
func RepoShowNameStatus(repoPath, rev string, opts ...ShowNameStatusOptions) (*NameStatus, error)
RepoShowNameStatus returns name status of given revision of the repository in given path.
type ObjectType ¶
type ObjectType string
ObjectType is the type of a Git objet.
const ( ObjectCommit ObjectType = "commit" ObjectTree ObjectType = "tree" ObjectBlob ObjectType = "blob" ObjectTag ObjectType = "tag" )
A list of object types.
type PullOptions ¶
type PullOptions struct { // Indicates whether to rebased during pulling. Rebase bool // Indicates whether to pull from all remotes. All bool // The remote to pull updates from when All=false. Remote string // The branch to pull updates from when All=false and Remote is supplied. Branch string // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
PullOptions contains optional arguments for pulling repository updates. Docs: https://git-scm.com/docs/git-pull
type PushOptions ¶
type PushOptions struct { // The environment variables set for the push. Envs []string // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
PushOptions contains optional arguments for pushing repository changes. Docs: https://git-scm.com/docs/git-push
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
func Open ¶
func Open(repoPath string) (*Repository, error)
Open opens the repository at the given path. It returns an os.ErrNotExist if the path does not exist.
func (*Repository) Add ¶
func (r *Repository) Add(opts ...AddOptions) error
Add adds local changes to index for the repository.
func (*Repository) Checkout ¶
func (r *Repository) Checkout(branch string, opts ...CheckoutOptions) error
Checkout checks out to given branch for the repository.
func (*Repository) CountObjects ¶
func (r *Repository) CountObjects(opts ...CountObjectsOptions) (*CountObject, error)
CountObjects returns disk usage report of the repository.
func (*Repository) Fetch ¶
func (r *Repository) Fetch(opts ...FetchOptions) error
Fetch fetches updates for the repository.
func (*Repository) Fsck ¶
func (r *Repository) Fsck(opts ...FsckOptions) error
Fsck verifies the connectivity and validity of the objects in the database for the repository.
func (*Repository) Move ¶
func (r *Repository) Move(src, dst string, opts ...MoveOptions) error
Move moves a file, a directory, or a symlink file or directory from source to destination for the repository.
func (*Repository) Pull ¶
func (r *Repository) Pull(opts ...PullOptions) error
Pull pulls updates for the repository.
func (*Repository) Push ¶
func (r *Repository) Push(remote, branch string, opts ...PushOptions) error
Push pushs local changes to given remote and branch for the repository.
func (*Repository) Reset ¶
func (r *Repository) Reset(rev string, opts ...ResetOptions) error
Reset resets working tree to given revision for the repository.
func (*Repository) RevParse ¶
func (r *Repository) RevParse(rev string, opts ...RevParseOptions) (string, error)
RevParse returns full length (40) commit ID by given revision in the repository.
func (*Repository) ShowNameStatus ¶
func (r *Repository) ShowNameStatus(rev string, opts ...ShowNameStatusOptions) (*NameStatus, error)
ShowNameStatus returns name status of given revision of the repository.
func (*Repository) String ¶
func (r *Repository) String() string
type ResetOptions ¶
type ResetOptions struct { // Indicates whether to perform a hard reset. Hard bool // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
ResetOptions contains optional arguments for resetting a branch. Docs: https://git-scm.com/docs/git-reset
type RevParseOptions ¶
type RevParseOptions struct { // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
RevParseOptions contains optional arguments for parsing revision. Docs: https://git-scm.com/docs/git-rev-parse
type ShowNameStatusOptions ¶
type ShowNameStatusOptions struct { // The timeout duration before giving up for each shell command execution. // The default timeout duration will be used when not supplied. Timeout time.Duration }
ShowNameStatusOptions contains optional arguments for showing name status. Docs: https://git-scm.com/docs/git-show#Documentation/git-show.txt---name-status