git

package
v1.4.5-0...-b3ef71d Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2016 License: MIT Imports: 15 Imported by: 34

Documentation

Overview

Package git contains various commands that shell out to git NOTE: Subject to change, do not rely on this package from outside git-lfs source

Index

Constants

View Source
const (
	RefTypeLocalBranch  = RefType(iota)
	RefTypeRemoteBranch = RefType(iota)
	RefTypeLocalTag     = RefType(iota)
	RefTypeRemoteTag    = RefType(iota)
	RefTypeHEAD         = RefType(iota) // current checkout
	RefTypeOther        = RefType(iota) // stash or unknown

	// A ref which can be used as a placeholder for before the first commit
	// Equivalent to git mktree < /dev/null, useful for diffing before first commit
	RefBeforeFirstCommit = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
)

Variables

View Source
var Config = &gitConfig{}

Functions

func CloneWithoutFilters

func CloneWithoutFilters(flags CloneFlags, args []string) error

CloneWithoutFilters clones a git repo but without the smudge filter enabled so that files in the working copy will be pointers and not real LFS data

func DefaultRemote

func DefaultRemote() (string, error)

DefaultRemote returns the default remote based on: 1. The currently tracked remote branch, if present 2. "origin", if defined 3. Any other SINGLE remote defined in .git/config Returns an error if all of these fail, i.e. no tracked remote branch, no "origin", and either no remotes defined or 2+ non-"origin" remotes

func FormatGitDate

func FormatGitDate(tm time.Time) string

FormatGitDate converts a Go date into a git command line format date

func GetTrackedFiles

func GetTrackedFiles(pattern string) ([]string, error)

GetTrackedFiles returns a list of files which are tracked in Git which match the pattern specified (standard wildcard form) Both pattern and the results are relative to the current working directory, not the root of the repository

func GitAndRootDirs

func GitAndRootDirs() (string, string, error)

func GitDir

func GitDir() (string, error)

func IsVersionAtLeast

func IsVersionAtLeast(actualVersion, desiredVersion string) bool

IsVersionAtLeast compares 2 version strings (ok to be prefixed with 'git version', ignores)

func LsRemote

func LsRemote(remote, remoteRef string) (string, error)

func ParseGitDate

func ParseGitDate(str string) (time.Time, error)

Parse a Git date formatted in ISO 8601 format (%ci/%ai)

func RemoteBranchForLocalBranch

func RemoteBranchForLocalBranch(localBranch string) string

RemoteBranchForLocalBranch returns the name (only) of the remote branch that the local branch is tracking If no specific branch is configured, returns local branch name

func RemoteForBranch

func RemoteForBranch(localBranch string) string

RemoteForBranch returns the remote name that a given local branch is tracking (blank if none)

func RemoteForCurrentBranch

func RemoteForCurrentBranch() (string, error)

RemoteForCurrentBranch returns the name of the remote that the current branch is tracking

func RemoteList

func RemoteList() ([]string, error)

func RemoteRefNameForCurrentBranch

func RemoteRefNameForCurrentBranch() (string, error)

RemoteRefForCurrentBranch returns the full remote ref (refs/remotes/{remote}/{remotebranch}) that the current branch is tracking.

func RootDir

func RootDir() (string, error)

func UpdateIndex added in v0.5.2

func UpdateIndex(file string) error

func ValidateRemote

func ValidateRemote(remote string) error

ValidateRemote checks that a named remote is valid for use Mainly to check user-supplied remotes & fail more nicely

func ValidateRemoteURL

func ValidateRemoteURL(remote string) error

ValidateRemoteURL checks that a string is a valid Git remote URL

Types

type CloneFlags

type CloneFlags struct {
	// --template <template_directory>
	TemplateDirectory string
	// -l --local
	Local bool
	// -s --shared
	Shared bool
	// --no-hardlinks
	NoHardlinks bool
	// -q --quiet
	Quiet bool
	// -n --no-checkout
	NoCheckout bool
	// --progress
	Progress bool
	// --bare
	Bare bool
	// --mirror
	Mirror bool
	// -o <name> --origin <name>
	Origin string
	// -b <name> --branch <name>
	Branch string
	// -u <upload-pack> --upload-pack <pack>
	Upload string
	// --reference <repository>
	Reference string
	// --dissociate
	Dissociate bool
	// --separate-git-dir <git dir>
	SeparateGit string
	// --depth <depth>
	Depth string
	// --recursive
	Recursive bool
	// --recurse-submodules
	RecurseSubmodules bool
	// -c <value> --config <value>
	Config string
	// --single-branch
	SingleBranch bool
	// --no-single-branch
	NoSingleBranch bool
	// --verbose
	Verbose bool
	// --ipv4
	Ipv4 bool
	// --ipv6
	Ipv6 bool
}

For compatibility with git clone we must mirror all flags in CloneWithoutFilters

type CommitSummary

type CommitSummary struct {
	Sha            string
	ShortSha       string
	Parents        []string
	CommitDate     time.Time
	AuthorDate     time.Time
	AuthorName     string
	AuthorEmail    string
	CommitterName  string
	CommitterEmail string
	Subject        string
}

Some top level information about a commit (only first line of message)

func GetCommitSummary

func GetCommitSummary(commit string) (*CommitSummary, error)

Get summary information about a commit

type Ref

type Ref struct {
	Name string
	Type RefType
	Sha  string
}

A git reference (branch, tag etc)

func CachedRemoteRefs

func CachedRemoteRefs(remoteName string) ([]*Ref, error)

CachedRemoteRefs returns the list of branches & tags for a remote which are currently cached locally. No remote request is made to verify them.

func CurrentRef

func CurrentRef() (*Ref, error)

func CurrentRemoteRef

func CurrentRemoteRef() (*Ref, error)

func GetAllWorkTreeHEADs

func GetAllWorkTreeHEADs(storageDir string) ([]*Ref, error)

GetAllWorkTreeHEADs returns the refs that all worktrees are using as HEADs This returns all worktrees plus the master working copy, and works even if working dir is actually in a worktree right now Pass in the git storage dir (parent of 'objects') to work from

func LocalRefs

func LocalRefs() ([]*Ref, error)

Refs returns all of the local and remote branches and tags for the current repository. Other refs (HEAD, refs/stash, git notes) are ignored.

func RecentBranches

func RecentBranches(since time.Time, includeRemoteBranches bool, onlyRemote string) ([]*Ref, error)

RecentBranches returns branches with commit dates on or after the given date/time Return full Ref type for easier detection of duplicate SHAs etc since: refs with commits on or after this date will be included includeRemoteBranches: true to include refs on remote branches onlyRemote: set to non-blank to only include remote branches on a single remote

func RemoteRefs

func RemoteRefs(remoteName string) ([]*Ref, error)

RemoteRefs returns a list of branches & tags for a remote by actually accessing the remote vir git ls-remote

func ResolveRef added in v0.5.2

func ResolveRef(ref string) (*Ref, error)

func ResolveRefs

func ResolveRefs(refnames []string) ([]*Ref, error)

type RefType

type RefType int

func ParseRefToTypeAndName

func ParseRefToTypeAndName(fullref string) (t RefType, name string)

Get the type & name of a git reference

Jump to

Keyboard shortcuts

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