git

package
v2.0.2-rc1+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2017 License: MIT Imports: 18 Imported by: 0

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

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"
)
View Source
const (
	LockableAttrib = "lockable"
)
View Source
const (
	// MaxPacketLength is the maximum total (header+payload) length
	// encode-able within one packet using Git's pkt-line protocol.
	MaxPacketLength = 65516
)

Variables

View Source
var Config = &gitConfig{}

Functions

func CloneWithoutFilters added in v1.2.0

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 added in v1.0.1

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 added in v0.6.0

func FormatGitDate(tm time.Time) string

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

func GetFilesChanged

func GetFilesChanged(from, to string) ([]string, error)

GetFilesChanged returns a list of files which were changed, either between 2 commits, or at a single commit if you only supply one argument and a blank string for the other

func GetTrackedFiles added in v1.2.0

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 added in v1.1.1

func GitAndRootDirs() (string, string, error)

func GitDir added in v1.0.1

func GitDir() (string, error)

func IsFileModified

func IsFileModified(filepath string) (bool, error)

IsFileModified returns whether the filepath specified is modified according to `git status`. A file is modified if it has uncommitted changes in the working copy or the index. This includes being untracked.

func IsVersionAtLeast added in v1.1.0

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 added in v0.6.0

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

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

func RemoteBranchForLocalBranch added in v1.0.1

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 added in v1.0.1

func RemoteForBranch(localBranch string) string

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

func RemoteForCurrentBranch added in v1.0.1

func RemoteForCurrentBranch() (string, error)

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

func RemoteList added in v1.0.1

func RemoteList() ([]string, error)

func RemoteRefNameForCurrentBranch added in v1.0.1

func RemoteRefNameForCurrentBranch() (string, error)

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

func RootDir added in v1.0.1

func RootDir() (string, error)

func UpdateIndex added in v0.5.2

func UpdateIndex(file string) error

func ValidateRemote added in v1.0.1

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 added in v1.4.0

func ValidateRemoteURL(remote string) error

ValidateRemoteURL checks that a string is a valid Git remote URL

Types

type AttributePath

type AttributePath struct {
	// Path entry in the attribute file
	Path string
	// The attribute file which was the source of this entry
	Source *AttributeSource
	// Path also has the 'lockable' attribute
	Lockable bool
}

AttributePath is a path entry in a gitattributes file which has the LFS filter

func GetAttributePaths

func GetAttributePaths(workingDir, gitDir string) []AttributePath

GetAttributePaths returns a list of entries in .gitattributes which are configured with the filter=lfs attribute workingDIr is the root of the working copy gitDir is the root of the git repo

type AttributeSource

type AttributeSource struct {
	Path       string
	LineEnding string
}

func (*AttributeSource) String

func (s *AttributeSource) String() string

type CloneFlags added in v1.2.1

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 added in v0.6.0

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 added in v0.6.0

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

Get summary information about a commit

type FilterProcessScanner added in v1.5.0

type FilterProcessScanner struct {
	// contains filtered or unexported fields
}

FilterProcessScanner provides a scanner-like interface capable of initializing the filter process with the Git parent, and scanning for requests across the protocol.

Reading a request (and errors) is as follows:

s := NewFilterProcessScanner(os.Stdin, os.Stderr)
for s.Scan() {
        req := s.Request()
	       // ...
}

if err := s.Err(); err != nil {
        // ...
}

func NewFilterProcessScanner added in v1.5.0

func NewFilterProcessScanner(r io.Reader, w io.Writer) *FilterProcessScanner

NewFilterProcessScanner constructs a new instance of the `*FilterProcessScanner` type which reads packets from the `io.Reader` "r", and writes packets to the `io.Writer`, "w".

Both reader and writers SHOULD NOT be `*git.PacketReader` or `*git.PacketWriter`s, they will be transparently treated as such. In other words, it is safe (and recommended) to pass `os.Stdin` and `os.Stdout` directly.

func (*FilterProcessScanner) Err added in v1.5.0

func (o *FilterProcessScanner) Err() error

Err returns any error encountered from the last call to Scan(). It is available only after a call to `Scan()` has completed, and is re-initialized to nil at the beginning of the subsequent `Scan()` call.

