Documentation
¶
Overview ¶
Package branch defines local branch lifecycle operations.
Index ¶
- Variables
- func ValidateSource(source Source) error
- type CreateRequest
- type CreateResult
- type DeleteRequest
- type DeleteResult
- type ListResult
- type Service
- func (s Service) Create(ctx context.Context, request CreateRequest) (CreateResult, error)
- func (s Service) Delete(ctx context.Context, request DeleteRequest) (DeleteResult, error)
- func (s Service) List(ctx context.Context) (ListResult, error)
- func (s Service) Switch(ctx context.Context, request SwitchRequest) (SwitchResult, error)
- type Source
- type Store
- type SwitchRequest
- type SwitchResult
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRequired reports a missing branch selector. ErrRequired = errors.New("branch is required") // ErrMissingSource reports a branch creation source with neither branch nor commit. ErrMissingSource = errors.New("branch source is required") // ErrAmbiguousSource reports a source that names both a branch and commit. ErrAmbiguousSource = errors.New("branch source must identify a branch or commit, not both") // ErrSourceNotFound reports a requested branch-creation source that does not exist. ErrSourceNotFound = errors.New("branch source not found") // ErrAlreadyExists reports an attempt to create an existing branch. ErrAlreadyExists = errors.New("branch already exists") // ErrNotFound reports a requested branch that does not exist. ErrNotFound = errors.New("branch not found") // ErrDefaultProtected reports an attempt to delete the default branch. ErrDefaultProtected = errors.New("default branch cannot be deleted") // ErrActiveProtected reports an attempt to delete the active branch. ErrActiveProtected = errors.New("active branch cannot be deleted") )
Functions ¶
func ValidateSource ¶
ValidateSource requires source to identify exactly one branch or commit.
Types ¶
type CreateRequest ¶
type CreateRequest struct {
// Name is the new branch name.
Name string `json:"name"`
// Source identifies the branch or commit from which to create Name.
Source Source `json:"source"`
}
CreateRequest describes a new branch and its required source.
type CreateResult ¶
type CreateResult struct {
// Name is the created branch name.
Name string `json:"name"`
// Commit is the source commit assigned to Name.
Commit string `json:"commit"`
}
CreateResult identifies the created branch and its initial commit.
type DeleteRequest ¶
type DeleteRequest struct {
// Name is the branch name.
Name string `json:"name"`
}
DeleteRequest identifies a branch to delete.
type DeleteResult ¶
type DeleteResult struct {
// Name is the deleted branch name.
Name string `json:"name"`
}
DeleteResult identifies the deleted branch.
type ListResult ¶
type ListResult struct {
// Branches is the list of branch names.
Branches []string `json:"branches"`
}
ListResult contains lexically ordered branch names.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service validates branch lifecycle requests and delegates durable operations to Store.
func NewService ¶
NewService returns a branch service backed by store.
func (Service) Create ¶
func (s Service) Create(ctx context.Context, request CreateRequest) (CreateResult, error)
Create validates request source, honors cancellation, and creates the branch through Store.
func (Service) Delete ¶
func (s Service) Delete(ctx context.Context, request DeleteRequest) (DeleteResult, error)
Delete honors cancellation and delegates deletion to Store.
func (Service) List ¶
func (s Service) List(ctx context.Context) (ListResult, error)
List honors cancellation and returns branches from Store.
func (Service) Switch ¶
func (s Service) Switch(ctx context.Context, request SwitchRequest) (SwitchResult, error)
Switch honors cancellation and delegates branch activation to Store.
type Source ¶
type Source struct {
// Branch identifies an existing branch source.
Branch string `json:"branch,omitempty"`
// Commit identifies an existing commit source.
Commit string `json:"commit,omitempty"`
}
Source identifies the existing branch or commit from which to create a branch.
type Store ¶
type Store interface {
// CreateBranch atomically creates a branch at its validated source.
CreateBranch(name string, source Source) (CreateResult, error)
// ListBranches returns the repository's branch names.
ListBranches() (ListResult, error)
// DeleteBranch atomically removes a branch when repository policy permits.
DeleteBranch(name string) (DeleteResult, error)
// SwitchBranch atomically selects an existing branch as active.
SwitchBranch(name string) (SwitchResult, error)
}
Store provides the atomic persistence operation required for branch creation.
type SwitchRequest ¶
type SwitchRequest struct {
// Name is the branch name.
Name string `json:"name"`
}
SwitchRequest identifies the branch to make active.
type SwitchResult ¶
type SwitchResult struct {
// ActiveBranch is the branch made active.
ActiveBranch string `json:"activeBranch"`
}
SwitchResult identifies the active branch after a successful switch.