gitstatus

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 15 Imported by: 7

README

Build Status Go Report Card Go Reference

gitstatus

retrieve the Git status of a working tree, in Go.

License MIT

See LICENSE file

Documentation

Overview

Package gitstatus provides information about the git status of a working tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Porcelain added in v0.4.0

type Porcelain struct {
	// NumModified is the number of modified files.
	NumModified int

	// NumConflicts is the number of unmerged files.
	NumConflicts int

	// NumUntracked is the number of untracked files.
	NumUntracked int

	// NumStaged is the number of staged files.
	NumStaged int

	// IsDetached reports whether HEAD is not associated to any branch
	// (detached).
	IsDetached bool

	// IsInitial reports whether the working tree is in its initial state (no
	// commit have been performed yet).
	IsInitial bool

	// LocalBranch is the name of the local branch.
	LocalBranch string

	// RemoteBranch is the name of upstream remote branch (tracking).
	RemoteBranch string

	// AheadCount reports by how many commits the local branch is ahead of its upstream branch.
	AheadCount int

	// BehindCount reports by how many commits the local branch is behind its upstream branch.
	BehindCount int
}

Porcelain holds the Git status variables extracted from calling git status --porcelain.

type Status

type Status struct {
	Porcelain

	// NumStashed is the number of stash entries.
	NumStashed int

	// HEAD is the shortened SHA1 of current commit (empty in initial state).
	HEAD string

	// State indicates the state of the working tree.
	State TreeState

	// IsClean reports whether the working tree is in a clean state (i.e empty
	// staging area, no conflicts and no untracked files).
	IsClean bool

	// Insertions is the count of inserted lines in the staging area.
	Insertions int

	// Deletions is the count of deleted lines in the staging area.
	Deletions int
}

Status represents the status of a Git working tree directory.

func New

func New() (*Status, error)

New returns the Git Status of the current working directory.

func NewWithContext added in v0.4.3

func NewWithContext(ctx context.Context) (*Status, error)

NewWithContext is likes New but includes a context.

The provided context is used to stop retrieving git status if the context becomes done before all calls to git have completed.

type TreeState

type TreeState int

TreeState indicates the state of a Git working tree. Its zero-value is NormalState.

const (
	// Default is state set when the working tree is not in any special state.
	Default TreeState = iota

	// Rebasing is the state set when a rebase is in progress, either
	// interactive or manual.
	Rebasing

	// AM is the state set when a git AM is in progress (mailbox patch).
	AM

	// AMRebase is the state set when a git AM rebasing is in progress.
	AMRebase

	// Merging is the state set when a merge is in progress.
	Merging

	// CherryPicking is the state when a cherry-pick is in progress.
	CherryPicking

	// Reverting is the state when a revert is in progress.
	Reverting

	// Bisecting is the state when a bisect is in progress.
	Bisecting
)

func (TreeState) MarshalJSON

func (s TreeState) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the tree state.

func (TreeState) String

func (i TreeState) String() string

Jump to

Keyboard shortcuts

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