sourcecontrol

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package sourcecontrol provides domain types for source control operations.

Package sourcecontrol provides domain types for source control operations.

Package sourcecontrol provides domain types for source control operations.

Package sourcecontrol provides domain types for source control operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRepositoryNotFound indicates the repository was not found.
	ErrRepositoryNotFound = errors.New("repository not found")

	// ErrNotARepository indicates the path is not a git repository.
	ErrNotARepository = errors.New("not a git repository")

	// ErrCommitNotFound indicates the commit was not found.
	ErrCommitNotFound = errors.New("commit not found")

	// ErrTagNotFound indicates the tag was not found.
	ErrTagNotFound = errors.New("tag not found")

	// ErrTagAlreadyExists indicates the tag already exists.
	ErrTagAlreadyExists = errors.New("tag already exists")

	// ErrBranchNotFound indicates the branch was not found.
	ErrBranchNotFound = errors.New("branch not found")

	// ErrRemoteNotFound indicates the remote was not found.
	ErrRemoteNotFound = errors.New("remote not found")

	// ErrWorkingTreeDirty indicates the working tree has uncommitted changes.
	ErrWorkingTreeDirty = errors.New("working tree has uncommitted changes")

	// ErrNoCommits indicates no commits were found.
	ErrNoCommits = errors.New("no commits found")

	// ErrNoTags indicates no tags were found.
	ErrNoTags = errors.New("no tags found")

	// ErrPushFailed indicates a push operation failed.
	ErrPushFailed = errors.New("push failed")

	// ErrFetchFailed indicates a fetch operation failed.
	ErrFetchFailed = errors.New("fetch failed")

	// ErrAuthenticationRequired indicates authentication is required.
	ErrAuthenticationRequired = errors.New("authentication required")
)

Domain errors for source control operations.

Functions

This section is empty.

Types

type Author

type Author struct {
	Name  string
	Email string
}

Author represents a commit author or committer.

type BranchInfo

type BranchInfo struct {
	Name      string
	IsRemote  bool
	IsCurrent bool
	Hash      CommitHash
	Upstream  string
}

BranchInfo represents a git branch.

type Commit

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

Commit represents a git commit entity.

func NewCommit

func NewCommit(hash CommitHash, message string, author Author, date time.Time) *Commit

NewCommit creates a new Commit entity.

func (*Commit) Author

func (c *Commit) Author() Author

Author returns the commit author.

func (*Commit) Committer

func (c *Commit) Committer() Author

Committer returns the committer.

func (*Commit) Date

func (c *Commit) Date() time.Time

Date returns the commit date.

func (*Commit) Hash

func (c *Commit) Hash() CommitHash

Hash returns the commit hash.

func (*Commit) IsMergeCommit

func (c *Commit) IsMergeCommit() bool

IsMergeCommit returns true if this is a merge commit.

func (*Commit) Message

func (c *Commit) Message() string

Message returns the full commit message.

func (*Commit) Parents

func (c *Commit) Parents() []CommitHash

Parents returns the parent commit hashes.

func (*Commit) SetCommitter

func (c *Commit) SetCommitter(committer Author)

SetCommitter sets the committer.

func (*Commit) SetParents

func (c *Commit) SetParents(parents []CommitHash)

SetParents sets the parent hashes.

func (*Commit) SetTreeHash

func (c *Commit) SetTreeHash(hash string)

SetTreeHash sets the tree hash.

func (*Commit) ShortHash

func (c *Commit) ShortHash() string

ShortHash returns the short commit hash.

func (*Commit) Subject

func (c *Commit) Subject() string

Subject returns the first line of the commit message.

func (*Commit) TreeHash

func (c *Commit) TreeHash() string

TreeHash returns the tree hash.

type CommitHash

type CommitHash string

CommitHash represents a git commit hash.

func (CommitHash) IsEmpty

func (h CommitHash) IsEmpty() bool

IsEmpty returns true if the hash is empty.

func (CommitHash) Short

func (h CommitHash) Short() string

Short returns the short (7 character) hash.

func (CommitHash) String

func (h CommitHash) String() string

String returns the full hash.

type CommitReader

type CommitReader interface {
	GetCommit(ctx context.Context, hash CommitHash) (*Commit, error)
	GetCommitsBetween(ctx context.Context, from, to string) ([]*Commit, error)
	GetCommitsSince(ctx context.Context, ref string) ([]*Commit, error)
	GetLatestCommit(ctx context.Context, branch string) (*Commit, error)
}

CommitReader provides read access to commits. Use this interface when you only need to read commit history.

type FileChange

type FileChange struct {
	Path   string
	Status FileStatus
}

FileChange represents a file change.

type FileStatus

type FileStatus string

FileStatus represents the status of a file change.

const (
	FileStatusAdded    FileStatus = "added"
	FileStatusModified FileStatus = "modified"
	FileStatusDeleted  FileStatus = "deleted"
	FileStatusRenamed  FileStatus = "renamed"
	FileStatusCopied   FileStatus = "copied"
)

type GitRepository

GitRepository defines the full interface for git operations. This is a repository interface in DDD - implemented in infrastructure layer. For more focused use cases, consider using the smaller interfaces: - RepositoryInfoReader: for reading repository metadata - CommitReader: for reading commit history - TagReader/TagWriter/TagManager: for tag operations - WorkingTreeInspector: for checking working tree status - RemoteOperator: for remote synchronization

type RemoteInfo

type RemoteInfo struct {
	Name string
	URL  string
}

RemoteInfo represents a git remote.

type RemoteOperator

type RemoteOperator interface {
	Fetch(ctx context.Context, remote string) error
	Pull(ctx context.Context, remote, branch string) error
	Push(ctx context.Context, remote, branch string) error
}

