git

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package git provides Git repository synchronization functionality for ghorg.

For comprehensive documentation on sync functionality, safety philosophy, configuration options, and troubleshooting, see README.md in this directory.

Index

Constants

View Source
const (
	BackendExec   = "exec"
	BackendGolang = "golang"
)

Git backend types

Variables

This section is empty.

Functions

func GoGitClient

func GoGitClient() goGitClient

GoGitClient creates a new goGitClient instance.

Types

type GitClient

type GitClient struct{}

GitClient implements the Gitter interface for executing git commands via exec.

func NewExecGit

func NewExecGit() GitClient

NewExecGit creates a GitClient that uses exec to run git commands. This is useful when you specifically need the exec-based implementation.

func (GitClient) Branch

func (g GitClient) Branch(repo scm.Repo) (string, error)

Branch returns the list of branches in the repository.

func (GitClient) Checkout

func (g GitClient) Checkout(repo scm.Repo) error

Checkout checks out the specified branch in the repository.

func (GitClient) CheckoutBranch

func (g GitClient) CheckoutBranch(repo scm.Repo, branch string) error

CheckoutBranch checks out the specified branch by name.

func (GitClient) Clean

func (g GitClient) Clean(repo scm.Repo) error

Clean removes untracked files and directories from the working tree.

func (GitClient) Clone

func (g GitClient) Clone(repo scm.Repo) error

Clone clones a repository to the specified path. Respects configuration for submodules, depth, filters, and backup mode.

func (GitClient) FetchAll

func (g GitClient) FetchAll(repo scm.Repo) error

FetchAll fetches from all remotes. Respects configuration for depth and prune.

func (GitClient) FetchCloneBranch

func (g GitClient) FetchCloneBranch(repo scm.Repo) error

FetchCloneBranch fetches the specified branch from origin. Respects configuration for depth.

func (GitClient) GetCurrentBranch

func (g GitClient) GetCurrentBranch(repo scm.Repo) (string, error)

GetCurrentBranch returns the currently checked-out branch name.

func (GitClient) GetRefHash

func (g GitClient) GetRefHash(repo scm.Repo, ref string) (string, error)

GetRefHash returns the commit hash for the given ref.

func (GitClient) GetRemoteDefaultBranch

func (g GitClient) GetRemoteDefaultBranch(repo scm.Repo) (string, error)

GetRemoteDefaultBranch returns the default branch name from the remote (e.g., "main" or "master").

func (GitClient) GetRemoteURL

func (g GitClient) GetRemoteURL(repo scm.Repo, remote string) (string, error)

GetRemoteURL returns the URL for the given remote name (e.g., "origin").

func (GitClient) HasCommitsNotOnDefaultBranch

func (g GitClient) HasCommitsNotOnDefaultBranch(repo scm.Repo, currentBranch string) (bool, error)

HasCommitsNotOnDefaultBranch returns true if currentBranch contains commits not present on the default branch.

func (GitClient) HasLocalChanges

func (g GitClient) HasLocalChanges(repo scm.Repo) (bool, error)

HasLocalChanges returns true if there are uncommitted changes in the working tree.

func (GitClient) HasRemoteHeads

func (g GitClient) HasRemoteHeads(repo scm.Repo) (bool, error)

HasRemoteHeads checks if the remote repository has any heads (branches). Returns false if the repository is empty.

func (GitClient) HasUnpushedCommits

func (g GitClient) HasUnpushedCommits(repo scm.Repo) (bool, error)

HasUnpushedCommits returns true if there are commits present locally that are not pushed to upstream.

func (GitClient) IsDefaultBranchBehindHead

func (g GitClient) IsDefaultBranchBehindHead(repo scm.Repo, currentBranch string) (bool, error)

IsDefaultBranchBehindHead returns true if the default branch is an ancestor of the current branch (i.e., can be fast-forwarded).

func (GitClient) MergeFastForward

func (g GitClient) MergeFastForward(repo scm.Repo) error

MergeFastForward merges the remote branch into the current branch using fast-forward only. This is used during sync to update the local branch with remote changes.

