git

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package git encapsulates git command and branch verification functionality.

Index

Constants

View Source
const (
	StatusCmd   string = "status"
	BranchCmd   string = "branch"
	CheckoutCmd string = "checkout"
	RemoteCmd   string = "remote"
)

Variables

This section is empty.

Functions

func FormatAsValidRef

func FormatAsValidRef(s string) string

FormatAsValidRef transforms `s` to a string that is a valid refname

A reference is used in git to specify branches and tags. The following rules must be followed when is comes to naming references: https://git-scm.com/docs/git-check-ref-format

func GetBranchName

func GetBranchName(base, key, title string) string

func GetLengthWithUpperbound

func GetLengthWithUpperbound(s []string, m int) int

Types

type Commander

type Commander struct{}

Commander implements git commands.

func NewCommander

func NewCommander() *Commander

NewCommander returns a new GitCommander.

func (*Commander) Branch added in v0.2.0

func (g *Commander) Branch(ctx ExecContext, b string) error

Branch executes `git branch <b>` where b represents the branch name. Returns an error if command execution fails.

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

func (*Commander) Checkout added in v0.2.0

func (g *Commander) Checkout(ctx ExecContext, b string) error

Checkout executes `git branch <b>` where b represents the branch name. Returns an error if command execution fails.

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

func (*Commander) DiffIndex added in v0.2.0

func (g *Commander) DiffIndex(ctx ExecContext, t string) error

DiffIndex compares a tree `t` to the working tree or index. Returns an error when there is a diff.

https://git-scm.com/docs/git-diff-index

func (*Commander) Remote added in v0.2.0

func (g *Commander) Remote(ctx ExecContext, args ...string) (string, error)

Remote executes `git remote <args>`

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

func (*Commander) ShortSymbolicRef added in v0.2.0

func (g *Commander) ShortSymbolicRef(ctx ExecContext) (string, error)

ShortSymbolicRef executes `git symbolic-ref --short HEAD` Returns which branch head the given symbolic ref refers to and outputs its path as first return value. Any error is returned as second return value.

https://git-scm.com/docs/git-symbolic-ref

func (*Commander) ShowRef added in v0.2.0

func (g *Commander) ShowRef(ctx ExecContext, b string) error

ShowRef list references in a local repository. This function can be used to check if a local branch exists or not.

https://git-scm.com/docs/git-show-ref

func (*Commander) Status added in v0.2.0

func (g *Commander) Status(ctx ExecContext, args ...string) (string, error)

Status executes `git status` and returns the output and an error if the command execution fails.

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

type ExecContext

type ExecContext = func(command string, args ...string) *exec.Cmd

ExecContext is a function that returns an external command being prepared or run in either a real or simulated shell.

Jump to

Keyboard shortcuts

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