RemoteOperator provides operations for interacting with remote repositories. Use this interface when you need to sync with remote repositories.

type RepositoryInfo

type RepositoryInfo struct {
	Path          string
	Name          string
	Owner         string
	RemoteURL     string
	DefaultBranch string
	CurrentBranch string
	IsDirty       bool
}

RepositoryInfo represents repository metadata.

type RepositoryInfoReader

type RepositoryInfoReader interface {
	GetInfo(ctx context.Context) (*RepositoryInfo, error)
	GetRemotes(ctx context.Context) ([]RemoteInfo, error)
	GetBranches(ctx context.Context) ([]BranchInfo, error)
	GetCurrentBranch(ctx context.Context) (string, error)
}

RepositoryInfoReader provides read access to repository metadata. Use this interface when you only need to read repository information.

type Tag

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

Tag represents a git tag entity.

func NewAnnotatedTag

func NewAnnotatedTag(name string, hash CommitHash, message string, tagger Author) *Tag

NewAnnotatedTag creates a new annotated Tag entity.

func NewTag

func NewTag(name string, hash CommitHash) *Tag

NewTag creates a new Tag entity.

func (*Tag) Date

func (t *Tag) Date() time.Time

Date returns the tag date.

func (*Tag) HasPrefix

func (t *Tag) HasPrefix(prefix string) bool

HasPrefix returns true if the tag has the specified prefix.

func (*Tag) Hash

func (t *Tag) Hash() CommitHash

Hash returns the commit hash the tag points to.

func (*Tag) IsLightweight

func (t *Tag) IsLightweight() bool

IsLightweight returns true if this is a lightweight tag.

func (*Tag) IsVersionTag

func (t *Tag) IsVersionTag() bool

IsVersionTag returns true if this tag represents a version.

func (*Tag) Message

func (t *Tag) Message() string

Message returns the tag message (for annotated tags).

func (*Tag) Name

func (t *Tag) Name() string

Name returns the tag name.

func (*Tag) SetDate

func (t *Tag) SetDate(date time.Time)

SetDate sets the tag date.

func (*Tag) SetMessage

func (t *Tag) SetMessage(msg string)

SetMessage sets the tag message.

func (*Tag) SetTagger

func (t *Tag) SetTagger(tagger Author)

SetTagger sets the tagger.

func (*Tag) Tagger

func (t *Tag) Tagger() Author

Tagger returns the tagger (for annotated tags).

func (*Tag) Version

func (t *Tag) Version() *version.SemanticVersion

Version returns the semantic version if this is a version tag.

func (*Tag) WithoutPrefix

func (t *Tag) WithoutPrefix(prefix string) string

WithoutPrefix returns the tag name without the specified prefix.

type TagList

type TagList []*Tag

TagList represents a sorted list of tags.

func (TagList) FilterByPrefix

func (tl TagList) FilterByPrefix(prefix string) TagList

FilterByPrefix returns tags with the specified prefix.

func (TagList) Latest

func (tl TagList) Latest() *Tag

Latest returns the latest version tag.

func (TagList) Len

func (tl TagList) Len() int

Len returns the number of tags.

func (TagList) Less

func (tl TagList) Less(i, j int) bool

Less compares tags by version (if both are version tags) or by date.

func (TagList) Swap

func (tl TagList) Swap(i, j int)

Swap swaps two tags.

func (TagList) VersionTags

func (tl TagList) VersionTags() TagList

VersionTags returns only version tags.

type TagManager

type TagManager interface {
	TagReader
	TagWriter
}

TagManager combines read and write access to tags. Use this interface when you need full tag management capabilities.

type TagReader

type TagReader interface {
	GetTags(ctx context.Context) (TagList, error)
	GetTag(ctx context.Context, name string) (*Tag, error)
	GetLatestVersionTag(ctx context.Context, prefix string) (*Tag, error)
}

TagReader provides read access to tags. Use this interface when you only need to read tag information.

type TagWriter

type TagWriter interface {
	CreateTag(ctx context.Context, name string, hash CommitHash, message string) (*Tag, error)
	DeleteTag(ctx context.Context, name string) error
	PushTag(ctx context.Context, name string, remote string) error
}

TagWriter provides write access to tags. Use this interface when you need to create, delete, or push tags.

type VersionDiscovery

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

VersionDiscovery provides methods for discovering versions from tags.

func NewVersionDiscovery

func NewVersionDiscovery(tagPrefix string) *VersionDiscovery

NewVersionDiscovery creates a new VersionDiscovery.

func (*VersionDiscovery) DiscoverAllVersions

func (vd *VersionDiscovery) DiscoverAllVersions(ctx context.Context, repo GitRepository) ([]version.SemanticVersion, error)

DiscoverAllVersions finds all versions from tags.

func (*VersionDiscovery) DiscoverCurrentVersion

func (vd *VersionDiscovery) DiscoverCurrentVersion(ctx context.Context, repo GitRepository) (version.SemanticVersion, error)

DiscoverCurrentVersion finds the current version from tags.

type WorkingTreeInspector

type WorkingTreeInspector interface {
	IsDirty(ctx context.Context) (bool, error)
	GetStatus(ctx context.Context) (*WorkingTreeStatus, error)
}

WorkingTreeInspector provides methods to inspect the working tree status. Use this interface when you only need to check working tree state.

type WorkingTreeStatus

type WorkingTreeStatus struct {
	IsClean   bool
	Staged    []FileChange
	Unstaged  []FileChange
	Untracked []string
}

WorkingTreeStatus represents the status of the working tree.

Jump to

Keyboard shortcuts

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