func (*FilterProcessScanner) Init added in v1.5.0

func (o *FilterProcessScanner) Init() error

Init initializes the filter and ACKs back and forth between the Git LFS subprocess and the Git parent process that each is a git-filter-server and client respectively.

If either side wrote an invalid sequence of data, or did not meet expectations, an error will be returned. If the filter type is not supported, an error will be returned. If the pkt-line welcome message was invalid, an error will be returned.

If there was an error reading or writing any of the packets below, an error will be returned.

func (*FilterProcessScanner) NegotiateCapabilities added in v1.5.0

func (o *FilterProcessScanner) NegotiateCapabilities() error

NegotiateCapabilities executes the process of negotiating capabilities between the filter client and server. If we don't support any of the capabilities given to LFS by the parent, an error will be returned. If there was an error reading or writing capabilities between the two, an error will be returned.

func (*FilterProcessScanner) Request added in v1.5.0

func (o *FilterProcessScanner) Request() *Request

Request returns the request read from a call to Scan(). It is available only after a call to `Scan()` has completed, and is re-initialized to nil at the beginning of the subsequent `Scan()` call.

func (*FilterProcessScanner) Scan added in v1.5.0

func (o *FilterProcessScanner) Scan() bool

Scan scans for the next request, or error and returns whether or not the scan was successful, indicating the presence of a valid request. If the Scan failed, there was either an error reading the next request (and the results of calling `Err()` should be inspected), or the pipe was closed and no more requests are present.

Closing the pipe is Git's way to communicate that no more files will be filtered. Git expects that the LFS process exits after this event.

func (*FilterProcessScanner) WriteStatus added in v1.5.0

func (o *FilterProcessScanner) WriteStatus(status string) error

type PktlineWriter added in v1.5.0

type PktlineWriter struct {
	// contains filtered or unexported fields
}

PktlineWriter is an implementation of `io.Writer` which writes data buffers "p" to an underlying pkt-line stream for use with the Git pkt-line format.

func NewPktlineWriter added in v1.5.0

func NewPktlineWriter(w io.Writer, c int) *PktlineWriter

NewPktlineWriter returns a new *PktlineWriter, which will write to the underlying data stream "w". The internal buffer is initialized with the given capacity, "c".

If "w" is already a `*PktlineWriter`, it will be returned as-is.

func (*PktlineWriter) Flush added in v1.5.0

func (w *PktlineWriter) Flush() error

Flush empties the internal buffer used to store data temporarily and then writes the pkt-line's FLUSH packet, to signal that it is done writing this chunk of data.

func (*PktlineWriter) Write added in v1.5.0

func (w *PktlineWriter) Write(p []byte) (int, error)

Write implements the io.Writer interface's `Write` method by providing a packet-based backend to the given buffer "p".

As many bytes are removed from "p" as possible and stored in an internal buffer until the amount of data in the internal buffer is enough to write a single packet. Once the internal buffer is full, a packet is written to the underlying stream of data, and the process repeats.

When the caller has no more data to write in the given chunk of packets, a subsequent call to `Flush()` SHOULD be made in order to signify that the current pkt sequence has terminated, and a new one can begin.

Write returns the number of bytes in "p" accepted into the writer, which _MAY_ be written to the underlying protocol stream, or may be written into the internal buffer.

If any error was encountered while either buffering or writing, that error is returned, along with the number of bytes written to the underlying protocol stream, as described above.

type Ref added in v0.6.0

type Ref struct {
	Name string
	Type RefType
	Sha  string
}

A git reference (branch, tag etc)

func CachedRemoteRefs added in v1.2.0

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 added in v1.1.0

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 added in v1.2.0

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 added in v0.6.0

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 added in v1.2.0

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 added in v1.2.0

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

type RefType added in v0.6.0

type RefType int

func ParseRefToTypeAndName added in v0.6.0

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

Get the type & name of a git reference

type Request added in v1.5.0

type Request struct {
	// Header maps header strings to values, and is encoded as the first
	// part of the packet.
	Header map[string]string
	// Payload represents the body of the packet, and contains the contents
	// of the file in the index.
	Payload io.Reader
}

Request represents a single command sent to LFS from the parent Git process.

Jump to

Keyboard shortcuts

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