Documentation ¶
Index ¶
- Constants
- Variables
- func Equals(dr, other DoltRef) bool
- func EqualsStr(dr DoltRef, str string) bool
- func IsRef(str string) bool
- func IsValidBranchName(s string) bool
- func IsValidTagName(tagName string) bool
- func IsWorkingSet(ref string) bool
- func MarshalJSON(dr DoltRef) ([]byte, error)
- func PrefixForType(refType RefType) string
- func String(dr DoltRef) string
- type BranchRef
- type BranchToBranchRefSpec
- type BranchToTrackingBranchRefSpec
- type DoltRef
- type InternalRef
- type MarshalableRef
- type RefSpec
- type RefType
- type RemoteRef
- type RemoteRefSpec
- type TagRef
- type TagToTagRefSpec
- type UpdateMode
- type WorkingSetRef
- type WorkspaceRef
Constants ¶
const WorkingSetRefPrefix = "workingSets"
Variables ¶
var EmptyBranchRef = BranchRef{""}
var ErrInvalidMapping = errors.New("invalid ref spec mapping")
ErrInvalidMapping is the error returned when a refspec tries to do an invalid mapping, such as mapping refs/heads/main to refs/remotes/origin/*
var ErrInvalidRefSpec = errors.New("invalid ref spec")
ErrInvalidRefSpec is the error returned when a refspec isn't syntactically valid
var ErrUnknownRefType = errors.New("unknown ref type")
ErrUnknownRefType is the error returned when parsing a ref in the format refs/type/... where type is unknown
var ErrUnsupportedMapping = errors.New("unsupported mapping")
ErrUnsupportedMapping is returned when trying to do anything other than map local branches (refs/heads/*) to remote tracking branches (refs/remotes/*). As other mappings are added this code will need updating
var ErrWorkingSetUnsupported = errors.New("unsupported type of ref for a working set")
var FastForwardOnly = UpdateMode{false}
var ForceUpdate = UpdateMode{true}
var HeadRefTypes = map[RefType]struct{}{ BranchRefType: {}, RemoteRefType: {}, InternalRefType: {}, TagRefType: {}, WorkspaceRefType: {}, }
HeadRefTypes are the ref types that point to a HEAD and contain a Commit struct. These are the types that are returned by GetHeadRefs. Other ref types don't point to Commits necessarily, so aren't in this list and must be asked for explicitly.
var InvalidBranchNameRegex = regexp.MustCompile(strings.Join([]string{
`[.*]`,
`:`, `\?`, `\[`, `\\`, `\^`, `~`, ` `, `\t`, `\*`,
`[\x00-\x1f]`, `\x7f`,
`\.lock\z`, `\.lock\/`,
`\A\z`, `\AHEAD\z`, `\A-\z`,
`\A[0-9a-v]{32}\z`,
`\.\.`, `@{`,
`\/\/`, `\A\/`, `\/\z`,
}, "|"))
The following list of patterns are all forbidden in a branch name.
var InvalidTagNameRegex = regexp.MustCompile(strings.Join([]string{
`:`, `\?`, `\[`, `\\`, `\^`, `~`, ` `, `\t`, `\*`,
`[\x00-\x1f]`, `\x7f`,
`\.lock\z`, `\.lock\/`,
`\A\z`, `\AHEAD\z`, `\A-\z`,
`\A[0-9a-v]{32}\z`,
`\.\.`, `@{`,
`\/\/`, `\A\/`, `\/\z`,
}, "|"))
The following list of patterns are all forbidden in a tag name.
Functions ¶
func EqualsStr ¶
EqualsStr compares a DoltRef to a reference string to see if they are referring to the same thing
func IsRef ¶
IsRef returns true if the string is a reference string (meanings it starts with the prefix refs/)
func IsValidBranchName ¶
func IsValidTagName ¶
IsValidTagName validates that tagName passes naming constraints.
func IsWorkingSet ¶
IsWorkingSet returns whether the given ref is a working set
func MarshalJSON ¶
MarshalJSON implements the json Marshaler interface to json encode DoltRefs as their string representation
func PrefixForType ¶
PrefixForType returns what a reference string for a given type should start with
Types ¶
type BranchRef ¶
type BranchRef struct {
// contains filtered or unexported fields
}
BranchRef is a reference to a branch
func NewBranchRef ¶
NewBranchRef creates a reference to a local branch from a branch name or a branch ref e.g. main, or refs/heads/main
func (BranchRef) MarshalJSON ¶
type BranchToBranchRefSpec ¶
type BranchToBranchRefSpec struct {
// contains filtered or unexported fields
}
BranchToBranchRefSpec maps one branch to another.
func (BranchToBranchRefSpec) DestRef ¶
func (rs BranchToBranchRefSpec) DestRef(r DoltRef) DoltRef
DestRef verifies the localRef matches the refspecs local pattern, and then maps it to a remote tracking branch, or nil if it does not match the local pattern.
func (BranchToBranchRefSpec) SrcRef ¶
func (rs BranchToBranchRefSpec) SrcRef(cwbRef DoltRef) DoltRef
SrcRef will always determine the DoltRef specified as the source ref regardless to the cwbRef
type BranchToTrackingBranchRefSpec ¶
type BranchToTrackingBranchRefSpec struct {
// contains filtered or unexported fields
}
BranchToTrackingBranchRefSpec maps a branch to the branch that should be tracking it
func (BranchToTrackingBranchRefSpec) DestRef ¶
func (rs BranchToTrackingBranchRefSpec) DestRef(branchRef DoltRef) DoltRef
DestRef verifies the branchRef matches the refspec's local pattern, and then maps it to a remote tracking branch, or to nil if it does not match the pattern.
func (BranchToTrackingBranchRefSpec) GetRemRefToLocal ¶
func (rs BranchToTrackingBranchRefSpec) GetRemRefToLocal() branchMapper
GetRemRefToLocal returns the local tracking branch.
func (BranchToTrackingBranchRefSpec) GetRemote ¶
func (rs BranchToTrackingBranchRefSpec) GetRemote() string
GetRemote returns the name of the remote being operated on.
func (BranchToTrackingBranchRefSpec) SrcRef ¶
func (rs BranchToTrackingBranchRefSpec) SrcRef(cwbRef DoltRef) DoltRef
SrcRef will return the current working branch reference that is passed in as long as the cwbRef matches the source portion of the ref spec
type DoltRef ¶
type DoltRef interface { fmt.Stringer // GetType returns the RefType of this ref GetType() RefType // GetPath returns the identifier for the reference GetPath() string }
DoltRef is a reference to a commit.
func NewInternalRef ¶
NewInternalRef creates an internal ref
func NewRemoteRefFromPathStr ¶
NewRemoteRefFromPathString creates a DoltRef from a string in the format origin/main, or remotes/origin/main, or refs/remotes/origin/main
type InternalRef ¶
type InternalRef struct {
// contains filtered or unexported fields
}
InternalRef is a dolt internal reference
func (InternalRef) GetPath ¶
func (ir InternalRef) GetPath() string
GetPath returns the name of the internal reference
func (InternalRef) GetType ¶
func (ir InternalRef) GetType() RefType
GetType returns InternalRefType
func (InternalRef) String ¶
func (ir InternalRef) String() string
String returns the fully qualified reference e.g. refs/internal/create
type MarshalableRef ¶
type MarshalableRef struct {
Ref DoltRef
}
MarshalableRef is a wrapper that provides the marshaling and unmarshaling of DoltRefs as strings within json.
func (MarshalableRef) MarshalJSON ¶
func (mr MarshalableRef) MarshalJSON() ([]byte, error)
MarshalJSON marshal the ref as a string
func (*MarshalableRef) UnmarshalJSON ¶
func (mr *MarshalableRef) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals the ref from a string
type RefSpec ¶
type RefSpec interface { // SrcRef will take a reference to the current working branch and return a reference to what should be used // for the source reference of an operation involving a reference spec SrcRef(cwbRef DoltRef) DoltRef // DestRef will take a source reference and return a reference to what shat should be used for the destination // reference of an operation involving a reference spec. DestRef(srcRef DoltRef) DoltRef }
RefSpec is an interface for mapping a reference in one space to a reference in another space.
func NewBranchToBranchRefSpec ¶
NewBranchToBranchRefSpec takes a source and destination BranchRef and returns a RefSpec that maps source to dest.
func NewTagToTagRefSpec ¶
NewTagToTagRefSpec takes a source and destination TagRef and returns a RefSpec that maps source to dest.
func ParseRefSpec ¶
ParseRefSpec parses a RefSpec from a string.
func ParseRefSpecForRemote ¶
ParseRefSpecForRemote takes the name of a remote and a refspec, and parses that refspec, verifying that it refers to the appropriate remote
type RefType ¶
type RefType string
RefType is the type of the reference, and this value follows the refPrefix in a ref string. e.g. refs/type/...
const ( // BranchRefType is a reference to a local branch in the format refs/heads/... BranchRefType RefType = "heads" // RemoteRefType is a reference to a local remote tracking branch RemoteRefType RefType = "remotes" // InternalRefType is a reference to a dolt internal commit InternalRefType RefType = "internal" // TagRefType is a reference to commit tag TagRefType RefType = "tags" // WorkspaceRefType is a reference to a workspace WorkspaceRefType RefType = "workspaces" )
type RemoteRef ¶
type RemoteRef struct {
// contains filtered or unexported fields
}
RemoteRef is a reference to a reference that tracks a branch on a remote
func NewRemoteRef ¶
NewRemoteRef creates a remote ref from an origin name and a path
type RemoteRefSpec ¶
RemoteRefSpec is an interface that embeds the RefSpec interface and provides an additional method to get the name of a remote.
type TagRef ¶
type TagRef struct {
// contains filtered or unexported fields
}
func NewTagRef ¶
NewTagRef creates a reference to a local tag from a tag name or a tag ref e.g. v1, or refs/tag/v1
func (TagRef) MarshalJSON ¶
MarshalJSON serializes a TagRef to JSON.
type TagToTagRefSpec ¶
type TagToTagRefSpec struct {
// contains filtered or unexported fields
}
func (TagToTagRefSpec) DestRef ¶
func (rs TagToTagRefSpec) DestRef(r DoltRef) DoltRef
DestRef verifies the localRef matches the refspecs local pattern, and then maps it to a remote tracking branch, or nil if it does not match the local pattern.
func (TagToTagRefSpec) SrcRef ¶
func (rs TagToTagRefSpec) SrcRef(_ DoltRef) DoltRef
SrcRef will always determine the DoltRef specified as the source ref regardless to the cwbRef
type UpdateMode ¶
type UpdateMode struct {
Force bool
}
type WorkingSetRef ¶
type WorkingSetRef struct {
// contains filtered or unexported fields
}
A WorkingSetRef is not a DoltRef, and doesn't live in the |refs/| namespace. But it functions similarly to DoltRefs
func NewWorkingSetRef ¶
func NewWorkingSetRef(workingSetName string) WorkingSetRef
NewWorkingSetRef creates a working set ref from a name or a working set ref e.g. heads/main, or workingSets/heads/main
func WorkingSetRefForHead ¶
func WorkingSetRefForHead(ref DoltRef) (WorkingSetRef, error)
WorkingSetRefForHead returns a new WorkingSetRef for the head ref given, or an error if the ref given doesn't represent a head.
func (WorkingSetRef) GetPath ¶
func (r WorkingSetRef) GetPath() string
GetPath returns the name of the working set
func (WorkingSetRef) String ¶
func (r WorkingSetRef) String() string
String returns the fully qualified reference name e.g. refs/workingSets/my-branch
func (WorkingSetRef) ToHeadRef ¶
func (r WorkingSetRef) ToHeadRef() (DoltRef, error)
type WorkspaceRef ¶
type WorkspaceRef struct {
// contains filtered or unexported fields
}
func NewWorkspaceRef ¶
func NewWorkspaceRef(workspace string) WorkspaceRef
NewWorkspaceRef creates a reference to a local workspace from a workspace name or a workspace ref e.g. my-workspace, or refs/workspace/my-workspace
func (WorkspaceRef) GetPath ¶
func (br WorkspaceRef) GetPath() string
GetPath returns the name of the workspace
func (WorkspaceRef) GetType ¶
func (br WorkspaceRef) GetType() RefType
GetType will return WorkspaceRefType
func (WorkspaceRef) MarshalJSON ¶
func (br WorkspaceRef) MarshalJSON() ([]byte, error)
MarshalJSON serializes a WorkspaceRef to JSON.
func (WorkspaceRef) String ¶
func (br WorkspaceRef) String() string
String returns the fully qualified reference name e.g. refs/workspace/my-workspace