Documentation ¶
Index ¶
- Constants
- Variables
- func AddTrailer(commitMsg, trailer string) (string, error)
- func BranchBaseName(branch string) string
- func Clone(ctx context.Context, repoUrl, dest string, mirror bool) error
- func DeleteLockFiles(ctx context.Context, workdir string) error
- func Executable(ctx context.Context) (string, error)
- func FullyQualifiedBranchName(branch string) string
- func GetBoolFooterVal(footersMap map[string]string, footer string, issue int64) bool
- func GetFootersMap(commitMsg string) map[string]string
- func GetStringFooterVal(footersMap map[string]string, footer string) string
- func IsCommitHash(s string) bool
- func IsFullCommitHash(s string) bool
- func JoinTrailers(bodyLines, trailers []string) string
- func LogFromTo(from, to string) string
- func MakeFileInfo(name, mode string, typ ObjectType, size int) (fs.FileInfo, error)
- func NormalizeURL(inputURL string) (string, error)
- func ParseDir(contents []byte) ([]fs.FileInfo, error)
- func SplitTrailers(commitMsg string) ([]string, []string)
- type Branch
- type BranchList
- type Checkout
- func (c *Checkout) AddRemote(ctx context.Context, remote, repoUrl string) error
- func (c *Checkout) Cleanup(ctx context.Context) error
- func (c *Checkout) CleanupBranch(ctx context.Context, branch string) error
- func (c *Checkout) Fetch(ctx context.Context) error
- func (c *Checkout) FetchRefFromRepo(ctx context.Context, repo, ref string) error
- func (c *Checkout) IsDirty(ctx context.Context) (bool, string, error)
- func (c *Checkout) Update(ctx context.Context) error
- func (c *Checkout) UpdateBranch(ctx context.Context, branch string) error
- type FS
- type File
- func (f *File) Close(_ context.Context) error
- func (f *File) Read(ctx context.Context, buf []byte) (int, error)
- func (f *File) ReadDir(ctx context.Context, n int) ([]fs.FileInfo, error)
- func (f *File) Stat(ctx context.Context) (fs.FileInfo, error)
- func (f *File) Write(_ context.Context, _ []byte) (int, error)
- type GitDir
- func (g GitDir) Branches(ctx context.Context) ([]*Branch, error)
- func (g GitDir) CatFile(ctx context.Context, ref, path string) ([]byte, error)
- func (g GitDir) Details(ctx context.Context, name string) (*vcsinfo.LongCommit, error)
- func (g GitDir) Dir() string
- func (g GitDir) FullHash(ctx context.Context, ref string) (string, error)
- func (g GitDir) GetBranchHead(ctx context.Context, branchName string) (string, error)
- func (g GitDir) GetFile(ctx context.Context, fileName, commit string) (string, error)
- func (g GitDir) GetRemotes(ctx context.Context) (map[string]string, error)
- func (g GitDir) Git(ctx context.Context, cmd ...string) (string, error)
- func (g GitDir) IsAncestor(ctx context.Context, a, b string) (bool, error)
- func (g GitDir) IsSubmodule(ctx context.Context, path, commit string) (bool, error)
- func (g GitDir) NumCommits(ctx context.Context) (int64, error)
- func (g GitDir) ReadDir(ctx context.Context, ref, path string) ([]os.FileInfo, error)
- func (g GitDir) ReadSubmodule(ctx context.Context, path, commit string) (string, error)
- func (g GitDir) RevList(ctx context.Context, args ...string) ([]string, error)
- func (g GitDir) RevParse(ctx context.Context, args ...string) (string, error)
- func (g GitDir) UpdateSubmodule(ctx context.Context, path, commit string) error
- func (g GitDir) VFS(ctx context.Context, ref string) (*FS, error)
- func (g GitDir) Version(ctx context.Context) (int, int, error)
- type ObjectType
- type Repo
- type TempCheckout
Constants ¶
const ( // MasterBranch is the name of the default branch for most repositories. MasterBranch = git_common.MasterBranch // MainBranch is the name of the default branch for some // repositories which don't use MasterBranch. // TODO(rmistry): Delete this after http://skbug.com/11842 is resolved. MainBranch = git_common.MainBranch // DefaultRef is the fully-qualified ref name of the default branch for most // repositories. DefaultRef = git_common.DefaultRef // DefaultRemote is the name of the default remote repository. DefaultRemote = git_common.DefaultRemote // DefaultRemoteBranch is the name of the default branch in the default // remote repository, for most repos. DefaultRemoteBranch = git_common.DefaultRemoteBranch )
Variables ¶
var ErrorNotFound = skerr.Fmt("file not found")
var ErrorNotSubmodule = skerr.Fmt("not a submodule")
Functions ¶
func AddTrailer ¶
AddTrailer adds a trailer to the given commit message.
func BranchBaseName ¶
BranchBaseName ensures that the branch does not have the refs/heads/ prefix.
func Clone ¶
Clone runs "git clone" into the given destination directory. Most callers should use NewRepo or NewCheckout instead.
func DeleteLockFiles ¶
DeleteLockFiles finds and deletes Git lock files within the given workdir.
func Executable ¶
Executable returns the path to Git.
func FullyQualifiedBranchName ¶
FullyQualifiedBranchName ensures that the branch has the refs/heads/ prefix.
func GetBoolFooterVal ¶
GetBoolFooterVal looks for the specified footer in the footersMap and returns it's boolean value. If the footer is not found then false is returned. If the value is not boolean then false is returned and an error is logged.
func GetFootersMap ¶
GetFootersMap parses the specified commit msg and returns it's footers. Invalid footer formats are logged. Eg: commit msg: "test test\n\nBug: skia:123\nTested: true" will return {"skia": "123", "Tested": "true"}.
func GetStringFooterVal ¶
GetStringFooterVal looks for the specified footer in the footersMap and returns it's strings value. If the footer is not found then an empty string is returned.
func IsCommitHash ¶
IsCommitHash returns true if the given string looks like a valid (possibly shortened) Git commit hash.
func IsFullCommitHash ¶
IsFullCommitHash returns true if the given string looks like a full 40- character Git commit hash.
func JoinTrailers ¶
JoinTrailers joins a main commit message body with a trailers footer.
func LogFromTo ¶
LogFromTo returns a string which is used to log from one commit to another. It is important to note that:
- The results may include the second commit but will not include the first.
- The results include all commits reachable from the first commit which are not reachable from the second, ie. if there is a merge in the given range, the results will include that line of history and not just the commits which are descendants of the first commit. If you want only commits which are ancestors of the second commit AND descendants of the first, you should use LogLinear, but note that the results will be empty if the first commit is not an ancestor of the second, ie. they're on different branches.
func MakeFileInfo ¶
MakeFileInfo returns an fs.FileInfo with the given information.
func NormalizeURL ¶
NormalizeURL strips everything from the URL except for the host and the path. A trailing ".git" is also stripped. The purpose is to allow for small variations in repo URL to be recognized as the same repo. The URL needs to contain a valid transport protocol, e.g. https, ssh. These URLs will all return 'github.com/skia-dev/textfiles':
"https://github.com/skia-dev/textfiles.git" "ssh://git@github.com/skia-dev/textfiles" "ssh://git@github.com:skia-dev/textfiles.git"
func ParseDir ¶
ParseDir parses the contents of a directory. Expects the contents to be in the format used by git, ie. lines taking the form:
mode tree|blob hash name
func SplitTrailers ¶
SplitTrailers splits a commit message into a main commit message body and trailers footer. Assumes that the commit message is already well-formed with respect to trailers, ie. there is an empty line between the last body paragraph and the single trailers paragraph, which contains only lines in "key: value" format.
Types ¶
type Branch ¶
type Branch struct { // The human-readable name of the branch. Name string `json:"name"` // The commit hash pointed to by this branch. Head string `json:"head"` }
Branch describes a Git branch.
type BranchList ¶
type BranchList []*Branch
BranchList is a slice of Branch objects which implements sort.Interface.
func (BranchList) Len ¶
func (bl BranchList) Len() int
func (BranchList) Less ¶
func (bl BranchList) Less(a, b int) bool
func (BranchList) Swap ¶
func (bl BranchList) Swap(a, b int)
type Checkout ¶
type Checkout struct {
GitDir
}
Checkout is a struct used for managing a local git checkout.
func NewCheckout ¶
NewCheckout returns a Checkout instance based in the given working directory. Uses any existing checkout in the given directory, or clones one if necessary. In general, servers should use Repo instead of Checkout unless it is absolutely necessary to have a working copy.
func (*Checkout) AddRemote ¶
AddRemote checks to see if a remote already exists in the checkout, if it exists then the URL is matched with the repoURL. If the remote does not exist then it is added.
func (*Checkout) Cleanup ¶
Cleanup forcibly resets all changes and checks out the main branch to match that of the remote. All local changes will be lost.
func (*Checkout) CleanupBranch ¶
CleanupBranch forcibly resets all changes and checks out the given branch, forcing it to match the same branch from origin. All local changes will be lost.
func (*Checkout) FetchRefFromRepo ¶
FetchRefFromRepo syncs the specified ref from the repo without modifying the working copy.
func (*Checkout) IsDirty ¶
IsDirty returns true if the Checkout is dirty, ie. any of the following are true: 1. There are unstaged changes. 2. There are untracked files (not including .gitignore'd files). 3. HEAD is not an ancestor of origin/main.
Also returns the output of "git status", for human consumption if desired.
func (*Checkout) Update ¶
Update syncs the Checkout from its remote. Forcibly resets and checks out the main branch to match the remote. All local changes will be lost. Equivalent to c.Fetch() + c.Cleanup().
func (*Checkout) UpdateBranch ¶
UpdateBranch syncs the Checkout from its remote. Forcibly resets and checks out the given branch, forcing it to match the same branch from origin. All local changes will be lost. Equivalent to c.Fetch() + c.CleanupBranch().
type FS ¶
type FS struct {
// contains filtered or unexported fields
}
FS implements vfs.FS using Git for a particular revision.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File implements vfs.File using Git for a particular revision.
type GitDir ¶
type GitDir string
GitDir is a directory in which one may run Git commands.
func (GitDir) Details ¶
Details returns a vcsinfo.LongCommit instance representing the given commit.
func (GitDir) GetBranchHead ¶
GetBranchHead returns the commit hash at the HEAD of the given branch.
func (GitDir) GetRemotes ¶
GetRemotes returns a mapping of remote repo name to URL.
func (GitDir) IsAncestor ¶
IsAncestor returns true iff A is an ancestor of B.
func (GitDir) IsSubmodule ¶
IsSubmodule returns true if the given path is submodule, ie contains gitlink.
func (GitDir) NumCommits ¶
NumCommits returns the number of commits in the repo.
func (GitDir) ReadSubmodule ¶
ReadSubmodule returns commit hash of the given path, if the path is git submodule. ErrorNotFound is returned if path is not found in the git worktree. ErrorNotSubmodule is returned if path exists, but it's not a submodule.
func (GitDir) UpdateSubmodule ¶
UpdateSubmodule updates git submodule of the given path to the given commit. If submodule doesn't exist, it returns ErrorNotFound since it doesn't have all necessary information to create a valid submodule (requires an entry in .gitmodules).
type ObjectType ¶
type ObjectType string
ObjectType represents a Git object type.
const ( ObjectTypeBlob ObjectType = "blob" ObjectTypeCommit ObjectType = "commit" ObjectTypeTree ObjectType = "tree" )
Types of git objects.
type Repo ¶
type Repo struct {
GitDir
}
Repo is a struct used for managing a local git repo.
func NewRepo ¶
NewRepo returns a Repo instance based in the given working directory. Uses any existing repo in the given directory, or clones one if necessary. Only creates bare clones; Repo does not maintain a checkout.
func (*Repo) TempCheckout ¶
func (r *Repo) TempCheckout(ctx context.Context) (*TempCheckout, error)
TempCheckout returns a TempCheckout of the repo.
type TempCheckout ¶
type TempCheckout struct {
*Checkout
}
TempCheckout is a temporary Git Checkout.
func NewTempCheckout ¶
func NewTempCheckout(ctx context.Context, repoUrl string) (*TempCheckout, error)
NewTempCheckout returns a TempCheckout instance. Creates a temporary directory and then clones the repoUrl into a subdirectory, based on default "git clone" behavior.
func (*TempCheckout) Delete ¶
func (c *TempCheckout) Delete()
Delete removes the TempCheckout's working directory.
Directories ¶
Path | Synopsis |
---|---|
Package gitinfo enables querying info from Git repository using git and a local checkout.
|
Package gitinfo enables querying info from Git repository using git and a local checkout. |