git

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountCommitsTouchingFile added in v0.2.0

func CountCommitsTouchingFile(
	ctx context.Context,
	cmdFactory opctx.CmdFactory,
	repoDir, relPath string,
) (count int, latest time.Time, err error)

CountCommitsTouchingFile returns the number of commits that touched relPath in the git repository rooted at repoDir, plus the timestamp of the most recent such commit (zero when no commits found).

The returned timestamp is on the committer-date axis: we format with %ct so it matches the order 'git log' walks (newest committer-date first).

Shells out to 'git log -- <path>' because go-git's PathFilter walks the entire commit graph in-process and is prohibitively slow on large repos (see the commentary on gitLogFileMetadata in internal/app/azldev/core/sources/synthistory.go).

func OpenProjectRepo added in v0.2.0

func OpenProjectRepo(path string) (*gogit.Repository, error)

OpenProjectRepo opens a go-git repository from a path within the project, detecting the .git directory and supporting linked worktrees. Use this for opening the project-config repo (not source checkouts, which may have different options).

func RunInDir added in v0.2.0

func RunInDir(
	ctx context.Context, cmdFactory opctx.CmdFactory, dir string, args ...string,
) (string, error)

RunInDir executes a git command in the given directory and returns its trimmed stdout output. The dir argument is passed via 'git -C dir'.

Types

type GitOptions

type GitOptions func(opts *cloneOptions)

GitOptions is a functional option that configures a clone operation. Options may add CLI arguments and/or request post-clone actions.

func WithGitBranch

func WithGitBranch(branch string) GitOptions

WithGitBranch returns a GitOptions that specifies the branch to clone.

func WithMetadataOnly added in v0.2.0

func WithMetadataOnly() GitOptions

WithMetadataOnly returns a GitOptions that performs a blobless partial clone (--filter=blob:none --no-checkout). Only git metadata is fetched; no working-tree files are checked out.

func WithQuiet added in v0.2.0

func WithQuiet() GitOptions

WithQuiet returns a GitOptions that suppresses event emission during the clone. Use this for internal operations (e.g., identity resolution) that run concurrently and would produce misleading nested log output.

type GitProvider

type GitProvider interface {
	// Clone clones a git repository to the specified destination
	Clone(ctx context.Context, repoURL string, destDir string, options ...GitOptions) error
	// Checkout checks out a specific commit in the repository at the specified directory.
	Checkout(ctx context.Context, repoDir string, commitHash string) error
	// GetCommitHashBeforeDate returns the commit hash at or before the specified date in the repository.
	GetCommitHashBeforeDate(ctx context.Context, repoDir string, dateTime time.Time) (string, error)
	// GetCurrentCommit returns the current commit hash of the repository at the given directory, regardless of the date.
	GetCurrentCommit(ctx context.Context, repoDir string) (string, error)
}

type GitProviderImpl

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

func NewGitProviderImpl

func NewGitProviderImpl(eventListener opctx.EventListener, cmdFactory opctx.CmdFactory) (*GitProviderImpl, error)

func (*GitProviderImpl) Checkout

func (g *GitProviderImpl) Checkout(ctx context.Context, repoDir string, commitHash string) error

func (*GitProviderImpl) Clone

func (g *GitProviderImpl) Clone(ctx context.Context, repoURL, destDir string, options ...GitOptions) error

func (*GitProviderImpl) GetCommitHashBeforeDate

func (g *GitProviderImpl) GetCommitHashBeforeDate(
	ctx context.Context, repoDir string, dateTime time.Time,
) (string, error)

func (*GitProviderImpl) GetCurrentCommit added in v0.2.0

func (g *GitProviderImpl) GetCurrentCommit(ctx context.Context, repoDir string) (string, error)

GetCurrentCommit returns the current commit hash of the repository at the given directory, regardless of the date.

Directories

Path Synopsis
Package git_test is a generated GoMock package.
Package git_test is a generated GoMock package.

Jump to

Keyboard shortcuts

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