git

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ColorDiffTrippleDash is the "file name before change", e.g:
	//	--- a/cmd/apply.go
	ColorDiffTrippleDash = color.New(color.FgHiRed, color.Italic)
	// ColorDiffTripplePlus is the "file name after change", e.g:
	//	+++ b/cmd/apply.go
	ColorDiffTripplePlus = color.New(color.FgHiGreen, color.Italic)
	// ColorDiffRemove is the removed lines, e.g:
	//	-	if !color.NoColor && cfg.Log.Format == config.LogFormatPretty {
	//	-		diff = colorizeDiff(diff)
	ColorDiffRemove = color.New(color.FgRed)
	// ColorDiffAdd is the added lines, e.g:
	//	+	if cfg.Log.Format == config.LogFormatPretty {
	//	+		diff = git.ColorizeDiff(diff)
	ColorDiffAdd = color.New(color.FgGreen)
	// ColorDiffDoubleAt is the double at-symbol (@) specifying section ranges, e.g:
	//	@@ -339,42 +338,12 @@ func logDiff(repo git.Repo) {
	ColorDiffDoubleAt = color.New(color.FgMagenta, color.Italic)
	// ColorDiffOtherNonSpace is the other Git info lines, i.e all other lines
	// that doesn't start with a space, e.g:
	//	diff --git a/cmd/apply.go b/cmd/apply.go
	//	index b4c2d30..a5f6e5f 100644
	ColorDiffOtherNonSpace = color.New(color.FgHiBlack, color.Italic)
)

Color settings for Git diffs.

Example diff:

diff --git a/cmd/apply.go b/cmd/apply.go
index b4c2d30..a5f6e5f 100644
--- a/cmd/apply.go
+++ b/cmd/apply.go
@@ -339,42 +338,12 @@ func logDiff(repo git.Repo) {
 		log.Warn().Err(err).Msg("Failed diffing changes. Trying to continue anyways.")
 		return
 	}
-	if !color.NoColor && cfg.Log.Format == config.LogFormatPretty {
-		diff = colorizeDiff(diff)
+	if cfg.Log.Format == config.LogFormatPretty {
+		diff = git.ColorizeDiff(diff)

Functions

func ColorizeDiff

func ColorizeDiff(diff string) string

Types

type Cmd

type Cmd struct {
	Credentials Credentials
	Committer   Committer
}

Cmd implements Git using the command-line version of Git.

func (Cmd) Clone

func (g Cmd) Clone(targetDir, remote string) (Repo, error)

type CmdRepo

type CmdRepo struct {
	Committer Committer
	// contains filtered or unexported fields
}

func (*CmdRepo) CheckoutNewBranch

func (r *CmdRepo) CheckoutNewBranch(branchName string) error

func (*CmdRepo) Close

func (r *CmdRepo) Close() error

func (*CmdRepo) CreateCommit

func (r *CmdRepo) CreateCommit(message string) (Commit, error)

func (*CmdRepo) CurrentBranch

func (r *CmdRepo) CurrentBranch() string

func (*CmdRepo) DiffChanges

func (r *CmdRepo) DiffChanges() (string, error)

func (*CmdRepo) DiffStaged added in v0.5.0

func (r *CmdRepo) DiffStaged() (string, error)

func (*CmdRepo) Directory

func (r *CmdRepo) Directory() string

func (*CmdRepo) MainBranch

func (r *CmdRepo) MainBranch() string

func (*CmdRepo) PushChanges

func (r *CmdRepo) PushChanges() error

func (*CmdRepo) StageChanges

func (r *CmdRepo) StageChanges() error

type Commit

type Commit struct {
	Hash           string
	AbbrHash       string
	ParentHash     string
	ParentAbbrHash string
	Subject        string
	Diff           string
}

func (Commit) String

func (c Commit) String() string

type Committer

type Committer struct {
	Name  string // maps to Git config user.name
	Email string // maps to Git config user.email
}

type Credentials

type Credentials struct {
	Username string
	Password string
}

type Git

type Git interface {
	Clone(targetDir, remote string) (Repo, error)
}

type Repo

type Repo interface {
	io.Closer
	Directory() string
	CurrentBranch() string
	MainBranch() string

	CheckoutNewBranch(branchName string) error
	DiffChanges() (string, error)
	DiffStaged() (string, error)
	StageChanges() error
	CreateCommit(message string) (Commit, error)
	PushChanges() error
}

func CloneTemp

func CloneTemp(g Git, tmpDirPattern, remote string) (Repo, error)

Jump to

Keyboard shortcuts

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