func (GitClient) MergeIntoDefaultBranch

func (g GitClient) MergeIntoDefaultBranch(repo scm.Repo, currentBranch string) error

MergeIntoDefaultBranch attempts a fast-forward merge of currentBranch into the default branch locally.

func (GitClient) Pull

func (g GitClient) Pull(repo scm.Repo) error

Pull pulls the latest changes from the origin for the specified branch. Respects configuration for submodules and depth.

func (GitClient) RepoCommitCount

func (g GitClient) RepoCommitCount(repo scm.Repo) (int, error)

RepoCommitCount returns the number of commits in the specified branch.

func (GitClient) Reset

func (g GitClient) Reset(repo scm.Repo) error

Reset performs a hard reset to the origin branch.

func (GitClient) RevListCompare

func (g GitClient) RevListCompare(repo scm.Repo, localBranch string, remoteBranch string) (string, error)

RevListCompare returns the list of commits in the local branch that are not in the remote branch.

func (GitClient) SetOrigin

func (g GitClient) SetOrigin(repo scm.Repo) error

SetOrigin sets the origin remote URL to the repository's base URL.

func (GitClient) SetOriginWithCredentials

func (g GitClient) SetOriginWithCredentials(repo scm.Repo) error

SetOriginWithCredentials sets the origin remote URL using the clone URL (which may include credentials).

func (GitClient) ShortStatus

func (g GitClient) ShortStatus(repo scm.Repo) (string, error)

ShortStatus returns the short status of the repository.

func (GitClient) SyncDefaultBranch

func (g GitClient) SyncDefaultBranch(repo scm.Repo) (bool, error)

SyncDefaultBranch synchronizes the local default branch with the remote It checks for local changes and unpushed commits before performing the sync Returns (wasUpdated, error) where wasUpdated indicates if the branch was actually changed

func (GitClient) UpdateRef

func (g GitClient) UpdateRef(repo scm.Repo, refName string, commitRef string) error

UpdateRef updates a local ref to point to the given remote ref (by resolving the remote ref SHA first).

func (GitClient) UpdateRemote

func (g GitClient) UpdateRemote(repo scm.Repo) error

UpdateRemote fetches updates from all remotes.

type Gitter

type Gitter interface {
	// Core cloning and syncing operations
	Clone(scm.Repo) error
	Reset(scm.Repo) error
	Pull(scm.Repo) error
	SetOrigin(scm.Repo) error
	SetOriginWithCredentials(scm.Repo) error
	Clean(scm.Repo) error
	Checkout(scm.Repo) error

	// Branch checkout by name
	CheckoutBranch(scm.Repo, string) error

	// Remote operations
	UpdateRemote(scm.Repo) error
	FetchAll(scm.Repo) error
	FetchCloneBranch(scm.Repo) error
	HasRemoteHeads(scm.Repo) (bool, error)
	GetRemoteURL(scm.Repo, string) (string, error)

	// Branch and status operations
	Branch(scm.Repo) (string, error)
	GetCurrentBranch(scm.Repo) (string, error)
	ShortStatus(scm.Repo) (string, error)
	HasLocalChanges(scm.Repo) (bool, error)
	HasUnpushedCommits(scm.Repo) (bool, error)

	// Commit comparison operations
	RevListCompare(scm.Repo, string, string) (string, error)
	RepoCommitCount(scm.Repo) (int, error)
	HasCommitsNotOnDefaultBranch(scm.Repo, string) (bool, error)
	IsDefaultBranchBehindHead(scm.Repo, string) (bool, error)

	// Sync and merge operations
	SyncDefaultBranch(scm.Repo) (bool, error)
	MergeIntoDefaultBranch(scm.Repo, string) error
	UpdateRef(scm.Repo, string, string) error
}

Gitter defines the interface for git operations. All git operations used by ghorg should be defined here to enable testing with mock implementations.

func NewGit

func NewGit() Gitter

NewGit creates a new Gitter instance based on the GHORG_GIT_BACKEND environment variable. Supported backends: "golang" (default) uses pure Go implementation, "exec" uses system git binary.

Jump to

Keyboard shortcuts

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