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
- type CheckoutDir
- func (c CheckoutDir) AddRemote(ctx context.Context, remote, repoUrl string) error
- func (c CheckoutDir) Branches(ctx context.Context) ([]*Branch, error)
- func (c CheckoutDir) CatFile(ctx context.Context, ref, path string) ([]byte, error)
- func (c CheckoutDir) Cleanup(ctx context.Context) error
- func (c CheckoutDir) CleanupBranch(ctx context.Context, branch string) error
- func (c CheckoutDir) Details(ctx context.Context, name string) (*vcsinfo.LongCommit, error)
- func (c CheckoutDir) Dir() string
- func (c CheckoutDir) Fetch(ctx context.Context) error
- func (c CheckoutDir) FetchRefFromRepo(ctx context.Context, repo, ref string) error
- func (c CheckoutDir) FullHash(ctx context.Context, ref string) (string, error)
- func (c CheckoutDir) GetBranchHead(ctx context.Context, branchName string) (string, error)
- func (c CheckoutDir) GetFile(ctx context.Context, fileName, commit string) (string, error)
- func (c CheckoutDir) GetRemotes(ctx context.Context) (map[string]string, error)
- func (c CheckoutDir) Git(ctx context.Context, cmd ...string) (string, error)
- func (c CheckoutDir) IsAncestor(ctx context.Context, a, b string) (bool, error)
- func (c CheckoutDir) IsDirty(ctx context.Context) (bool, string, error)
- func (c CheckoutDir) IsSubmodule(ctx context.Context, path, commit string) (bool, error)
- func (c CheckoutDir) NumCommits(ctx context.Context) (int64, error)
- func (c CheckoutDir) ReadDir(ctx context.Context, ref, path string) ([]os.FileInfo, error)
- func (c CheckoutDir) ReadSubmodule(ctx context.Context, path, commit string) (string, error)
- func (c CheckoutDir) RevList(ctx context.Context, args ...string) ([]string, error)
- func (c CheckoutDir) RevParse(ctx context.Context, args ...string) (string, error)
- func (c CheckoutDir) Update(ctx context.Context) error
- func (c CheckoutDir) UpdateBranch(ctx context.Context, branch string) error
- func (c CheckoutDir) UpdateSubmodule(ctx context.Context, path, commit string) error
- func (c CheckoutDir) VFS(ctx context.Context, ref string) (*FS, error)
- func (c CheckoutDir) Version(ctx context.Context) (int, int, 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
- type ObjectType
- type Repo
- type RepoDir
- func (r RepoDir) Branches(ctx context.Context) ([]*Branch, error)
- func (r RepoDir) CatFile(ctx context.Context, ref, path string) ([]byte, error)
- func (r RepoDir) Checkout(ctx context.Context, workdir string) (CheckoutDir, error)
- func (r RepoDir) Details(ctx context.Context, name string) (*vcsinfo.LongCommit, error)
- func (r RepoDir) Dir() string
- func (r RepoDir) FullHash(ctx context.Context, ref string) (string, error)
- func (r RepoDir) GetBranchHead(ctx context.Context, branchName string) (string, error)
- func (r RepoDir) GetFile(ctx context.Context, fileName, commit string) (string, error)
- func (r RepoDir) GetRemotes(ctx context.Context) (map[string]string, error)
- func (r RepoDir) Git(ctx context.Context, cmd ...string) (string, error)
- func (r RepoDir) IsAncestor(ctx context.Context, a, b string) (bool, error)
- func (r RepoDir) IsSubmodule(ctx context.Context, path, commit string) (bool, error)
- func (r RepoDir) NumCommits(ctx context.Context) (int64, error)
- func (r RepoDir) ReadDir(ctx context.Context, ref, path string) ([]os.FileInfo, error)
- func (r RepoDir) ReadSubmodule(ctx context.Context, path, commit string) (string, error)
- func (r RepoDir) RevList(ctx context.Context, args ...string) ([]string, error)
- func (r RepoDir) RevParse(ctx context.Context, args ...string) (string, error)
- func (r RepoDir) TempCheckout(ctx context.Context) (*TempCheckout, error)
- func (r RepoDir) Update(ctx context.Context) error
- func (r RepoDir) UpdateSubmodule(ctx context.Context, path, commit string) error
- func (r RepoDir) VFS(ctx context.Context, ref string) (*FS, error)
- func (r RepoDir) Version(ctx context.Context) (int, int, error)
- 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 interface { GitDir // FetchRefFromRepo syncs the specified ref from the repo without modifying the // working copy. FetchRefFromRepo(ctx context.Context, repo, ref string) error // Fetch syncs refs from the remote without modifying the working copy. Fetch(ctx context.Context) error // 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. AddRemote(ctx context.Context, remote, repoUrl string) error // 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. CleanupBranch(ctx context.Context, branch string) error // Cleanup forcibly resets all changes and checks out the main branch to match // that of the remote. All local changes will be lost. Cleanup(ctx context.Context) error // 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(). UpdateBranch(ctx context.Context, branch string) error // 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(). Update(ctx context.Context) error // 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. IsDirty(ctx context.Context) (bool, string, error) }
Checkout is used for managing a local git checkout.
type CheckoutDir ¶
type CheckoutDir string
CheckoutDir implements Checkout.
func NewCheckout ¶
func NewCheckout(ctx context.Context, repoUrl, workdir string) (CheckoutDir, error)
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 (CheckoutDir) AddRemote ¶
func (c CheckoutDir) AddRemote(ctx context.Context, remote, repoUrl string) error
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 (CheckoutDir) Branches ¶
func (c CheckoutDir) Branches(ctx context.Context) ([]*Branch, error)
Branches runs "git branch" and returns a slice of Branch instances.
func (CheckoutDir) Cleanup ¶
func (c CheckoutDir) Cleanup(ctx context.Context) error
Cleanup forcibly resets all changes and checks out the main branch to match that of the remote. All local changes will be lost.
func (CheckoutDir) CleanupBranch ¶
func (c CheckoutDir) CleanupBranch(ctx context.Context, branch string) error
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 (CheckoutDir) Details ¶
func (c CheckoutDir) Details(ctx context.Context, name string) (*vcsinfo.LongCommit, error)
Details returns a vcsinfo.LongCommit instance representing the given commit.
func (CheckoutDir) Dir ¶
func (c CheckoutDir) Dir() string
Dir returns the working directory of the GitDir.
func (CheckoutDir) Fetch ¶
func (c CheckoutDir) Fetch(ctx context.Context) error
Fetch syncs refs from the remote without modifying the working copy.
func (CheckoutDir) FetchRefFromRepo ¶
func (c CheckoutDir) FetchRefFromRepo(ctx context.Context, repo, ref string) error
FetchRefFromRepo syncs the specified ref from the repo without modifying the working copy.
func (CheckoutDir) GetBranchHead ¶
GetBranchHead returns the commit hash at the HEAD of the given branch.
func (CheckoutDir) GetRemotes ¶
GetRemotes returns a mapping of remote repo name to URL.
func (CheckoutDir) IsAncestor ¶
IsAncestor returns true iff A is an ancestor of B.
func (CheckoutDir) 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 (CheckoutDir) IsSubmodule ¶
IsSubmodule returns true if the given path is submodule, ie contains gitlink.
func (CheckoutDir) NumCommits ¶
func (c CheckoutDir) NumCommits(ctx context.Context) (int64, error)
NumCommits returns the number of commits in the repo.
func (CheckoutDir) 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 (CheckoutDir) RevList ¶
RevList runs "git rev-list <name>" and returns a slice of commit hashes.
func (CheckoutDir) Update ¶
func (c CheckoutDir) Update(ctx context.Context) error
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 (CheckoutDir) UpdateBranch ¶
func (c CheckoutDir) UpdateBranch(ctx context.Context, branch string) error
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().
func (CheckoutDir) UpdateSubmodule ¶
func (c CheckoutDir) UpdateSubmodule(ctx context.Context, path, commit string) error
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 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 interface { // Dir returns the working directory of the GitDir. Dir() string // Git runs the given git command in the GitDir. Git(ctx context.Context, cmd ...string) (string, error) // Details returns a vcsinfo.LongCommit instance representing the given commit. Details(ctx context.Context, name string) (*vcsinfo.LongCommit, error) // RevParse runs "git rev-parse <name>" and returns the result. RevParse(ctx context.Context, args ...string) (string, error) // RevList runs "git rev-list <name>" and returns a slice of commit hashes. RevList(ctx context.Context, args ...string) ([]string, error) // GetBranchHead returns the commit hash at the HEAD of the given branch. GetBranchHead(ctx context.Context, branchName string) (string, error) // Branches runs "git branch" and returns a slice of Branch instances. Branches(ctx context.Context) ([]*Branch, error) // GetFile returns the contents of the given file at the given commit. GetFile(ctx context.Context, fileName, commit string) (string, error) // IsSubmodule returns true if the given path is submodule, ie contains gitlink. IsSubmodule(ctx context.Context, path, commit string) (bool, error) // 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. ReadSubmodule(ctx context.Context, path, commit string) (string, error) // 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). UpdateSubmodule(ctx context.Context, path, commit string) error // NumCommits returns the number of commits in the repo. NumCommits(ctx context.Context) (int64, error) // IsAncestor returns true iff A is an ancestor of B. IsAncestor(ctx context.Context, a, b string) (bool, error) // Version returns the Git version. Version(ctx context.Context) (int, int, error) // FullHash gives the full commit hash for the given ref. FullHash(ctx context.Context, ref string) (string, error) // CatFile runs "git cat-file -p <ref>:<path>". CatFile(ctx context.Context, ref, path string) ([]byte, error) // ReadDir is analogous to os.File.Readdir for a particular ref. ReadDir(ctx context.Context, ref, path string) ([]os.FileInfo, error) // GetRemotes returns a mapping of remote repo name to URL. GetRemotes(ctx context.Context) (map[string]string, error) // VFS returns a vfs.FS using Git for the given revision. VFS(ctx context.Context, ref string) (*FS, error) }
GitDir is a directory in which one may run Git commands.
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 interface { GitDir // Update syncs the Repo from its remote. Update(ctx context.Context) error // Checkout returns a Checkout of the Repo in the given working directory. Checkout(ctx context.Context, workdir string) (CheckoutDir, error) // TempCheckout returns a TempCheckout of the repo. TempCheckout(ctx context.Context) (*TempCheckout, error) }
Repo is used for managing a local git repo, without a working copy.
type RepoDir ¶
type RepoDir string
RepoDir implements 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 (RepoDir) Details ¶
Details returns a vcsinfo.LongCommit instance representing the given commit.
func (RepoDir) GetBranchHead ¶
GetBranchHead returns the commit hash at the HEAD of the given branch.
func (RepoDir) GetRemotes ¶
GetRemotes returns a mapping of remote repo name to URL.
func (RepoDir) IsAncestor ¶
IsAncestor returns true iff A is an ancestor of B.
func (RepoDir) IsSubmodule ¶
IsSubmodule returns true if the given path is submodule, ie contains gitlink.
func (RepoDir) NumCommits ¶
NumCommits returns the number of commits in the repo.
func (RepoDir) 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 (RepoDir) TempCheckout ¶
func (r RepoDir) TempCheckout(ctx context.Context) (*TempCheckout, error)
TempCheckout returns a TempCheckout of the repo.
func (RepoDir) 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 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. |