Documentation ¶
Overview ¶
Package ginternals contains objects and methods to work on git internals
Index ¶
- Constants
- Variables
- func ConfigPath(cfg *config.Config) string
- func DescriptionFilePath(cfg *config.Config) string
- func DotGitPath(cfg *config.Config) string
- func IsRefNameValid(name string) bool
- func LocalBranchFullName(shortName string) string
- func LocalBranchShortName(fullName string) string
- func LocalBranchesPath(cfg *config.Config) string
- func LocalTagFullName(shortName string) string
- func LocalTagShortName(fullName string) string
- func LooseObjectPath(cfg *config.Config, sha string) string
- func ObjectsInfoPath(cfg *config.Config) string
- func ObjectsPacksPath(cfg *config.Config) string
- func ObjectsPath(cfg *config.Config) string
- func PackedRefsPath(cfg *config.Config) string
- func PackfilePath(cfg *config.Config, name string) string
- func RefFullName(shortName string) string
- func RefPath(cfg *config.Config, name string) string
- func RefsPath(cfg *config.Config) string
- func TagsPath(cfg *config.Config) string
- type Oid
- type RefContent
- type Reference
- type ReferenceType
Constants ¶
const ( // Head is a reference to the current branch, or to a commit if // we're detached Head = "HEAD" // OrigHead is a backup reference of HEAD set during destructive commands // such as rebase, merge, etc. and can be used to revert an operation OrigHead = "ORIG_HEAD" // MergeHead is a reference to the commit that is being merged // into the current branch MergeHead = "MERGE_HEAD" // CherryPickHead is a reference to the commit that is being // cherry-picked CherryPickHead = "CHERRY_PICK_HEAD" // Master correspond to the default branch name if none was // specified Master = "master" )
Common ref names
const (
// OidSize is the length of an oid, in bytes
OidSize = 20
)
Variables ¶
var ( // NullOid is the value of an empty Oid, or one that's all 0s NullOid = Oid{} // ErrInvalidOid is returned when a given value isn't a valid Oid ErrInvalidOid = errors.New("invalid Oid") )
var ( // ErrRefNotFound is an error thrown when trying to act on a // reference that doesn't exists ErrRefNotFound = errors.New("reference not found") // ErrRefExists is an error thrown when trying to act on a // reference that should not exist, but does ErrRefExists = errors.New("reference already exists") // ErrRefNameInvalid is an error thrown when the name of a reference // is not valid ErrRefNameInvalid = errors.New("reference name is not valid") // ErrRefInvalid is an error thrown when a reference is not valid ErrRefInvalid = errors.New("reference is not valid") // ErrPackedRefInvalid is an error thrown when the packed-refs // file cannot be parsed properly ErrPackedRefInvalid = errors.New("packed-refs file is invalid") // ErrUnknownRefType is an error thrown when the type of a reference // is unknown ErrUnknownRefType = errors.New("unknown reference type") )
var ErrObjectNotFound = errors.New("object not found")
ErrObjectNotFound is an error corresponding to a git object not being found
Functions ¶
func ConfigPath ¶
ConfigPath returns the path to the local config file
func DescriptionFilePath ¶
DescriptionFilePath returns the path to the description file
func DotGitPath ¶
DotGitPath returns the path to the dotgit directory
func IsRefNameValid ¶
IsRefNameValid returns whether the name of a reference is valid or not https://stackoverflow.com/a/12093994/382879
func LocalBranchFullName ¶
LocalBranchFullName returns the full name of branch ex. for `main` returns `refs/heads/main`
func LocalBranchShortName ¶
LocalBranchShortName returns the short name of a branch ex. for `refs/heads/main` returns `main`
func LocalBranchesPath ¶
LocalBranchesPath returns the path to the directory containing the local branches
func LocalTagFullName ¶
LocalTagFullName returns the full name of a tag ex. for `my-tag` returns `refs/tags/my-tag`
func LocalTagShortName ¶
LocalTagShortName returns the short name of a tag ex. for refs/tags/my-tag returns my-tag
func LooseObjectPath ¶
LooseObjectPath returns the path of a loose object. Path is .git/objects/first_2_chars_of_sha/remaining_chars_of_sha
Ex. path of fcfe68a0e44e04bd7fd564fc0b75f1ae457e18b3 is: .git/objects/fc/fe68a0e44e04bd7fd564fc0b75f1ae457e18b3
func ObjectsInfoPath ¶
ObjectsInfoPath returns the path to the directory that contains the info about the objects
func ObjectsPacksPath ¶
ObjectsPacksPath returns the path to the directory that contains the packfiles
func ObjectsPath ¶
ObjectsPath returns the path to the directory that contains the object
func PackedRefsPath ¶
PackedRefsPath return the local path of a the packed-refs file
func PackfilePath ¶
PackfilePath returns the path of a packfiles
func RefFullName ¶
RefFullName returns the UNIX path of a ref
Types ¶
type Oid ¶
Oid represents an object id
func NewOidFromChars ¶
NewOidFromChars creates an Oid from the given char bytes For the SHA {'9', 'b', '9', '1', 'd', 'a', ...} the oid will be {0x9b, 0x91, 0xda, ...}
func NewOidFromContent ¶
NewOidFromContent returns the Oid of the given content. The oid will be the SHA1 sum of the content
func NewOidFromHex ¶
NewOidFromHex returns an Oid from the provided byte-encoded oid This basically cast a slice that contains an encoded oid into a Oid object
func NewOidFromStr ¶
NewOidFromStr creates an Oid from the given string For the SHA 9b91da06e69613397b38e0808e0ba5ee6983251b the oid will be {0x9b, 0x91, 0xda, ...}
func (Oid) Bytes ¶
Bytes returns the raw Oid as []byte. This is different than doing []byte(oid.String()) For the oid 642480605b8b0fd464ab5762e044269cf29a60a3: oid.Bytes(): []byte{ 0x64, 0x24, 0x80, ... } []byte(oid.String()): []byte{ '6', '4', '2', '4', '8' '0', ... }
type RefContent ¶
RefContent represents a method that returns the content of reference This is used so we can do the process here, without depending on a specific backend or having circular dependencies
type Reference ¶
type Reference struct {
// contains filtered or unexported fields
}
Reference represents a git reference https://git-scm.com/book/en/v2/Git-Internals-Git-References
func NewReference ¶
NewReference return a new Reference object that targets an object
func NewSymbolicReference ¶
NewSymbolicReference return a new Reference object that targets another reference. Example HEAD targeting heads/master
func ResolveReference ¶
func ResolveReference(name string, finder RefContent) (*Reference, error)
ResolveReference resolves symbolic references
func (*Reference) SymbolicTarget ¶
SymbolicTarget returns the symbolic target of a reference
func (*Reference) Type ¶
func (ref *Reference) Type() ReferenceType
Type returns the type of a reference
type ReferenceType ¶
type ReferenceType int8
ReferenceType represents the type of a reference
const ( // OidReference represents a reference that targets an Oid OidReference ReferenceType = 1 // SymbolicReference represents a reference that targets another // reference SymbolicReference ReferenceType = 2 )
Directories ¶
Path | Synopsis |
---|---|
Package config contains structs to interact with git configuration as well as to configure the library
|
Package config contains structs to interact with git configuration as well as to configure the library |
Package object contains methods and objects to work with git objects
|
Package object contains methods and objects to work with git objects |
Package packfile contains methods and structs to read and write packfiles
|
Package packfile contains methods and structs to read and write packfiles |