Documentation ¶
Overview ¶
Package domain provides strong type support for modeling the domain of Git Town. This helps lean on the typesystem to prevent bugs, stringly-typed code, and primitive obsession and improve maintainability.
Index ¶
- Variables
- type BranchInfo
- func (self BranchInfo) HasLocalBranch() bool
- func (self BranchInfo) HasOnlyLocalBranch() bool
- func (self BranchInfo) HasOnlyRemoteBranch() bool
- func (self BranchInfo) HasRemoteBranch() bool
- func (self BranchInfo) HasTrackingBranch() bool
- func (self BranchInfo) IsEmpty() bool
- func (self BranchInfo) IsLocal() bool
- func (self BranchInfo) IsOmniBranch() bool
- type BranchInfos
- func (self BranchInfos) FindByLocalName(branchName LocalBranchName) *BranchInfo
- func (self BranchInfos) FindByRemoteName(remoteBranch RemoteBranchName) *BranchInfo
- func (self BranchInfos) FindMatchingRecord(other BranchInfo) BranchInfo
- func (self BranchInfos) HasLocalBranch(localBranch LocalBranchName) bool
- func (self BranchInfos) HasMatchingTrackingBranchFor(localBranch LocalBranchName) bool
- func (self BranchInfos) LocalBranches() BranchInfos
- func (self BranchInfos) LocalBranchesWithDeletedTrackingBranches() BranchInfos
- func (self BranchInfos) Names() LocalBranchNames
- func (self BranchInfos) Remove(branchName LocalBranchName) BranchInfos
- func (self BranchInfos) Select(names []LocalBranchName) (BranchInfos, error)
- func (self BranchInfos) UpdateLocalSHA(branch LocalBranchName, sha SHA) error
- type BranchName
- type BranchTypes
- type Branches
- type BranchesSnapshot
- type Change
- type InconsistentChange
- type InconsistentChanges
- type LocalBranchChange
- type LocalBranchName
- func (self LocalBranchName) AtRemote(remote Remote) RemoteBranchName
- func (self LocalBranchName) BranchName() BranchName
- func (self LocalBranchName) IsEmpty() bool
- func (self LocalBranchName) Location() Location
- func (self LocalBranchName) String() string
- func (self LocalBranchName) TrackingBranch() RemoteBranchName
- type LocalBranchNames
- func (self LocalBranchNames) Categorize(branchTypes BranchTypes) (perennials, features LocalBranchNames)
- func (self LocalBranchNames) Hoist(needle LocalBranchName) LocalBranchNames
- func (self LocalBranchNames) Join(sep string) string
- func (self LocalBranchNames) Remove(toRemove LocalBranchName) LocalBranchNames
- func (self LocalBranchNames) RemoveWorkspaceMarkers() LocalBranchNames
- func (self LocalBranchNames) Sort()
- func (self LocalBranchNames) Strings() []string
- type LocalBranchesSHAs
- type Location
- type Proposal
- type Remote
- type RemoteBranchChange
- type RemoteBranchName
- func (self RemoteBranchName) BranchName() BranchName
- func (self RemoteBranchName) IsEmpty() bool
- func (self RemoteBranchName) LocalBranchName() LocalBranchName
- func (self RemoteBranchName) Parts() (Remote, LocalBranchName)
- func (self RemoteBranchName) Remote() Remote
- func (self RemoteBranchName) String() string
- type RemoteBranchNames
- type RemoteBranchesSHAs
- type Remotes
- type RepoRootDir
- type RepoStatus
- type SHA
- type SHAs
- type StashSnapshot
- type SyncStatus
Constants ¶
This section is empty.
Variables ¶
var ( NoRemote = NewRemote("") //nolint:gochecknoglobals OriginRemote = NewRemote("origin") //nolint:gochecknoglobals UpstreamRemote = NewRemote("upstream") //nolint:gochecknoglobals )
Functions ¶
This section is empty.
Types ¶
type BranchInfo ¶
type BranchInfo struct { // LocalName contains the local name of the branch. LocalName LocalBranchName // LocalSHA contains the SHA that this branch had locally before Git Town ran. LocalSHA SHA // SyncStatus of the branch SyncStatus SyncStatus // RemoteName contains the fully qualified name of the tracking branch, i.e. "origin/foo". RemoteName RemoteBranchName // RemoteSHA contains the SHA of the tracking branch before Git Town ran. RemoteSHA SHA }
BranchInfo describes the sync status of a branch in relation to its tracking branch.
func EmptyBranchInfo ¶
func EmptyBranchInfo() BranchInfo
func (BranchInfo) HasLocalBranch ¶
func (self BranchInfo) HasLocalBranch() bool
func (BranchInfo) HasOnlyLocalBranch ¶
func (self BranchInfo) HasOnlyLocalBranch() bool
func (BranchInfo) HasOnlyRemoteBranch ¶
func (self BranchInfo) HasOnlyRemoteBranch() bool
func (BranchInfo) HasRemoteBranch ¶
func (self BranchInfo) HasRemoteBranch() bool
func (BranchInfo) HasTrackingBranch ¶
func (self BranchInfo) HasTrackingBranch() bool
func (BranchInfo) IsEmpty ¶
func (self BranchInfo) IsEmpty() bool
IsEmpty indicates whether this BranchInfo is completely empty, i.e. not a single branch contains something.
func (BranchInfo) IsLocal ¶
func (self BranchInfo) IsLocal() bool
IsLocalBranch indicates whether this branch exists in the local repo that Git Town is running in.
func (BranchInfo) IsOmniBranch ¶
func (self BranchInfo) IsOmniBranch() bool
IsOmniBranch indicates whether the local and remote branch are in sync.
type BranchInfos ¶
type BranchInfos []BranchInfo
BranchInfos contains the BranchInfos for all branches in a repo. Tracking branches on the origin remote don't get their own entry, they are listed in the `TrackingBranch` property of the local branch they track.
func (BranchInfos) FindByLocalName ¶
func (self BranchInfos) FindByLocalName(branchName LocalBranchName) *BranchInfo
FindByLocalName provides the branch with the given name if one exists.
func (BranchInfos) FindByRemoteName ¶
func (self BranchInfos) FindByRemoteName(remoteBranch RemoteBranchName) *BranchInfo
FindByRemoteName provides the local branch that has the given remote branch as its tracking branch or nil if no such branch exists.
func (BranchInfos) FindMatchingRecord ¶
func (self BranchInfos) FindMatchingRecord(other BranchInfo) BranchInfo
func (BranchInfos) HasLocalBranch ¶
func (self BranchInfos) HasLocalBranch(localBranch LocalBranchName) bool
IsKnown indicates whether the given local branch is already known to this BranchesSyncStatus instance.
func (BranchInfos) HasMatchingTrackingBranchFor ¶
func (self BranchInfos) HasMatchingTrackingBranchFor(localBranch LocalBranchName) bool
HasMatchingRemoteBranchFor indicates whether there is already a remote branch matching the given local branch.
func (BranchInfos) LocalBranches ¶
func (self BranchInfos) LocalBranches() BranchInfos
LocalBranches provides only the branches that exist on the local machine.
func (BranchInfos) LocalBranchesWithDeletedTrackingBranches ¶
func (self BranchInfos) LocalBranchesWithDeletedTrackingBranches() BranchInfos
LocalBranchesWithDeletedTrackingBranches provides only the branches that exist locally and have a deleted tracking branch.
func (BranchInfos) Names ¶
func (self BranchInfos) Names() LocalBranchNames
Names provides the names of all local branches in this BranchesSyncStatus instance.
func (BranchInfos) Remove ¶
func (self BranchInfos) Remove(branchName LocalBranchName) BranchInfos
func (BranchInfos) Select ¶
func (self BranchInfos) Select(names []LocalBranchName) (BranchInfos, error)
Select provides the BranchSyncStatus elements with the given names.
func (BranchInfos) UpdateLocalSHA ¶
func (self BranchInfos) UpdateLocalSHA(branch LocalBranchName, sha SHA) error
type BranchName ¶
type BranchName string
BranchName is the name of a local or remote Git branch.
func NewBranchName ¶
func NewBranchName(id string) BranchName
func (BranchName) IsLocal ¶
func (self BranchName) IsLocal() bool
IsLocal indicates whether the branch with this BranchName exists locally.
func (BranchName) LocalName ¶
func (self BranchName) LocalName() LocalBranchName
LocalName provides the local version of this branch name.
func (BranchName) RemoteName ¶
func (self BranchName) RemoteName() RemoteBranchName
RemoteName provides the remote version of this branch name.
func (BranchName) String ¶
func (self BranchName) String() string
Implementation of the fmt.Stringer interface.
type BranchTypes ¶
type BranchTypes struct { MainBranch LocalBranchName PerennialBranches LocalBranchNames }
BranchTypes answers questions about whether branches are long-lived or not.
func EmptyBranchTypes ¶
func EmptyBranchTypes() BranchTypes
func (BranchTypes) IsFeatureBranch ¶
func (self BranchTypes) IsFeatureBranch(branch LocalBranchName) bool
func (BranchTypes) IsMainBranch ¶
func (self BranchTypes) IsMainBranch(branch LocalBranchName) bool
func (BranchTypes) IsPerennialBranch ¶
func (self BranchTypes) IsPerennialBranch(branch LocalBranchName) bool
func (BranchTypes) MainAndPerennials ¶ added in v11.1.0
func (self BranchTypes) MainAndPerennials() LocalBranchNames
type Branches ¶
type Branches struct { All BranchInfos Types BranchTypes Initial LocalBranchName }
func EmptyBranches ¶
func EmptyBranches() Branches
EmptyBranches provides the zero value for Branches.
type BranchesSnapshot ¶
type BranchesSnapshot struct { // Branches is a read-only copy of the branches that exist in this repo at the time the snapshot was taken. // Don't use these branches for business logic since businss logic might want to modify its in-memory cache of branches // as it adds or removes branches. Branches BranchInfos // the branch that was checked out at the time the snapshot was taken Active LocalBranchName }
BranchesSnapshot is a snapshot of the Git branches at a particular point in time.
func EmptyBranchesSnapshot ¶
func EmptyBranchesSnapshot() BranchesSnapshot
func (BranchesSnapshot) IsEmpty ¶
func (self BranchesSnapshot) IsEmpty() bool
type InconsistentChange ¶
type InconsistentChange struct { Before BranchInfo After BranchInfo }
InconsistentChange describes a change where both local and remote branch exist before and after, but it's not an OmniChange, i.e. the SHA are different.
type InconsistentChanges ¶
type InconsistentChanges []InconsistentChange
func (InconsistentChanges) BranchNames ¶
func (self InconsistentChanges) BranchNames() LocalBranchNames
func (InconsistentChanges) Categorize ¶
func (self InconsistentChanges) Categorize(branchTypes BranchTypes) (perennials, features InconsistentChanges)
type LocalBranchChange ¶
type LocalBranchChange map[LocalBranchName]Change[SHA]
func (LocalBranchChange) BranchNames ¶
func (self LocalBranchChange) BranchNames() LocalBranchNames
func (LocalBranchChange) Categorize ¶
func (self LocalBranchChange) Categorize(branchTypes BranchTypes) (changedPerennials, changedFeatures LocalBranchChange)
type LocalBranchName ¶
type LocalBranchName string
LocalBranchName is the name of a local Git branch. The zero value is an empty local branch name, i.e. a local branch name that is unknown or not configured.
func EmptyLocalBranchName ¶
func EmptyLocalBranchName() LocalBranchName
func NewLocalBranchName ¶
func NewLocalBranchName(id string) LocalBranchName
func (LocalBranchName) AtRemote ¶
func (self LocalBranchName) AtRemote(remote Remote) RemoteBranchName
AtRemote provides the RemoteBranchName of this branch at the given remote.
func (LocalBranchName) BranchName ¶
func (self LocalBranchName) BranchName() BranchName
BranchName widens the type of this LocalBranchName to a more generic BranchName.
func (LocalBranchName) IsEmpty ¶
func (self LocalBranchName) IsEmpty() bool
IsEmpty indicates whether this branch name is not set.
func (LocalBranchName) Location ¶
func (self LocalBranchName) Location() Location
Location widens the type of this LocalBranchName to a more generic Location.
func (LocalBranchName) String ¶
func (self LocalBranchName) String() string
Implementation of the fmt.Stringer interface.
func (LocalBranchName) TrackingBranch ¶
func (self LocalBranchName) TrackingBranch() RemoteBranchName
TrackingBranch provides the name of the tracking branch for this local branch.
type LocalBranchNames ¶
type LocalBranchNames []LocalBranchName
func NewLocalBranchNames ¶
func NewLocalBranchNames(names ...string) LocalBranchNames
func (LocalBranchNames) Categorize ¶
func (self LocalBranchNames) Categorize(branchTypes BranchTypes) (perennials, features LocalBranchNames)
func (LocalBranchNames) Hoist ¶ added in v11.1.0
func (self LocalBranchNames) Hoist(needle LocalBranchName) LocalBranchNames
Hoist moves the given needle to the front of the list.
func (LocalBranchNames) Join ¶
func (self LocalBranchNames) Join(sep string) string
Join provides the names of all branches in this collection connected by the given separator.
func (LocalBranchNames) Remove ¶ added in v11.1.0
func (self LocalBranchNames) Remove(toRemove LocalBranchName) LocalBranchNames
Remove removes the given branch name from this collection.
func (LocalBranchNames) RemoveWorkspaceMarkers ¶ added in v11.1.0
func (self LocalBranchNames) RemoveWorkspaceMarkers() LocalBranchNames
RemoveWorkspaceMarkers removes the workspace markers from the branch names in this list.
func (LocalBranchNames) Sort ¶
func (self LocalBranchNames) Sort()
Sort orders the branches in this collection alphabetically.
func (LocalBranchNames) Strings ¶
func (self LocalBranchNames) Strings() []string
Strings provides the names of all branches in this collection as strings.
type LocalBranchesSHAs ¶
type LocalBranchesSHAs map[LocalBranchName]SHA
func (LocalBranchesSHAs) BranchNames ¶
func (self LocalBranchesSHAs) BranchNames() LocalBranchNames
type Location ¶
type Location string
Location is a location within a Git repo. Examples for locations are SHA addresses of commits or branch names.
func EmptyLocation ¶
func EmptyLocation() Location
func NewLocation ¶
type Proposal ¶
type Proposal struct { // whether this proposal can be merged via the API MergeWithAPI bool // the number used to identify the proposal on the hosting platform Number int // name of the target branch ("base") of this proposal Target LocalBranchName // textual title of the proposal Title string }
Proposal contains information about a change request on a code hosting platform. Alternative names are "pull request" or "merge request".
type RemoteBranchChange ¶
type RemoteBranchChange map[RemoteBranchName]Change[SHA]
func (RemoteBranchChange) BranchNames ¶
func (self RemoteBranchChange) BranchNames() RemoteBranchNames
func (RemoteBranchChange) Categorize ¶
func (self RemoteBranchChange) Categorize(branchTypes BranchTypes) (perennialChanges, featureChanges RemoteBranchChange)
type RemoteBranchName ¶
type RemoteBranchName string
RemoteBranchName is the name of a remote branch, e.g. "origin/foo".
func EmptyRemoteBranchName ¶
func EmptyRemoteBranchName() RemoteBranchName
func NewRemoteBranchName ¶
func NewRemoteBranchName(id string) RemoteBranchName
func (RemoteBranchName) BranchName ¶
func (self RemoteBranchName) BranchName() BranchName
BranchName widens the type of this RemoteBranchName to a more generic BranchName.
func (RemoteBranchName) IsEmpty ¶
func (self RemoteBranchName) IsEmpty() bool
func (RemoteBranchName) LocalBranchName ¶
func (self RemoteBranchName) LocalBranchName() LocalBranchName
LocalBranchName provides the name of the local branch that this remote branch tracks.
func (RemoteBranchName) Parts ¶
func (self RemoteBranchName) Parts() (Remote, LocalBranchName)
func (RemoteBranchName) Remote ¶
func (self RemoteBranchName) Remote() Remote
func (RemoteBranchName) String ¶
func (self RemoteBranchName) String() string
Implementation of the fmt.Stringer interface.
type RemoteBranchNames ¶
type RemoteBranchNames []RemoteBranchName
func (RemoteBranchNames) Sort ¶
func (self RemoteBranchNames) Sort()
Sort orders the branches in this collection alphabetically.
func (RemoteBranchNames) Strings ¶
func (self RemoteBranchNames) Strings() []string
Strings provides these remote branch names as strings.
type RemoteBranchesSHAs ¶
type RemoteBranchesSHAs map[RemoteBranchName]SHA
func (RemoteBranchesSHAs) BranchNames ¶
func (self RemoteBranchesSHAs) BranchNames() RemoteBranchNames
BranchNames provides the names of the involved branches as strings.
func (RemoteBranchesSHAs) Categorize ¶
func (self RemoteBranchesSHAs) Categorize(branchTypes BranchTypes) (perennials, features RemoteBranchesSHAs)
type Remotes ¶
type Remotes []Remote
Remotes answers questions which Git remotes a repo has.
func NewRemotes ¶
func (Remotes) HasUpstream ¶
type RepoRootDir ¶
type RepoRootDir string
RepoRootDir represents the root directory of a Git repository.
func EmptyRepoRootDir ¶
func EmptyRepoRootDir() RepoRootDir
func NewRepoRootDir ¶
func NewRepoRootDir(dir string) RepoRootDir
func (RepoRootDir) IsEmpty ¶
func (self RepoRootDir) IsEmpty() bool
func (RepoRootDir) String ¶
func (self RepoRootDir) String() string
type RepoStatus ¶
type SHA ¶
type SHA string
SHA represents a Git SHA as a dedicated data type. This helps avoid stringly-typed code.
func NewSHA ¶
NewSHA creates a new SHA instance with the given value. The value is verified for correctness.
func (SHA) TruncateTo ¶
TruncateTo provides a new SHA instance that contains a shorter checksum.
type StashSnapshot ¶
type StashSnapshot int
StashSnapshot is a snapshot of the state of Git stash at a given point in time.
func EmptyStashSnapshot ¶
func EmptyStashSnapshot() StashSnapshot
type SyncStatus ¶
type SyncStatus string
SyncStatus encodes the places a branch can exist at. This is a type-safe enum, see https://npf.io/2022/05/safer-enums.
const ( SyncStatusUpToDate SyncStatus = "up to date" // the branch exists locally and remotely, the local branch is up to date SyncStatusNotInSync SyncStatus = "not in sync" // the branch exists locally and remotely, the local branch is behind the remote tracking branch SyncStatusLocalOnly SyncStatus = "local only" // the branch was created locally and hasn't been pushed to the remote yet SyncStatusRemoteOnly SyncStatus = "remote only" // the branch exists only at the remote SyncStatusDeletedAtRemote SyncStatus = "deleted at remote" // the branch was deleted on the remote SyncStatusOtherWorktree SyncStatus = "active in another worktree" // the branch is active in another worktree and should not be synced )
func (SyncStatus) String ¶
func (self SyncStatus) String() string
Source Files ¶
- branch_info.go
- branch_infos.go
- branch_name.go
- branch_types.go
- branches.go
- branches_snapshot.go
- core.go
- inconsistent_change.go
- inconsistent_changes.go
- local_branch_change.go
- local_branch_name.go
- local_branch_names.go
- local_branches_shas.go
- location.go
- proposal.go
- remote.go
- remote_branch_change.go
- remote_branch_name.go
- remote_branch_names.go
- remote_branch_sha.go
- remotes.go
- repo_root_dir.go
- repo_status.go
- sha.go
- shas.go
- stash_snapshot.go
- sync_status.go