xgit

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

README

Go Git Cmd Wrapper

It's a simple wrapper around git command.

Import github.com/kumose-go/xgit.

// clone
output, err := xgit.Clone(clone.Repository("https://github.com/ldez/prm"))
// with debug option
output, err := xgit.Clone(clone.Repository("https://github.com/ldez/prm"), xgit.Debug)
output, err := xgit.Clone(clone.Repository("https://github.com/ldez/prm"), xgit.Debugger(true))

// fetch
output, err = xgit.Fetch(fetch.NoTags, fetch.Remote("upstream"))
output, err = xgit.Fetch(fetch.NoTags, fetch.Remote("upstream"), fetch.RefSpec("master"))

// add a remote
output, err = xgit.Remote(remote.Add, remote.Name("upstream"), remote.URL("https://github.com/ldez/prm"))

// --- global options ---
output, err := xgit.Clone(global.UpperC("/tmp"), clone.Repository("https://github.com/ldez/prm"))

More examples: Documentation

Documentation

Overview

Package git Main package of the git commands.

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

Package xgit A simple wrapper around `git` command.

import (
	// ...
	"github.com/kumose-go/xgit"
	// ...
	"github.com/kumose-go/xgit/clone"
	"github.com/kumose-go/xgit/config"
	"github.com/kumose-go/xgit/fetch"
	"github.com/kumose-go/xgit/remote"
)

// clone
output, err := xgit.Clone(clone.Repository("https://github.com/ldez/gcg"))
// with debug option
output, err := xgit.Clone(clone.Repository("https://github.com/ldez/gcg"), xgit.Debug)
output, err := xgit.Clone(clone.Repository("https://github.com/ldez/gcg"), xgit.Debugger(true))

// fetch
output, err = xgit.Fetch(fetch.NoTags, fetch.Remote("upstream"))
output, err = xgit.Fetch(fetch.NoTags, fetch.Remote("upstream"), fetch.RefSpec("master"))

// add a remote
output, err = xgit.Remote(remote.Add, remote.Name("upstream"), remote.URL("https://github.com/ldez/gcg"))

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

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

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/add"
)

