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
- func GoGitClient() goGitClient
- type GitClient
- func (g GitClient) Branch(repo scm.Repo) (string, error)
- func (g GitClient) Checkout(repo scm.Repo) error
- func (g GitClient) CheckoutBranch(repo scm.Repo, branch string) error
- func (g GitClient) Clean(repo scm.Repo) error
- func (g GitClient) Clone(repo scm.Repo) error
- func (g GitClient) FetchAll(repo scm.Repo) error
- func (g GitClient) FetchCloneBranch(repo scm.Repo) error
- func (g GitClient) GetCurrentBranch(repo scm.Repo) (string, error)
- func (g GitClient) GetRefHash(repo scm.Repo, ref string) (string, error)
- func (g GitClient) GetRemoteDefaultBranch(repo scm.Repo) (string, error)
- func (g GitClient) GetRemoteURL(repo scm.Repo, remote string) (string, error)
- func (g GitClient) HasCommitsNotOnDefaultBranch(repo scm.Repo, currentBranch string) (bool, error)
- func (g GitClient) HasLocalChanges(repo scm.Repo) (bool, error)
- func (g GitClient) HasRemoteHeads(repo scm.Repo) (bool, error)
- func (g GitClient) HasUnpushedCommits(repo scm.Repo) (bool, error)
- func (g GitClient) IsDefaultBranchBehindHead(repo scm.Repo, currentBranch string) (bool, error)
- func (g GitClient) MergeFastForward(repo scm.Repo) error
- func (g GitClient) MergeIntoDefaultBranch(repo scm.Repo, currentBranch string) error
- func (g GitClient) Pull(repo scm.Repo) error
- func (g GitClient) RepoCommitCount(repo scm.Repo) (int, error)
- func (g GitClient) Reset(repo scm.Repo) error
- func (g GitClient) RevListCompare(repo scm.Repo, localBranch string, remoteBranch string) (string, error)
- func (g GitClient) SetOrigin(repo scm.Repo) error
- func (g GitClient) SetOriginWithCredentials(repo scm.Repo) error
- func (g GitClient) ShortStatus(repo scm.Repo) (string, error)
- func (g GitClient) SyncDefaultBranch(repo scm.Repo) (bool, error)
- func (g GitClient) UpdateRef(repo scm.Repo, refName string, commitRef string) error
- func (g GitClient) UpdateRemote(repo scm.Repo) error
- type Gitter
Constants ¶
const ( BackendExec = "exec" BackendGolang = "golang" )
Git backend types
Variables ¶
This section is empty.
Functions ¶
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) CheckoutBranch ¶
CheckoutBranch checks out the specified branch by name.
func (GitClient) Clone ¶
Clone clones a repository to the specified path. Respects configuration for submodules, depth, filters, and backup mode.
func (GitClient) FetchAll ¶
FetchAll fetches from all remotes. Respects configuration for depth and prune.
func (GitClient) FetchCloneBranch ¶
FetchCloneBranch fetches the specified branch from origin. Respects configuration for depth.
func (GitClient) GetCurrentBranch ¶
GetCurrentBranch returns the currently checked-out branch name.
func (GitClient) GetRefHash ¶
GetRefHash returns the commit hash for the given ref.
func (GitClient) GetRemoteDefaultBranch ¶
GetRemoteDefaultBranch returns the default branch name from the remote (e.g., "main" or "master").
func (GitClient) GetRemoteURL ¶
GetRemoteURL returns the URL for the given remote name (e.g., "origin").
func (GitClient) HasCommitsNotOnDefaultBranch ¶
HasCommitsNotOnDefaultBranch returns true if currentBranch contains commits not present on the default branch.
func (GitClient) HasLocalChanges ¶
HasLocalChanges returns true if there are uncommitted changes in the working tree.
func (GitClient) HasRemoteHeads ¶
HasRemoteHeads checks if the remote repository has any heads (branches). Returns false if the repository is empty.
func (GitClient) HasUnpushedCommits ¶
HasUnpushedCommits returns true if there are commits present locally that are not pushed to upstream.
func (GitClient) IsDefaultBranchBehindHead ¶
IsDefaultBranchBehindHead returns true if the default branch is an ancestor of the current branch (i.e., can be fast-forwarded).
func (GitClient) MergeFastForward ¶
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 ¶
MergeIntoDefaultBranch attempts a fast-forward merge of currentBranch into the default branch locally.
func (GitClient) Pull ¶
Pull pulls the latest changes from the origin for the specified branch. Respects configuration for submodules and depth.
func (GitClient) RepoCommitCount ¶
RepoCommitCount returns the number of commits in the specified 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) SetOriginWithCredentials ¶
SetOriginWithCredentials sets the origin remote URL using the clone URL (which may include credentials).
func (GitClient) ShortStatus ¶
ShortStatus returns the short status of the repository.
func (GitClient) SyncDefaultBranch ¶
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
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.