ref

package
v0.40.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const WorkingSetRefPrefix = "workingSets"

Variables

View Source
var EmptyBranchRef = BranchRef{""}
View Source
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/*

View Source
var ErrInvalidRefSpec = errors.New("invalid ref spec")

ErrInvalidRefSpec is the error returned when a refspec isn't syntactically valid

View Source
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

View Source
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

View Source
var ErrWorkingSetUnsupported = errors.New("unsupported type of ref for a working set")
View Source
var FastForwardOnly = UpdateMode{false}
View Source
var ForceUpdate = UpdateMode{true}
View Source
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.

View Source
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.

View Source
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 Equals

func Equals(dr, other DoltRef) bool

Equals returns true if two DoltRefs have the same Type and Path

func EqualsStr

func EqualsStr(dr DoltRef, str string) bool

EqualsStr compares a DoltRef to a reference string to see if they are referring to the same thing

func IsRef

func IsRef(str string) bool

IsRef returns true if the string is a reference string (meanings it starts with the prefix refs/)

func IsValidBranchName

func IsValidBranchName(s string) bool

func IsValidTagName

func IsValidTagName(tagName string) bool

IsValidTagName validates that tagName passes naming constraints.

func IsWorkingSet

func IsWorkingSet(ref string) bool

IsWorkingSet returns whether the given ref is a working set

func MarshalJSON

func MarshalJSON(dr DoltRef) ([]byte, error)

MarshalJSON implements the json Marshaler interface to json encode DoltRefs as their string representation

func PrefixForType

func PrefixForType(refType RefType) string

PrefixForType returns what a reference string for a given type should start with

func String

func String(dr DoltRef) string

String converts the DoltRef to a reference string in the format refs/type/path

Types

type BranchRef

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

BranchRef is a reference to a branch

func NewBranchRef

func NewBranchRef(branchName string) BranchRef

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

func (br BranchRef) GetPath() string

GetPath returns the name of the branch

func (BranchRef) GetType

func (br BranchRef) GetType() RefType

GetType will return BranchRefType

func (BranchRef) MarshalJSON

func (br BranchRef) MarshalJSON() ([]byte, error)

func (BranchRef) String

func (br BranchRef) String() string

String returns the fully qualified reference name e.g. refs/heads/main

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

func NewInternalRef(name string) DoltRef

NewInternalRef creates an internal ref

func NewRemoteRefFromPathStr

func NewRemoteRefFromPathStr(remoteAndPath string) (DoltRef, error)

NewRemoteRefFromPathString creates a DoltRef from a string in the format origin/main, or remotes/origin/main, or refs/remotes/origin/main

func Parse

func Parse(str string) (DoltRef, error)

Parse will parse ref strings and return a DoltRef or an error for refs that can't be parsed. refs without a RefType prefix ("refs/heads/", "refs/tags/", etc) are assumed to be branches)

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

func NewBranchToBranchRefSpec(srcRef, destRef BranchRef) (RefSpec, error)

NewBranchToBranchRefSpec takes a source and destination BranchRef and returns a RefSpec that maps source to dest.

func NewTagToTagRefSpec

func NewTagToTagRefSpec(srcRef, destRef TagRef) (RefSpec, error)

NewTagToTagRefSpec takes a source and destination TagRef and returns a RefSpec that maps source to dest.

func ParseRefSpec

func ParseRefSpec(refSpecStr string) (RefSpec, error)

ParseRefSpec parses a RefSpec from a string.

func ParseRefSpecForRemote

func ParseRefSpecForRemote(remote, refSpecStr string) (RefSpec, error)

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

func NewRemoteRef(remote, branch string) RemoteRef

NewRemoteRef creates a remote ref from an origin name and a path

func (RemoteRef) GetBranch

func (rr RemoteRef) GetBranch() string

GetBranch returns the name of a remote branch

func (RemoteRef) GetPath

func (rr RemoteRef) GetPath() string

GetPath returns the remote name separated by the branch e.g. origin/main

func (RemoteRef) GetRemote

func (rr RemoteRef) GetRemote() string

GetRemote returns the name of the remote that this reference is referring to.

func (RemoteRef) GetType

func (rr RemoteRef) GetType() RefType

GetType returns RemoteRefType

func (RemoteRef) String

func (rr RemoteRef) String() string

String returns the fully qualified reference e.g. refs/remotes/origin/main

type RemoteRefSpec

type RemoteRefSpec interface {
	RefSpec
	GetRemote() string
	GetRemRefToLocal() branchMapper
}

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

func NewTagRef(tagName string) TagRef

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

func (br TagRef) GetPath() string

GetPath returns the name of the tag

func (TagRef) GetType

func (br TagRef) GetType() RefType

GetType will return TagRefType

func (TagRef) MarshalJSON

func (br TagRef) MarshalJSON() ([]byte, error)

MarshalJSON serializes a TagRef to JSON.

func (TagRef) String

func (br TagRef) String() string

String returns the fully qualified reference name e.g. refs/heads/main

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

Jump to

Keyboard shortcuts

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