git

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package git Main package of the git commands.

Reference: https://git-scm.com/docs/

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add added in v0.17.0

func Add(options ...types.Option) (string, error)

Add https://git-scm.com/docs/git-add

Example
out, _ := Add(add.All, CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git add --all

func Branch added in v0.6.0

func Branch(options ...types.Option) (string, error)

Branch https://git-scm.com/docs/git-branch

Example
out, _ := Branch(branch.DeleteForce, branch.BranchName("myBranch"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git branch -D myBranch

func Checkout

func Checkout(options ...types.Option) (string, error)

Checkout https://git-scm.com/docs/git-checkout

Example
out, _ := Checkout(checkout.NewBranch("myBranchName"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git checkout -b myBranchName

func Clone

func Clone(options ...types.Option) (string, error)

Clone https://git-scm.com/docs/git-clone

Example
out, _ := Clone(clone.Repository("git@github.com:ldez/go-git-cmd-wrapper.git"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git clone git@github.com:ldez/go-git-cmd-wrapper.git

func CmdExecutor added in v0.22.0

func CmdExecutor(executor types.Executor) types.Option

CmdExecutor Allow to override the Git command call (useful for testing purpose)

func Commit added in v0.16.0

func Commit(options ...types.Option) (string, error)

Commit https://git-scm.com/docs/git-commit

Example
out, _ := Commit(commit.Amend, commit.Message("chore: foo"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git commit --amend --message="chore: foo"

func Cond

func Cond(apply bool, options ...types.Option) types.Option

Cond apply conditionally some options

Example
param := false
out, _ := Push(push.All, Cond(param, push.DryRun), push.FollowTags, push.ReceivePack("aaa"), CmdExecutor(cmdExecutorMock))

fmt.Print(out)

param = true
out, _ = Push(push.All, Cond(param, push.DryRun), push.FollowTags, push.ReceivePack("aaa"), CmdExecutor(cmdExecutorMock))

fmt.Print(out)
Output:

git push --all --follow-tags --receive-pack=aaa
git push --all --dry-run --follow-tags --receive-pack=aaa

func Config

func Config(options ...types.Option) (string, error)

Config https://git-scm.com/docs/git-config

Example
out, _ := Config(config.Entry("rebase.autoSquash", "true"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git config rebase.autoSquash true

func Debug

func Debug(g *types.Cmd)

Debug display command line

func Debugger added in v0.4.1

func Debugger(debug bool) types.Option

Debugger display command line

func Fetch

func Fetch(options ...types.Option) (string, error)

Fetch https://git-scm.com/docs/git-fetch

Example
out, _ := Fetch(fetch.NoTags, fetch.Remote("upstream"), fetch.RefSpec("myBranchName"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git fetch --no-tags upstream myBranchName

func Init

func Init(options ...types.Option) (string, error)

Init https://git-scm.com/docs/git-init

Example
out, _ := Init(ginit.Bare, ginit.Quiet, ginit.Directory("foobar"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git init --bare --quiet foobar

func LogOutput added in v1.0.0

func LogOutput(w io.Writer) types.Option

LogOutput Writer used by the internal logger.

func Merge added in v0.18.0

func Merge(options ...types.Option) (string, error)

Merge https://git-scm.com/docs/git-merge

Example
out, _ := Merge(merge.Squash, merge.Commits("myBranch"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git merge --squash myBranch

func NoOp

func NoOp(_ *types.Cmd)

NoOp do nothing.

func Pull added in v0.11.0

func Pull(options ...types.Option) (string, error)

Pull https://git-scm.com/docs/git-pull

Example
out, _ := Pull(pull.All, pull.Force, pull.Repository("upstream"), pull.Refspec("master"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git pull --all --force upstream master

func Push

func Push(options ...types.Option) (string, error)

Push https://git-scm.com/docs/git-push

Example
out, _ := Push(push.All, push.FollowTags, push.ReceivePack("aaa"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git push --all --follow-tags --receive-pack=aaa

func Raw added in v0.9.0

func Raw(cmd string, options ...types.Option) (string, error)

Raw use to execute arbitrary commands.

func Rebase

func Rebase(options ...types.Option) (string, error)

Rebase https://git-scm.com/docs/git-rebase

Example
out, _ := Rebase(rebase.PreserveMerges, rebase.Branch(fmt.Sprintf("%s/%s", "upstream", "master")), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git rebase --preserve-merges upstream/master

func Remote

func Remote(options ...types.Option) (string, error)

Remote https://git-scm.com/docs/git-remote

Example
out, _ := Remote(remote.Add("upstream", "git@github.com:johndoe/go-git-cmd-wrapper.git"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git remote add upstream git@github.com:johndoe/go-git-cmd-wrapper.git

func Reset added in v0.16.0

func Reset(options ...types.Option) (string, error)

Reset https://git-scm.com/docs/git-reset

Example
out, _ := Reset(reset.Soft, reset.Commit("e41f083"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git reset --soft e41f083

func RevParse added in v0.9.0

func RevParse(options ...types.Option) (string, error)

RevParse https://git-scm.com/docs/git-rev-parse

Example
out, _ := RevParse(revparse.AbbrevRef(""), revparse.Args("HEAD"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git rev-parse --abbrev-ref HEAD

func Tag added in v1.1.0

func Tag(options ...types.Option) (string, error)

Tag https://git-scm.com/docs/git-tag

Example
out, _ := Tag(tag.List, CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git tag --list

func Worktree added in v0.21.0

func Worktree(options ...types.Option) (string, error)

Worktree https://git-scm.com/docs/git-worktree

Example
out, _ := Worktree(worktree.Add("v1.0", "origin/v1.0"), CmdExecutor(cmdExecutorMock))

fmt.Println(out)
Output:

git worktree add v1.0 origin/v1.0

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL