git

package
v2.5.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: MIT Imports: 20 Imported by: 154

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

This section is empty.

Functions

func CatFile

func CatFile() (*subprocess.BufferedCmd, error)

func Checkout

func Checkout(treeish string, paths []string, force bool) error

Checkout performs an invocation of `git-checkout(1)` applying the given treeish, paths, and force option, if given.

If any error was encountered, it will be returned immediately. Otherwise, the checkout has occurred successfully.

func CloneWithoutFilters added in v1.5.6

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 DiffIndex

func DiffIndex(ref string, cached bool) (*bufio.Scanner, error)

func Fetch

func Fetch(remotes ...string) error

Fetch performs a fetch with no arguments against the given remotes.

func FormatGitDate added in v1.5.6

func FormatGitDate(tm time.Time) string

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

func GetAttributeFilter

func GetAttributeFilter(workingDir, gitDir string) *filepathfilter.Filter

GetAttributeFilter returns a list of entries in .gitattributes which are configured with the filter=lfs attribute as a file path filter which file paths can be matched against workingDir is the root of the working copy gitDir is the root of the git repo

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.5.6

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.5.6

func GitAndRootDirs() (string, string, error)

func GitDir added in v1.5.6

func GitDir() (string, error)

func HashObject

func HashObject(r io.Reader) (string, error)

func IsBare

func IsBare() (bool, error)

IsBare returns whether or not a repository is bare. It requires that the current working directory is a repository.

If there was an error determining whether or not the repository is bare, it will be returned.

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 IsGitVersionAtLeast

func IsGitVersionAtLeast(ver string) bool

IsVersionAtLeast returns whether the git version is the one specified or higher argument is plain version string separated by '.' e.g. "2.3.1" but can omit minor/patch

func IsMissingObject

func IsMissingObject(err error) bool

func IsVersionAtLeast added in v1.5.6

func IsVersionAtLeast(actualVersion, desiredVersion string) bool

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

func IsWorkingCopyDirty

func IsWorkingCopyDirty() (bool, error)

IsWorkingCopyDirty returns true if and only if the working copy in which the command was executed is dirty as compared to the index.

If the status of the working copy could not be determined, an error will be returned instead.

func Log

func Log(args ...string) (*subprocess.BufferedCmd, error)

func LsRemote

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

func LsTree

func LsTree(ref string) (*subprocess.BufferedCmd, error)

func ParseGitDate added in v1.5.6

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

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

func RemoteList added in v1.5.6

func RemoteList() ([]string, error)

func RootDir added in v1.5.6

func RootDir() (string, error)

func UpdateIndexFromStdin

func UpdateIndexFromStdin() *subprocess.Cmd

func UpdateRef

func UpdateRef(ref *Ref, to []byte, reason string) error

UpdateRef moves the given ref to a new sha with a given reason (and creates a reflog entry, if a "reason" was provided). It returns an error if any were encountered.

func UpdateRefIn

func UpdateRefIn(wd string, ref *Ref, to []byte, reason string) error

UpdateRef moves the given ref to a new sha with a given reason (and creates a reflog entry, if a "reason" was provided). It operates within the given working directory "wd". It returns an error if any were encountered.

func ValidateRemote added in v1.5.6

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.5.6

func ValidateRemoteURL(remote string) error

ValidateRemoteURL checks that a string is a valid Git remote URL

func Version

func Version() (string, error)

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

func GetRootAttributePaths

func GetRootAttributePaths(cfg Env) []AttributePath

GetRootAttributePaths beahves as GetRootAttributePaths, and loads information only from the global gitattributes file.

func GetSystemAttributePaths

func GetSystemAttributePaths(env Env) []AttributePath

GetSystemAttributePaths behaves as GetAttributePaths, and loads information only from the system gitattributes file, respecting the $PREFIX environment variable.

type AttributeSource

type AttributeSource struct {
	Path       string
	LineEnding string
}

func (*AttributeSource) String

func (s *AttributeSource) String() string

type CloneFlags added in v1.5.6

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
	// --reference-if-able <repository>
	ReferenceIfAble 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
	// --shallow-since <date>
	ShallowSince string
	// --shallow-since <date>
	ShallowExclude string
	// --shallow-submodules
	ShallowSubmodules bool
	// --no-shallow-submodules
	NoShallowSubmodules bool
	// jobs <n>
	Jobs int64
}

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

type CommitSummary added in v1.5.6

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 v1.5.6

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

Get summary information about a commit

type Configuration

type Configuration struct {
	WorkDir string
	GitDir  string
	// contains filtered or unexported fields
}

Configuration can fetch or modify the current Git config and track the Git version.

func NewConfig

func NewConfig(workdir, gitdir string) *Configuration

func (*Configuration) CurrentRemoteRef

func (c *Configuration) CurrentRemoteRef() (*Ref, error)

func (*Configuration) FileSource

func (c *Configuration) FileSource(filename string) (*ConfigurationSource, error)

func (*Configuration) Find

func (c *Configuration) Find(val string) string

Find returns the git config value for the key

func (*Configuration) FindGlobal

func (c *Configuration) FindGlobal(key string) string

FindGlobal returns the git config value global scope for the key

func (*Configuration) FindLocal

func (c *Configuration) FindLocal(key string) string

Find returns the git config value for the key

func (*Configuration) FindSystem

func (c *Configuration) FindSystem(key string) string

FindSystem returns the git config value in system scope for the key

func (*Configuration) RemoteBranchForLocalBranch

func (c *Configuration) 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 (*Configuration) RemoteForBranch

func (c *Configuration) RemoteForBranch(localBranch string) string

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

func (*Configuration) RemoteRefNameForCurrentBranch

func (c *Configuration) RemoteRefNameForCurrentBranch() (string, error)

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

func (*Configuration) SetGlobal

func (c *Configuration) SetGlobal(key, val string) (string, error)

SetGlobal sets the git config value for the key in the global config

func (*Configuration) SetLocal

func (c *Configuration) SetLocal(key, val string) (string, error)

SetLocal sets the git config value for the key in the specified config file

func (*Configuration) SetSystem

func (c *Configuration) SetSystem(key, val string) (string, error)

SetSystem sets the git config value for the key in the system config

func (*Configuration) Source

func (c *Configuration) Source() (*ConfigurationSource, error)

func (*Configuration) Sources

func (c *Configuration) Sources(optionalFilename string) ([]*ConfigurationSource, error)

func (*Configuration) UnsetGlobalSection

func (c *Configuration) UnsetGlobalSection(key string) (string, error)

UnsetGlobalSection removes the entire named section from the global config

func (*Configuration) UnsetLocalKey

func (c *Configuration) UnsetLocalKey(key string) (string, error)

UnsetLocalKey removes the git config value for the key from the specified config file

func (*Configuration) UnsetLocalSection

func (c *Configuration) UnsetLocalSection(key string) (string, error)

UnsetLocalSection removes the entire named section from the system config

func (*Configuration) UnsetSystemSection

func (c *Configuration) UnsetSystemSection(key string) (string, error)

UnsetSystemSection removes the entire named section from the system config

type ConfigurationSource

type ConfigurationSource struct {
	Lines        []string
	OnlySafeKeys bool
}

func ParseConfigLines

func ParseConfigLines(lines string, onlySafeKeys bool) *ConfigurationSource

type Env

type Env interface {
	Get(key string) (val string, ok bool)
}

copy of env

type FilterProcessScanner added in v1.5.6

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.6

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.6

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.6

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.6

func (o *FilterProcessScanner) NegotiateCapabilities() ([]string, 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 Git, 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.6

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.6

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) WriteList

func (o *FilterProcessScanner) WriteList(list []string) error

WriteList writes a list of strings to the underlying pktline data stream in pktline format.

func (*FilterProcessScanner) WriteStatus added in v1.5.6

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

type FilterProcessStatus

type FilterProcessStatus uint8

FilterProcessStatus is a constant type representing the various valid responses for `status=` in the Git filtering process protocol.

const (
	// StatusSuccess is a valid response when a successful event has
	// occurred.
	StatusSuccess FilterProcessStatus = iota + 1
	// StatusDelay is a valid response when a delay has occurred.
	StatusDelay
	// StatusError is a valid response when an error has occurred.
	StatusError
)

func (FilterProcessStatus) String

func (s FilterProcessStatus) String() string

String implements fmt.Stringer by returning a protocol-compliant representation of the receiving status, or panic()-ing if the Status is unknown.

type ObjectScanner

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

ObjectScanner is a scanner type that scans for Git objects reference-able in Git's object database by their unique OID.

func NewObjectScanner

func NewObjectScanner() (*ObjectScanner, error)

NewObjectScanner constructs a new instance of the `*ObjectScanner` type and returns it. It backs the ObjectScanner with an invocation of the `git cat-file --batch` command. If any errors were encountered while starting that command, they will be returned immediately.

Otherwise, an `*ObjectScanner` is returned with no error.

func NewObjectScannerFrom

func NewObjectScannerFrom(r io.Reader) *ObjectScanner

NewObjectScannerFrom returns a new `*ObjectScanner` populated with data from the given `io.Reader`, "r". It supplies no close function, and discards any input given to the Scan() function.

func (*ObjectScanner) Close

func (s *ObjectScanner) Close() error

Close closes and frees any resources owned by the *ObjectScanner that it is called upon. If there were any errors in freeing that (those) resource(s), it it will be returned, otherwise nil.

func (*ObjectScanner) Contents

func (s *ObjectScanner) Contents() io.Reader

Contents returns an io.Reader which reads Git's representation of the object that was last scanned for.

func (*ObjectScanner) Err

func (s *ObjectScanner) Err() error

Err returns the error (if any) that was encountered during the last Scan() operation.

func (*ObjectScanner) Scan

func (s *ObjectScanner) Scan(oid string) bool

Scan scans for a particular object given by the "oid" parameter. Once the scan is complete, the Contents(), Sha1(), Size() and Type() functions may be called and will return data corresponding to the given OID.

Scan() returns whether the scan was successful, or in other words, whether or not the scanner can continue to progress.

func (*ObjectScanner) Sha1

func (s *ObjectScanner) Sha1() string

Sha1 returns the SHA1 object ID of the object that was last scanned for.

func (*ObjectScanner) Size

func (s *ObjectScanner) Size() int64

Size returns the size in bytes of the object that was last scanned for.

func (*ObjectScanner) Type

func (s *ObjectScanner) Type() string

Type returns the type of the object that was last scanned for.

type PktlineWriter added in v1.5.6

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.6

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.6

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.6

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 v1.5.6

type Ref struct {
	Name string
	Type RefType
	Sha  string
}

A git reference (branch, tag etc)

func AllRefs

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

AllRefs returns a slice of all references in a Git repository in the current working directory, or an error if those references could not be loaded.

func AllRefsIn

func AllRefsIn(wd string) ([]*Ref, error)

AllRefs returns a slice of all references in a Git repository located in a the given working directory "wd", or an error if those references could not be loaded.

func CachedRemoteRefs added in v1.5.6

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

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.5.6

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 ParseRef

func ParseRef(absRef, sha string) *Ref

func RecentBranches added in v1.5.6

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.5.6

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.5.6

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

func (*Ref) Refspec

func (r *Ref) Refspec() string

Refspec returns the fully-qualified reference name (including remote), i.e., for a remote branch called 'my-feature' on remote 'origin', this function will return:

refs/remotes/origin/my-feature

type RefType added in v1.5.6

type RefType int

func ParseRefToTypeAndName added in v1.5.6

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

Get the type & name of a git reference

func (RefType) Prefix

func (t RefType) Prefix() (string, bool)

Prefix returns the given RefType's prefix, "refs/heads", "ref/remotes", etc. It returns an additional value of either true/false, whether or not this given ref type has a prefix.

If the RefType is unrecognized, Prefix() will panic.

type RefUpdate

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

func NewRefUpdate

func NewRefUpdate(g Env, remote string, l, r *Ref) *RefUpdate

func (*RefUpdate) Left

func (u *RefUpdate) Left() *Ref

func (*RefUpdate) LeftCommitish

func (u *RefUpdate) LeftCommitish() string

func (*RefUpdate) Right

func (u *RefUpdate) Right() *Ref

func (*RefUpdate) RightCommitish

func (u *RefUpdate) RightCommitish() string

type Request added in v1.5.6

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.

type RevListOrder

type RevListOrder int

RevListOrder is a constant type that allows for variation in the ordering of revisions given by the *RevListScanner below.

const (
	// DefaultRevListOrder is the zero-value for this type and yields the
	// results as given by git-rev-list(1) without any `--<t>-order`
	// argument given. By default: reverse chronological order.
	DefaultRevListOrder RevListOrder = iota
	// DateRevListOrder gives the revisions such that no parents are shown
	// before children, and otherwise in commit timestamp order.
	DateRevListOrder
	// AuthorDateRevListOrder gives the revisions such that no parents are
	// shown before children, and otherwise in author date timestamp order.
	AuthorDateRevListOrder
	// TopoRevListOrder gives the revisions such that they appear in
	// topological order.
	TopoRevListOrder
)

func (RevListOrder) Flag

func (o RevListOrder) Flag() (string, bool)

Flag returns the command-line flag to be passed to git-rev-list(1) in order to order the output according to the given RevListOrder. It returns both the flag ("--date-order", "--topo-order", etc) and a bool, whether or not to append the flag (for instance, DefaultRevListOrder requires no flag).

Given a type other than those defined above, Flag() will panic().

type RevListScanner

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

RevListScanner is a Scanner type that parses through results of the `git rev-list` command.

func NewRevListScanner

func NewRevListScanner(include, excluded []string, opt *ScanRefsOptions) (*RevListScanner, error)

NewRevListScanner instantiates a new RevListScanner instance scanning all revisions reachable by refs contained in "include" and not reachable by any refs included in "excluded", using the *ScanRefsOptions "opt" configuration.

It returns a new *RevListScanner instance, or an error if one was encountered. Upon returning, the `git-rev-list(1)` instance is already running, and Scan() may be called immediately.

func (*RevListScanner) Close

func (s *RevListScanner) Close() error

Close closes the RevListScanner by freeing any resources held by the instance while running, and returns any error encountered while doing so.

func (*RevListScanner) Err

func (s *RevListScanner) Err() error

Err returns the last encountered error (or nil) after a call to Scan().

It SHOULD be called, checked and handled after a call to Scan().

func (*RevListScanner) Name

func (s *RevListScanner) Name() string

Name is an optional field that gives the name of the object (if the object is a tree, blob).

It can be called before or after Scan(), but will return "" if called before.

func (*RevListScanner) OID

func (s *RevListScanner) OID() []byte

OID is the hex-decoded bytes of the object's ID.

It can be called before or after Scan(), but will return "" if called before.

func (*RevListScanner) Scan

func (s *RevListScanner) Scan() bool

Scan scans the next entry given by git-rev-list(1), and returns true/false indicating if there are more results to scan.

type ScanRefsOptions

type ScanRefsOptions struct {
	// Mode is the scan mode to apply, see above.
	Mode ScanningMode
	// Remote is the current remote to scan against, if using
	// ScanLeftToRemoveMode.
	Remote string
	// SkipDeletedBlobs specifies whether or not to traverse into commit
	// ancestry (revealing potentially deleted (unreferenced) blobs, trees,
	// or commits.
	SkipDeletedBlobs bool
	// Order specifies the order in which revisions are yielded from the
	// output of `git-rev-list(1)`. For more information, see the above
	// documentation on the RevListOrder type.
	Order RevListOrder
	// CommitsOnly specifies whether or not the *RevListScanner should
	// return only commits, or all objects in range by performing a
	// traversal of the graph. By default, false: show all objects.
	CommitsOnly bool
	// WorkingDir specifies the working directory in which to run
	// git-rev-list(1). If this is an empty string, (has len(WorkingDir) ==
	// 0), it is equivalent to running in os.Getwd().
	WorkingDir string
	// Reverse specifies whether or not to give the revisions in reverse
	// order.
	Reverse bool

	// SkippedRefs provides a list of refs to ignore.
	SkippedRefs []string
	// Mutex guards names.
	Mutex *sync.Mutex
	// Names maps Git object IDs (encoded as hex using
	// hex.EncodeString()) to their names, i.e., a directory name
	// (fully-qualified) for trees, or a pathspec for blob tree entries.
	Names map[string]string
}

ScanRefsOptions is an "options" type that is used to configure a scan operation on the `*git.RevListScanner` instance when given to the function `NewRevListScanner()`.

func (*ScanRefsOptions) GetName

func (o *ScanRefsOptions) GetName(sha string) (string, bool)

GetName returns the name associated with a given blob/tree sha and "true" if it exists, or ("", false) if it doesn't.

GetName is guarded by a use of o.Mutex, and is goroutine safe.

func (*ScanRefsOptions) SetName

func (o *ScanRefsOptions) SetName(sha, name string)

SetName sets the name associated with a given blob/tree sha.

SetName is guarded by a use of o.Mutex, and is therefore goroutine safe.

type ScanningMode

type ScanningMode int

ScanningMode is a constant type that allows for variation in the range of commits to scan when given to the `*git.RevListScanner` type.

const (
	// ScanRefsMode will scan between two refspecs.
	ScanRefsMode ScanningMode = iota
	// ScanAllMode will scan all history.
	ScanAllMode
	// ScanLeftToRemoteMode will scan the difference between any included
	// SHA1s and a remote tracking ref.
	ScanLeftToRemoteMode
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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