gitrepo

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package gitrepo provides operations on git repos.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commit

type Commit struct {
	Hash    plumbing.Hash
	Message string
	When    time.Time
}

Commit represents a git commit.

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() (git.Status, error)

AddAll adds all pending changes from the working tree to the index, so that the changes can later be committed.

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) 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() ([]*git.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() (git.Status, error)
	Commit(msg string) error
	IsClean() (bool, error)
	Remotes() ([]*git.Remote, error)
	GetDir() string
	HeadHash() (string, error)
	ChangedFilesInCommit(commitHash string) ([]string, error)
	GetCommit(commitHash 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.

Jump to

Keyboard shortcuts

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