Documentation
¶
Overview ¶
Package git provides functionality to interact with a Git repository.
Index ¶
- Constants
- func CommandIsInstalled() bool
- func CommitID(dir string) (string, error)
- func IsGitDir(dir string) (bool, error)
- func LsFiles(ctx context.Context, dir string, skipUntracked bool, ch chan<- *Object) error
- func ObjectID(ctx context.Context, absFilePath, repoRelFilePath string) (string, error)
- func UntrackedFiles(dir string) ([]string, error)
- func WorktreeIsDirty(dir string) (bool, error)
- type Object
- type Repository
Constants ¶
const ( // H tracked file that is not either unmerged or skip-worktree ObjectStatusCached byte = 'H' // S tracked file that is skip-worktree ObjectStatusSkipWorktree byte = 'S' // M tracked file that is unmerged ObjectStatusUnmerged byte = 'M' // R tracked file with unstaged removal/deletion ObjectStatusRemoved byte = 'R' // C tracked file with unstaged modification/change ObjectStatusChanged byte = 'C' // K untracked paths which are part of file/directory conflicts which // prevent checking out tracked files ObjectStatusToBeKilled byte = 'K' // ? untracked file ObjectStatusUntracked byte = '?' // U file with resolve-undo information ObjectStatusWithResolveUndoInfo byte = 'U' )
const ( ObjectTypeSymlink = 0120000 ObjectTypeFile = 0100000 )
const Name = "git"
Variables ¶
This section is empty.
Functions ¶
func CommandIsInstalled ¶
func CommandIsInstalled() bool
CommandIsInstalled returns true if an executable called "git" is found in the directories listed in the PATH environment variable.
func CommitID ¶
CommitID return the commit id of HEAD by running git rev-parse in the passed directory
func IsGitDir ¶
IsGitDir checks if the passed directory is in a git repository. It returns true if: - .git/ exists or - the "git" command is in $PATH and "git rev-parse --git-dir" returns exit code 0 It returns false if:
- .git/ does not exist and the "git" command is not in $PATH or "git rev-parse --git-dir" exits with code 128
func LsFiles ¶ added in v3.3.0
LsFiles retrieves information about files in the index and working tree. The information is sent to ch. For a path multiple objects might be sent, if the status in the index and working tree differs. Listing files in git submodules is not supported. The function closes ch when it terminates.
func UntrackedFiles ¶
UntrackedFiles returns a list of untracked and modified files in the git repository. Files that exist and are in a .gitignore file are included.
func WorktreeIsDirty ¶
WorktreeIsDirty returns true if the repository contains modified files, untracked files are considered, files in .gitignore are ignored
Types ¶
type Object ¶ added in v3.3.0
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository reads information from a Git repository.
func NewRepository ¶
func NewRepository(dir string) *Repository
NewRepository creates a new Repository that interacts with the repository at dir. dir must be directory in a Git worktree. This means it must have a .git/ directory or one of the parent directories must contain a .git/ directory.
func (*Repository) CommitID ¶
func (g *Repository) CommitID() (string, error)
CommitID calls git.CommitID() for the repository. After the first successful call the commit ID is stored and the stored value is returned on successive calls.
func (*Repository) Name ¶ added in v3.2.0
func (g *Repository) Name() string
func (*Repository) UntrackedFiles ¶ added in v3.2.0
func (g *Repository) UntrackedFiles() ([]string, error)
UntrackedFiles returns a list of untracked and modified files in the git repository. Files that exist and are in a .gitignore file are included.
func (*Repository) WithoutUntracked ¶
func (g *Repository) WithoutUntracked(paths ...string) ([]string, error)
func (*Repository) WorktreeIsDirty ¶
func (g *Repository) WorktreeIsDirty() (bool, error)
WorktreeIsDirty calls git.WorktreeIsDirty. After the first successful call the result is stored and the stored value is returned on successive calls.