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 ¶
- func Add(options ...types.Option) (string, error)
- func AddWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Branch(options ...types.Option) (string, error)
- func BranchWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Checkout(options ...types.Option) (string, error)
- func CheckoutWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Clone(options ...types.Option) (string, error)
- func CloneWithContext(ctx context.Context, options ...types.Option) (string, error)
- func CmdExecutor(executor types.Executor) types.Option
- func Commit(options ...types.Option) (string, error)
- func CommitWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Cond(apply bool, options ...types.Option) types.Option
- func Config(options ...types.Option) (string, error)
- func ConfigWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Debug(g *types.Cmd)
- func Debugger(debug bool) types.Option
- func Fetch(options ...types.Option) (string, error)
- func FetchWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Init(options ...types.Option) (string, error)
- func InitWithContext(ctx context.Context, options ...types.Option) (string, error)
- func LogOutput(w io.Writer) types.Option
- func LsFiles(subCommand ...types.Option) (string, error)
- func LsFilesWithContext(ctx context.Context, subCommand ...types.Option) (string, error)
- func Merge(options ...types.Option) (string, error)
- func MergeWithContext(ctx context.Context, options ...types.Option) (string, error)
- func NoOp(_ *types.Cmd)
- func Notes(subCommand ...types.Option) (string, error)
- func NotesWithContext(ctx context.Context, subCommand ...types.Option) (string, error)
- func Pull(options ...types.Option) (string, error)
- func PullWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Push(options ...types.Option) (string, error)
- func PushWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Raw(cmd string, options ...types.Option) (string, error)
- func RawWithContext(ctx context.Context, cmd string, options ...types.Option) (string, error)
- func Rebase(options ...types.Option) (string, error)
- func RebaseWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Remote(options ...types.Option) (string, error)
- func RemoteWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Reset(options ...types.Option) (string, error)
- func ResetWithContext(ctx context.Context, options ...types.Option) (string, error)
- func RevParse(options ...types.Option) (string, error)
- func RevParseWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Stash(options ...types.Option) (string, error)
- func StashWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Status(options ...types.Option) (string, error)
- func StatusWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Tag(options ...types.Option) (string, error)
- func TagWithContext(ctx context.Context, options ...types.Option) (string, error)
- func Worktree(options ...types.Option) (string, error)
- func WorktreeWithContext(ctx context.Context, options ...types.Option) (string, error)
Examples ¶
- Add
- AddWithContext
- Branch
- BranchWithContext
- Checkout
- CheckoutWithContext
- Clone
- CloneWithContext
- Commit
- CommitWithContext
- Cond
- Config
- ConfigWithContext
- Fetch
- FetchWithContext
- Init
- InitWithContext
- LsFiles
- LsFilesWithContext
- Merge
- MergeWithContext
- Notes (Add)
- Notes (Append)
- Notes (Copy)
- Notes (Edit)
- Notes (GetRef)
- Notes (List)
- Notes (List_ref)
- Notes (Merge)
- Notes (Prune)
- Notes (Remove)
- Notes (Show)
- NotesWithContext (Add)
- NotesWithContext (Append)
- NotesWithContext (Copy)
- NotesWithContext (Edit)
- NotesWithContext (GetRef)
- NotesWithContext (List)
- NotesWithContext (List_ref)
- NotesWithContext (Merge)
- NotesWithContext (Prune)
- NotesWithContext (Remove)
- NotesWithContext (Show)
- Pull
- PullWithContext
- Push
- PushWithContext
- Raw
- RawWithContext
- RawWithContext (BaseOptions)
- Rebase
- RebaseWithContext
- Remote
- RemoteWithContext
- Reset
- ResetWithContext
- RevParse
- RevParseWithContext
- Stash (Apply)
- Stash (Branch)
- Stash (Clear)
- Stash (Create)
- Stash (Drop)
- Stash (List)
- Stash (Pop)
- Stash (Push)
- Stash (Save)
- Stash (Show)
- Stash (Store)
- StashWithContext (Apply)
- StashWithContext (Branch)
- StashWithContext (Clear)
- StashWithContext (Create)
- StashWithContext (Drop)
- StashWithContext (List)
- StashWithContext (Pop)
- StashWithContext (Push)
- StashWithContext (Save)
- StashWithContext (Show)
- StashWithContext (Store)
- Status
- StatusWithContext
- Tag
- TagWithContext
- Worktree
- WorktreeWithContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
CmdExecutor Allow to override the Git command call (useful for testing purpose).
func Commit ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 Fetch ¶
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 ¶
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 ¶
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 ¶
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 LsFiles ¶
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 ¶
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 ¶
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 ¶
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 Notes ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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. |