func main() {
	out, _ := xgit.Add(add.All, xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git add --all

func AddWithContext

func AddWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/add"
)

func main() {
	out, _ := xgit.AddWithContext(context.Background(), add.All, xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git add --all

func Branch

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

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/branch"
)

func main() {
	out, _ := xgit.Branch(branch.DeleteForce, branch.BranchName("myBranch"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git branch -D myBranch

func BranchWithContext

func BranchWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/branch"
)

func main() {
	out, _ := xgit.BranchWithContext(context.Background(), branch.DeleteForce, branch.BranchName("myBranch"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git branch -D myBranch

func Checkout

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

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/checkout"
)

func main() {
	out, _ := xgit.Checkout(checkout.NewBranch("myBranchName"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git checkout -b myBranchName

func CheckoutWithContext

func CheckoutWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/checkout"
)

func main() {
	out, _ := xgit.CheckoutWithContext(context.Background(), checkout.NewBranch("myBranchName"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git checkout -b myBranchName

func Clone

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

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/clone"
)

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

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

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

func CloneWithContext

func CloneWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/clone"
)

func main() {
	out, _ := xgit.CloneWithContext(context.Background(), clone.Repository("git@github.com:ldez/go-git-cmd-wrapper.git"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

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

func CmdExecutor

func CmdExecutor(executor types.Executor) types.Option

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

func Commit

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

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/commit"
)

func main() {
	out, _ := xgit.Commit(commit.Amend, commit.Message("foo"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git commit --amend --message=foo

func CommitWithContext

func CommitWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/commit"
)

func main() {
	out, _ := xgit.CommitWithContext(context.Background(), commit.Amend, commit.Message("foo"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git commit --amend --message=foo

func Cond

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

Cond apply conditionally some options.

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/push"
)

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

	fmt.Print(out)

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

	fmt.Print(out)

}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
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
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/config"
)

func main() {
	out, _ := xgit.Config(config.Entry("rebase.autoSquash", "true"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git config rebase.autoSquash true

func ConfigWithContext

func ConfigWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/config"
)

func main() {
	out, _ := xgit.ConfigWithContext(context.Background(), config.Entry("rebase.autoSquash", "true"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git config rebase.autoSquash true

func Debug

func Debug(g *types.Cmd)

Debug display command line.

func Debugger

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
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/fetch"
)

func main() {
	out, _ := xgit.Fetch(fetch.NoTags, fetch.Remote("upstream"), fetch.RefSpec("myBranchName"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git fetch --no-tags upstream myBranchName

func FetchWithContext

func FetchWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/fetch"
)

func main() {
	out, _ := xgit.FetchWithContext(context.Background(), fetch.NoTags, fetch.Remote("upstream"), fetch.RefSpec("myBranchName"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
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
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"

	ginit "github.com/kumose-go/xgit/init"
)

func main() {
	out, _ := xgit.Init(ginit.Bare, ginit.Quiet, ginit.Directory("foobar"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git init --bare --quiet foobar

func InitWithContext

func InitWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"

	ginit "github.com/kumose-go/xgit/init"
)

func main() {
	out, _ := xgit.InitWithContext(context.Background(), ginit.Bare, ginit.Quiet, ginit.Directory("foobar"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git init --bare --quiet foobar

func LogOutput

func LogOutput(w io.Writer) types.Option

LogOutput Writer used by the internal logger.

func LsFiles

func LsFiles(subCommand ...types.Option) (string, error)

LsFiles https://git-scm.com/docs/git-ls-files

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/lsfiles"
)

func main() {
	out, _ := xgit.LsFiles(lsfiles.Z, lsfiles.ExcludeStandard, lsfiles.Others, lsfiles.Cached, xgit.CmdExecutor(cmdExecutorMock))

	// Notes: to parse the output you can use `fmt.Println(strings.Split(out, "\x00"))`

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git ls-files -z --exclude-standard --others --cached

func LsFilesWithContext

func LsFilesWithContext(ctx context.Context, subCommand ...types.Option) (string, error)

LsFilesWithContext https://git-scm.com/docs/git-ls-files

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/lsfiles"
)

func main() {
	out, _ := xgit.LsFilesWithContext(context.Background(), lsfiles.Z, lsfiles.ExcludeStandard, lsfiles.Others, lsfiles.Cached, xgit.CmdExecutor(cmdExecutorMock))

	// Notes: to parse the output you can use `fmt.Println(strings.Split(out, "\x00"))`

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git ls-files -z --exclude-standard --others --cached

func Merge

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

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/merge"
)

func main() {
	out, _ := xgit.Merge(merge.Squash, merge.Commits("myBranch"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git merge --squash myBranch

func MergeWithContext

func MergeWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/merge"
)

func main() {
	out, _ := xgit.MergeWithContext(context.Background(), merge.Squash, merge.Commits("myBranch"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git merge --squash myBranch

func NoOp

func NoOp(_ *types.Cmd)

NoOp do nothing.

func Notes

func Notes(subCommand ...types.Option) (string, error)

Notes https://git-scm.com/docs/git-notes

Example (Add)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.Notes(notes.Add("", notes.Message("foo")), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes add --message=foo
Example (Append)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.Notes(notes.Append("", notes.Message("foo")), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes append --message=foo
Example (Copy)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.Notes(notes.Copy(notes.Object("cb17b52c17fb36a807f135245725dee88603cc08", "c9718bfd46a7261d1120ac2e50ef6b298bb2394a")), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes copy cb17b52c17fb36a807f135245725dee88603cc08 c9718bfd46a7261d1120ac2e50ef6b298bb2394a
Example (Edit)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.Notes(notes.Edit("", notes.Message("foo")), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes edit --message=foo
Example (GetRef)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.Notes(notes.GetRef(), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes get-ref
Example (List)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.Notes(notes.List(""), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes list
Example (List_ref)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.Notes(notes.Ref("c9718bfd46a7261d1120ac2e50ef6b298bb2394a"), notes.List(""), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes --ref c9718bfd46a7261d1120ac2e50ef6b298bb2394a list
Example (Merge)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.Notes(notes.Merge(notes.Commit, notes.NotesRef("cb17b52c17fb36a807f135245725dee88603cc08")), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes merge --commit cb17b52c17fb36a807f135245725dee88603cc08
Example (Prune)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.Notes(notes.Prune(notes.Verbose), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes prune --verbose
Example (Remove)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.Notes(notes.Remove("", notes.Stdin), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes remove --stdin
Example (Show)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.Notes(notes.Show(""), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes show

func NotesWithContext

func NotesWithContext(ctx context.Context, subCommand ...types.Option) (string, error)

NotesWithContext https://git-scm.com/docs/git-notes

Example (Add)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.NotesWithContext(context.Background(), notes.Add("", notes.Message("foo")), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes add --message=foo
Example (Append)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.NotesWithContext(context.Background(), notes.Append("", notes.Message("foo")), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes append --message=foo
Example (Copy)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.NotesWithContext(context.Background(), notes.Copy(notes.Stdin), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes copy --stdin
Example (Edit)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.NotesWithContext(context.Background(), notes.Edit("", notes.Message("foo")), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes edit --message=foo
Example (GetRef)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.NotesWithContext(context.Background(), notes.GetRef(), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes get-ref
Example (List)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.NotesWithContext(context.Background(), notes.List(""), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes list
Example (List_ref)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.Notes(notes.Ref("c9718bfd46a7261d1120ac2e50ef6b298bb2394a"), notes.List(""), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes --ref c9718bfd46a7261d1120ac2e50ef6b298bb2394a list
Example (Merge)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.NotesWithContext(context.Background(), notes.Merge(notes.Commit), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes merge --commit
Example (Prune)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.NotesWithContext(context.Background(), notes.Prune(notes.Verbose), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes prune --verbose
Example (Remove)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.NotesWithContext(context.Background(), notes.Remove("", notes.Stdin), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes remove --stdin
Example (Show)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/notes"
)

func main() {
	out, _ := xgit.NotesWithContext(context.Background(), notes.Show(""), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git notes show

func Pull

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

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/pull"
)

func main() {
	out, _ := xgit.Pull(pull.All, pull.Force, pull.Repository("upstream"), pull.Refspec("master"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git pull --all --force upstream master

func PullWithContext

func PullWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/pull"
)

func main() {
	out, _ := xgit.PullWithContext(context.Background(), pull.All, pull.Force, pull.Repository("upstream"), pull.Refspec("master"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
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
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/push"
)

func main() {
	out, _ := xgit.Push(push.All, push.FollowTags, push.ReceivePack("aaa"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

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

func PushWithContext

func PushWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/push"
)

func main() {
	out, _ := xgit.PushWithContext(context.Background(), push.All, push.FollowTags, push.ReceivePack("aaa"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

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

func Raw

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

Raw use to execute arbitrary git commands.

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/types"
)

func main() {
	out, _ := xgit.Raw("stash", xgit.CmdExecutor(cmdExecutorMock), func(g *types.Cmd) {
		g.AddOptions("list")
		g.AddOptions("--pretty=format:'%Cblue%gd%Creset%Cred:%Creset %C(yellow)%s%Creset'")
	})

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash list --pretty=format:'%Cblue%gd%Creset%Cred:%Creset %C(yellow)%s%Creset'

func RawWithContext

func RawWithContext(ctx context.Context, cmd string, options ...types.Option) (string, error)

RawWithContext use to execute arbitrary git commands.

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/types"
)

func main() {
	out, _ := xgit.RawWithContext(context.Background(), "stash", xgit.CmdExecutor(cmdExecutorMock), func(g *types.Cmd) {
		g.AddOptions("list")
		g.AddOptions("--pretty=format:'%Cblue%gd%Creset%Cred:%Creset %C(yellow)%s%Creset'")
	})

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash list --pretty=format:'%Cblue%gd%Creset%Cred:%Creset %C(yellow)%s%Creset'
Example (BaseOptions)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/types"
)

func main() {
	out, _ := xgit.RawWithContext(
		context.Background(),
		"stash",
		func(g *types.Cmd) {
			g.AddOptions("list")
			g.AddOptions("--pretty=format:'%Cblue%gd%Creset%Cred:%Creset %C(yellow)%s%Creset'")
		},
		func(g *types.Cmd) {
			g.AddBaseOptions("-C")
			g.AddBaseOptions("<your_path>")
		},
		xgit.CmdExecutor(cmdExecutorMock),
	)

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git -C <your_path> stash list --pretty=format:'%Cblue%gd%Creset%Cred:%Creset %C(yellow)%s%Creset'

func Rebase

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

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/rebase"
)

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

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git rebase --preserve-merges upstream/master

func RebaseWithContext

func RebaseWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/rebase"
)

func main() {
	out, _ := xgit.RebaseWithContext(context.Background(), rebase.PreserveMerges, rebase.Branch(fmt.Sprintf("%s/%s", "upstream", "master")), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
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
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/remote"
)

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

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

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

func RemoteWithContext

func RemoteWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/remote"
)

func main() {
	out, _ := xgit.RemoteWithContext(context.Background(), remote.Add("upstream", "git@github.com:johndoe/go-git-cmd-wrapper.git"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

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

func Reset

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

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/reset"
)

func main() {
	out, _ := xgit.Reset(reset.Soft, reset.Commit("e41f083"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git reset --soft e41f083

func ResetWithContext

func ResetWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/reset"
)

func main() {
	out, _ := xgit.ResetWithContext(context.Background(), reset.Soft, reset.Commit("e41f083"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git reset --soft e41f083

func RevParse

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

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/revparse"
)

func main() {
	out, _ := xgit.RevParse(revparse.AbbrevRef(""), revparse.Args("HEAD"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git rev-parse --abbrev-ref HEAD

func RevParseWithContext

func RevParseWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/revparse"
)

func main() {
	out, _ := xgit.RevParseWithContext(context.Background(), revparse.AbbrevRef(""), revparse.Args("HEAD"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git rev-parse --abbrev-ref HEAD

func Stash

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

Stash https://git-scm.com/docs/git-stash

Example (Apply)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.Stash(stash.Apply("stash@{1}", stash.Quiet), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash apply --quiet stash@{1}
Example (Branch)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.Stash(stash.Branch("foo", "stash@{1}"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash branch foo stash@{1}
Example (Clear)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.Stash(stash.Clear(), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash clear
Example (Create)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.Stash(stash.Create(), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash create
Example (Drop)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.Stash(stash.Drop("stash@{1}", stash.Quiet), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash drop --quiet stash@{1}
Example (List)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.Stash(stash.List(), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash list
Example (Pop)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.Stash(stash.Pop("stash@{1}", stash.Quiet), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash pop --quiet stash@{1}
Example (Push)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.Stash(stash.Push("foo", stash.All), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash push --all foo
Example (Save)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.Stash(stash.Save("foo", stash.Patch), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash save --patch foo
Example (Show)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.Stash(stash.Show("stash@{1}", stash.IncludeUntracked), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash show --include-untracked stash@{1}
Example (Store)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.Stash(stash.Store(), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash store

func StashWithContext

func StashWithContext(ctx context.Context, options ...types.Option) (string, error)

StashWithContext https://git-scm.com/docs/git-stash

Example (Apply)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.StashWithContext(context.Background(), stash.Apply("stash@{1}", stash.Quiet), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash apply --quiet stash@{1}
Example (Branch)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.StashWithContext(context.Background(), stash.Branch("foo", "stash@{1}"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash branch foo stash@{1}
Example (Clear)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.StashWithContext(context.Background(), stash.Clear(), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash clear
Example (Create)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.StashWithContext(context.Background(), stash.Create(), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash create
Example (Drop)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.StashWithContext(context.Background(), stash.Drop("stash@{1}", stash.Quiet), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash drop --quiet stash@{1}
Example (List)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.StashWithContext(context.Background(), stash.List(), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash list
Example (Pop)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.StashWithContext(context.Background(), stash.Pop("stash@{1}", stash.Quiet), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash pop --quiet stash@{1}
Example (Push)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.StashWithContext(context.Background(), stash.Push("foo", stash.All), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash push --all foo
Example (Save)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.StashWithContext(context.Background(), stash.Save("foo", stash.Patch), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash save --patch foo
Example (Show)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.StashWithContext(context.Background(), stash.Show("stash@{1}", stash.IncludeUntracked), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash show --include-untracked stash@{1}
Example (Store)
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/stash"
)

func main() {
	out, _ := xgit.StashWithContext(context.Background(), stash.Store(), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git stash store

func Status

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

Status https://git-scm.com/docs/git-status

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/status"
)

func main() {
	out, _ := xgit.Status(status.Short, status.Branch, xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git status --short --branch

func StatusWithContext

func StatusWithContext(ctx context.Context, options ...types.Option) (string, error)

StatusWithContext https://git-scm.com/docs/git-status

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/status"
)

func main() {
	out, _ := xgit.StatusWithContext(context.Background(), status.Short, status.Branch, xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git status --short --branch

func Tag

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

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/tag"
)

func main() {
	out, _ := xgit.Tag(tag.List, xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git tag --list

func TagWithContext

func TagWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/tag"
)

func main() {
	out, _ := xgit.TagWithContext(context.Background(), tag.List, xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git tag --list

func Worktree

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

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/worktree"
)

func main() {
	out, _ := xgit.Worktree(worktree.Add("v1.0", "origin/v1.0"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git worktree add v1.0 origin/v1.0

func WorktreeWithContext

func WorktreeWithContext(ctx context.Context, options ...types.Option) (string, error)

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

Example
package main

import (
	"context"
	"fmt"
	"strings"

	"github.com/kumose-go/xgit"
	"github.com/kumose-go/xgit/worktree"
)

func main() {
	out, _ := xgit.WorktreeWithContext(context.Background(), worktree.Add("v1.0", "origin/v1.0"), xgit.CmdExecutor(cmdExecutorMock))

	fmt.Println(out)
}

func cmdExecutorMock(_ context.Context, name string, _ bool, args ...string) (string, error) {
	return fmt.Sprintln(name, strings.Join(args, " ")), nil
}
Output:

git worktree add v1.0 origin/v1.0

Types

This section is empty.

Directories

Path Synopsis
Package add git-add - Add file contents to the index.
Package add git-add - Add file contents to the index.
Package branch git-branch - List, create, or delete branches.
Package branch git-branch - List, create, or delete branches.
Package checkout git-checkout - Switch branches or restore working tree files.
Package checkout git-checkout - Switch branches or restore working tree files.
Package clone git-clone - Clone a repository into a new directory.
Package clone git-clone - Clone a repository into a new directory.
Package commit git-commit - Record changes to the repository.
Package commit git-commit - Record changes to the repository.
cleanup
Package cleanup This option determines how the supplied commit message should be cleaned up before committing.
Package cleanup This option determines how the supplied commit message should be cleaned up before committing.
untracked
Package untracked The mode parameter is optional (defaults to all), and is used to specify the handling of untracked files; when -u is not used, the default is normal, i.e.
Package untracked The mode parameter is optional (defaults to all), and is used to specify the handling of untracked files; when -u is not used, the default is normal, i.e.
Package config git-config - Get and set repository or global options.
Package config git-config - Get and set repository or global options.
Package fetch git-fetch - Download objects and refs from another repository.
Package fetch git-fetch - Download objects and refs from another repository.
Package global contains the global git command options/
Package global contains the global git command options/
Package init git-init - Create an empty Git repository or reinitialize an existing one.
Package init git-init - Create an empty Git repository or reinitialize an existing one.
Package lsfiles git-ls-files - Show information about files in the index and the working tree.
Package lsfiles git-ls-files - Show information about files in the index and the working tree.
Package merge git-merge - Join two or more development histories together.
Package merge git-merge - Join two or more development histories together.
Package notes git-notes - Add or inspect object notes.
Package notes git-notes - Add or inspect object notes.
Package pull git-pull - Fetch from and integrate with another repository or a local branch.
Package pull git-pull - Fetch from and integrate with another repository or a local branch.
Package push git-push - Update remote refs along with associated objects.
Package push git-push - Update remote refs along with associated objects.
Package rebase git-rebase - Reapply commits on top of another base tip.
Package rebase git-rebase - Reapply commits on top of another base tip.
Package remote git-remote - Manage set of tracked repositories.
Package remote git-remote - Manage set of tracked repositories.
Package reset git-reset - Reset current HEAD to the specified state.
Package reset git-reset - Reset current HEAD to the specified state.
Package revparse git-rev-parse - Pick out and massage parameters.
Package revparse git-rev-parse - Pick out and massage parameters.
Package stash git-stash - Stash the changes in a dirty working directory away.
Package stash git-stash - Stash the changes in a dirty working directory away.
Package status git-status - Show the working tree status
Package status git-status - Show the working tree status
Package tag git-tag - git-tag - Create, list, delete or verify a tag object signed with GPG.
Package tag git-tag - git-tag - Create, list, delete or verify a tag object signed with GPG.
Package worktree git-worktree - Manage multiple working trees.
Package worktree git-worktree - Manage multiple working trees.

Jump to

Keyboard shortcuts

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