Documentation
¶
Overview ¶
Package gitrepo provides operations on git repos.
Index ¶
- Constants
- Variables
- type Commit
- type ConventionalCommit
- type LocalRepository
- func (r *LocalRepository) AddAll() error
- func (r *LocalRepository) ChangedFiles() ([]string, error)
- func (r *LocalRepository) ChangedFilesInCommit(commitHash string) ([]string, error)
- func (r *LocalRepository) CleanUntracked(paths []string) error
- func (r *LocalRepository) Commit(msg string) error
- func (r *LocalRepository) CreateBranchAndCheckout(name string) error
- func (r *LocalRepository) DeleteBranch(branchName string) error
- func (r *LocalRepository) GetCommit(commitHash string) (*Commit, error)
- func (r *LocalRepository) GetCommitsForPathsSinceCommit(paths []string, sinceCommit string) ([]*Commit, error)
- func (r *LocalRepository) GetCommitsForPathsSinceTag(paths []string, tagName string) ([]*Commit, error)
- func (r *LocalRepository) GetDir() string
- func (r *LocalRepository) GetLatestCommit(path string) (*Commit, error)
- func (r *LocalRepository) HeadHash() (string, error)
- func (r *LocalRepository) IsClean() (bool, error)
- func (r *LocalRepository) Push(branchName string) error
- func (r *LocalRepository) Remotes() ([]*Remote, error)
- func (r *LocalRepository) Restore(paths []string) error
- type Remote
- type Repository
- type RepositoryOptions
Constants ¶
const RootPath = "."
Variables ¶
var ErrEmptyCommitMessage = errors.New("empty commit message")
ErrEmptyCommitMessage returns when the commit message is empty.
Functions ¶
This section is empty.
Types ¶
type ConventionalCommit ¶ added in v0.4.0
type ConventionalCommit struct {
// Type is the type of change (e.g., "feat", "fix", "docs").
Type string `yaml:"type" json:"type"`
// Subject is the short summary of the change.
Subject string `yaml:"subject" json:"subject"`
// Body is the long-form description of the change.
Body string `yaml:"body" json:"body"`
// LibraryID is the library ID the commit associated with.
LibraryID string `yaml:"-" json:"-"`
// Repeated footer keys not supported, only first value is kept
Footers map[string]string `yaml:"-" json:"-"`
// IsBreaking indicates if the commit introduces a breaking change.
IsBreaking bool `yaml:"-" json:"-"`
// IsNested indicates if the commit is a nested commit.
IsNested bool `yaml:"-" json:"-"`
// CommitHash is the full commit hash.
CommitHash string `yaml:"-" json:"commit_hash,omitempty"`
// When is the timestamp of the commit.
When time.Time `yaml:"-" json:"-"`
}
ConventionalCommit represents a parsed conventional commit message. See https://www.conventionalcommits.org/en/v1.0.0/ for details.
func ParseCommits ¶ added in v0.4.0
func ParseCommits(commit *Commit, libraryID string) ([]*ConventionalCommit, error)
ParseCommits parses a commit message into a slice of ConventionalCommit structs.
It supports an override block wrapped in BEGIN_COMMIT_OVERRIDE and END_COMMIT_OVERRIDE. If found, this block takes precedence, and only its content will be parsed.
The message can also contain multiple nested commits, each wrapped in BEGIN_NESTED_COMMIT and END_NESTED_COMMIT markers.
Malformed override or nested blocks (e.g., with a missing end marker) are ignored. Any commit part that is found but fails to parse as a valid conventional commit is logged and skipped.
func (*ConventionalCommit) MarshalJSON ¶ added in v0.4.0
func (c *ConventionalCommit) MarshalJSON() ([]byte, error)
MarshalJSON implements a custom JSON marshaler for ConventionalCommit.
type LocalRepository ¶ added in v0.1.1
type LocalRepository struct {
Dir string
// contains filtered or unexported fields
}
LocalRepository represents a git repository.
func NewRepository ¶
func NewRepository(opts *RepositoryOptions) (*LocalRepository, error)
NewRepository provides access to a git repository based on the provided options.
If opts.Clone is CloneOptionNone, it opens an existing repository at opts.Dir. If opts.Clone is CloneOptionMaybe, it opens the repository if it exists, otherwise it clones from opts.RemoteURL. If opts.Clone is CloneOptionAlways, it always clones from opts.RemoteURL.
func (*LocalRepository) AddAll ¶ added in v0.1.1
func (r *LocalRepository) AddAll() error
AddAll adds all pending changes from the working tree to the index, so that the changes can later be committed.
func (*LocalRepository) ChangedFiles ¶ added in v0.4.0
func (r *LocalRepository) ChangedFiles() ([]string, error)
ChangedFiles returns a list of files that have been modified, added, or deleted in the working tree, including both staged and unstaged changes.
func (*LocalRepository) ChangedFilesInCommit ¶ added in v0.2.0
func (r *LocalRepository) ChangedFilesInCommit(commitHash string) ([]string, error)
ChangedFilesInCommit returns the files changed in the given commit.
func (*LocalRepository) CleanUntracked ¶ added in v0.2.0
func (r *LocalRepository) CleanUntracked(paths []string) error
CleanUntracked removes untracked files within the given paths.
func (*LocalRepository) Commit ¶ added in v0.1.1
func (r *LocalRepository) Commit(msg string) error
Commit creates a new commit with the provided message and author information.
func (*LocalRepository) CreateBranchAndCheckout ¶ added in v0.2.0
func (r *LocalRepository) CreateBranchAndCheckout(name string) error
CreateBranchAndCheckout creates a new git branch and checks out the branch in the local git repository.
func (*LocalRepository) DeleteBranch ¶ added in v0.2.0
func (r *LocalRepository) DeleteBranch(branchName string) error
DeleteBranch deletes a branch on the origin remote.
func (*LocalRepository) GetCommit ¶ added in v0.2.0
func (r *LocalRepository) GetCommit(commitHash string) (*Commit, error)
GetCommit returns a commit for the given commit hash.
func (*LocalRepository) GetCommitsForPathsSinceCommit ¶ added in v0.2.0
func (r *LocalRepository) GetCommitsForPathsSinceCommit(paths []string, sinceCommit string) ([]*Commit, error)
GetCommitsForPathsSinceCommit returns the commits affecting any of the given paths, stopping looking at the given commit (which is not included in the results). The returned commits are ordered such that the most recent commit is first.
If sinceCommit is not provided, all commits are searched; otherwise, if no commit matching sinceCommit is found, an error is returned.
func (*LocalRepository) GetCommitsForPathsSinceTag ¶ added in v0.2.0
func (r *LocalRepository) GetCommitsForPathsSinceTag(paths []string, tagName string) ([]*Commit, error)
GetCommitsForPathsSinceTag returns all commits since tagName that contains files in paths.
If tagName empty, all commits for the given paths are returned.
func (*LocalRepository) GetDir ¶ added in v0.1.1
func (r *LocalRepository) GetDir() string
GetDir returns the directory of the repository.
func (*LocalRepository) GetLatestCommit ¶ added in v0.4.0
func (r *LocalRepository) GetLatestCommit(path string) (*Commit, error)
GetLatestCommit returns the latest commit of the given path in the repository.
func (*LocalRepository) HeadHash ¶ added in v0.2.0
func (r *LocalRepository) HeadHash() (string, error)
HeadHash returns hash of the commit for the repository's HEAD.
func (*LocalRepository) IsClean ¶ added in v0.1.1
func (r *LocalRepository) IsClean() (bool, error)
IsClean reports whether the working tree has no uncommitted changes.
func (*LocalRepository) Push ¶ added in v0.2.0
func (r *LocalRepository) Push(branchName string) error
Push pushes the local branch to the origin remote.
func (*LocalRepository) Remotes ¶ added in v0.1.1
func (r *LocalRepository) Remotes() ([]*Remote, error)
Remotes returns the remotes within the repository.
func (*LocalRepository) Restore ¶ added in v0.2.0
func (r *LocalRepository) Restore(paths []string) error
Restore restores changes in the working tree, leaving staged area untouched. Note that untracked files, if any, are not touched.
Wrap git operations in exec, because git.Worktree.Restore does not support this operation.
type Repository ¶
type Repository interface {
AddAll() error
Commit(msg string) error
IsClean() (bool, error)
Remotes() ([]*Remote, error)
GetDir() string
HeadHash() (string, error)
ChangedFilesInCommit(commitHash string) ([]string, error)
ChangedFiles() ([]string, error)
GetCommit(commitHash string) (*Commit, error)
GetLatestCommit(path string) (*Commit, error)
GetCommitsForPathsSinceTag(paths []string, tagName string) ([]*Commit, error)
GetCommitsForPathsSinceCommit(paths []string, sinceCommit string) ([]*Commit, error)
CreateBranchAndCheckout(name string) error
Push(branchName string) error
Restore(paths []string) error
CleanUntracked(paths []string) error
// contains filtered or unexported methods
}
Repository defines the interface for git repository operations.
type RepositoryOptions ¶
type RepositoryOptions struct {
// Dir is the directory where the repository will reside locally. Required.
Dir string
// MaybeClone will try to clone the repository if it does not exist locally.
// If set to true, RemoteURL and RemoteBranch must also be set. Optional.
MaybeClone bool
// RemoteURL is the URL of the remote repository to clone from. Required if MaybeClone is set to true.
RemoteURL string
// RemoteBranch is the remote branch to clone. Required if MaybeClone is set to true.
RemoteBranch string
// CI is the type of Continuous Integration (CI) environment in which
// the tool is executing.
CI string
// GitPassword is used for HTTP basic auth.
GitPassword string
// Depth controls the cloning depth if the repository needs to be cloned.
Depth int
}
RepositoryOptions are used to configure a LocalRepository.