git

package
v1.9.13 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckForValidForkRemote

func CheckForValidForkRemote(upstreamURL, remoteURL, repo string) bool

CheckForValidForkRemote checks if the remote URL is a valid remote fork for the upstream URL.

func GetChangedFiles added in v1.9.12

func GetChangedFiles(ctx context.Context, repoPath, baseBranch string) (object.Changes, error)

GetChangedFiles opens the git repository at repoRoot and returns all files that were added or modified between the merge base of HEAD and origin/baseBranch.

Equivalent to: git diff origin/<baseBranch>...HEAD Correctly handles PRs with any number of commits via merge base resolution.

func GetGitInfo added in v1.9.0

func GetGitInfo(ctx context.Context, repoRoot string) (*gogit.Repository, *gogit.Worktree, gogit.Status, error)

GetGitInfo returns the git repository, worktree, and status for a given repository root path. This function is used for validation operations that need to check git status and repository state. It uses go-git library instead of exec commands.

func GetLocalBranchRefName added in v1.9.0

func GetLocalBranchRefName(branch string) plumbing.ReferenceName

GetLocalBranchRefName returns the reference name of a given local branch

func SparseCloneSubdirectory added in v1.9.0

func SparseCloneSubdirectory(ctx context.Context, url, commit, subdirectory string, fs billy.Filesystem, path string) error

SparseCloneSubdirectory performs a sparse Git clone of only a specific subdirectory using Git CLI commands. This is significantly more efficient than cloning the entire repository when only a small subdirectory is needed.

The function clones directly to the specified path using billy.Filesystem abstraction, with sparse-checkout configured to only download the specified subdirectory. The caller is responsible for removing the .git folder and restructuring with MakeSubdirectoryRoot if needed.

Parameters:

  • ctx: Context for cancellation
  • url: Git repository URL (e.g., "https://github.com/rancher/ob-team-charts.git")
  • commit: Specific commit SHA to checkout
  • subdirectory: Path to subdirectory within the repo (e.g., "charts/rancher-monitoring/...")
  • fs: Billy filesystem for path operations
  • path: Destination path where the repository should be cloned

Returns an error if the operation fails.

Types

type Git

type Git struct {
	Dir     string
	Branch  string
	Remotes map[string]string
}

Git struct holds necessary data to work with the current git repository

var GitRepo *Git

GitRepo uses singleton pattern to access a local git repository

func CloneAtDir

func CloneAtDir(ctx context.Context, url, dir string) (*Git, error)

CloneAtDir clones a repository at a given directory. Equivalent to: git clone <url> <dir> It will return a Git struct with the repository's branch and remotes populated.

func OpenGitRepo

func OpenGitRepo(ctx context.Context, workingDir string) (*Git, error)

OpenGitRepo will check if the target workingDir exists and is a local git repository. will also get the current branch and configured remotes.

func (*Git) AddAndCommit

func (g *Git) AddAndCommit(message string) error

AddAndCommit stages all changes and commits them with a given message, equivalent to: git add -A && git commit -m message

func (*Git) CheckFileExists added in v0.9.6

func (g *Git) CheckFileExists(file, branch string) error

CheckFileExists checks if a file exists in the git repository for a specific branch

func (*Git) CheckoutBranch

func (g *Git) CheckoutBranch(branch string) error

CheckoutBranch checks out a branch

func (*Git) CheckoutFile added in v0.9.6

func (g *Git) CheckoutFile(branch, file string) error

CheckoutFile checks out a file in a branch ex: git checkout <remote>/<branch> -- <file>

func (*Git) CreateAndCheckoutBranch

func (g *Git) CreateAndCheckoutBranch(branch string) error

CreateAndCheckoutBranch creates and checks out to a given branch. Equivalent to: git checkout -b <branch>

func (*Git) DeleteBranch

func (g *Git) DeleteBranch(branch string) error

DeleteBranch deletes the given branch

func (*Git) FetchAndCheckoutBranch

func (g *Git) FetchAndCheckoutBranch(ctx context.Context, branch string) error

FetchAndCheckoutBranch fetches and checks out a branch

func (*Git) FetchAndPullBranch added in v1.3.3

func (g *Git) FetchAndPullBranch(ctx context.Context, branch string) error

FetchAndPullBranch fetches and pulls a branch

func (*Git) FetchBranch

func (g *Git) FetchBranch(branch string) error

FetchBranch fetches a branch

func (*Git) ForceClean added in v1.4.8

func (g *Git) ForceClean() error

ForceClean = git clean -fdx

func (*Git) FullReset added in v1.4.8

func (g *Git) FullReset() error

FullReset performs a hard reset, cleans the repository and restores it

func (*Git) HardHEADReset added in v1.4.8

func (g *Git) HardHEADReset() error

HardHEADReset = git reset --hard HEAD

func (*Git) IsClean

func (g *Git) IsClean(ctx context.Context) error

IsClean checks if the git repository is clean and, returns nil if it is clean, throws an error otherwise

func (*Git) PushBranch

func (g *Git) PushBranch(remote, branch string) error

PushBranch pushes the current branch to a given remote name

func (*Git) ResetHEAD added in v0.9.6

func (g *Git) ResetHEAD() error

ResetHEAD resets the HEAD of the git repository ex: git reset HEAD

func (*Git) Restore added in v1.4.8

func (g *Git) Restore() error

Restore = git restore .

func (*Git) Status added in v1.5.5

func (g *Git) Status(ctx context.Context) error

Status prints the status of the git repository equivalent to: git status --untracked-files=all --short

func (*Git) StatusProcelain

func (g *Git) StatusProcelain(ctx context.Context) (bool, error)

StatusProcelain checks if the git repository is clean and, returns true if it is clean, false otherwise

Jump to

Keyboard shortcuts

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