{"modulePath":"github.com/Didstopia/githubby","version":"v1.1.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package git\n\nPackage git provides Git operations for repository management\n\n## Constants\n\n```go\nconst PullRefSpec = \"+refs/pull/*/head:refs/pull/*/head\"\n```\nPullRefSpec maps GitHub's pull request heads to the same names locally\n\n## Variables\n\n```go\nvar (\n\tErrGitNotInstalled = errors.New(\"git is not installed or not in PATH\")\n\tErrNotAGitRepo     = errors.New(\"not a git repository\")\n\tErrCloneFailed     = errors.New(\"git clone failed\")\n\tErrPullFailed      = errors.New(\"git pull failed\")\n\tErrFetchFailed     = errors.New(\"git fetch failed\")\n\tErrSubmoduleFailed = errors.New(\"git submodule update failed\")\n)\n```\nCommon errors\n\n```go\nvar (\n\tErrLFSNotInstalled = errors.New(\"git-lfs is not installed\")\n\tErrLFSInstallFail  = errors.New(\"failed to install git-lfs\")\n\tErrLFSFetchFailed  = errors.New(\"git lfs fetch failed\")\n)\n```\nCommon LFS errors\n\n```go\nvar (\n\tErrLsRemoteFailed = errors.New(\"git ls-remote failed\")\n\tErrFsckFailed     = errors.New(\"git fsck failed\")\n\tErrLFSListFailed  = errors.New(\"git lfs ls-files failed\")\n)\n```\nErrors from the backup checks\n\n```go\nvar (\n\tErrDirtyWorkTree  = errors.New(\"local changes, working tree not updated\")\n\tErrCheckoutFailed = errors.New(\"working tree not updated\")\n)\n```\nErrors from updating the working tree\n\n```go\nvar ErrSubmoduleStatusFailed = errors.New(\"git submodule status failed\")\n```\nErrSubmoduleStatusFailed is returned when git can't report on the submodules\n\n## Types\n\n```go\ntype Commander interface {\n\t// Run executes a git command and returns an error if it fails\n\tRun(ctx context.Context, dir string, args ...string) error\n\n\t// Output executes a git command and returns its output\n\tOutput(ctx context.Context, dir string, args ...string) (string, error)\n}\n```\nCommander provides an interface for executing git commands This interface is used for mocking in tests\n\n```go\ntype Git struct {\n\t// GitPath is the path to the git executable\n\tGitPath string\n\t// Quiet suppresses stdout/stderr output (for TUI mode)\n\tQuiet bool\n\t// Token is the authentication token for HTTPS operations\n\tToken string\n\t// Host is the GitHub host the token is sent to (default github.com)\n\tHost string\n}\n```\nGit provides Git operations\n\n```go\nfunc New() (*Git, error)\n```\nNew creates a new Git instance\n\n```go\nfunc NewQuiet() (*Git, error)\n```\nNewQuiet creates a new Git instance that suppresses output\n\n```go\nfunc NewQuietWithToken(token string) (*Git, error)\n```\nNewQuietWithToken creates a new Git instance that suppresses output and uses auth token\n\n```go\nfunc NewWithToken(token string) (*Git, error)\n```\nNewWithToken creates a new Git instance with authentication token\n\n```go\nfunc (g *Git) Clone(ctx context.Context, url, targetDir string) error\n```\nClone clones a repository to the target directory\n\n```go\nfunc (g *Git) FetchAll(ctx context.Context, repoDir string) error\n```\nFetchAll fetches all branches from all remotes with pruning. This updates all remote-tracking branches without modifying the working directory. Use --prune to remove local references to branches deleted on remote.\n\n```go\nfunc (g *Git) FetchPullRefs(ctx context.Context, repoDir string) error\n```\nFetchPullRefs fetches the head commit of every pull request into refs/pull/\\\u003cn\u003e/head. These keep commits of fork and deleted branches. They are never pruned. FETCH\\_HEAD is left alone, since fast sync reads its time as the last full fetch.\n\n```go\nfunc (g *Git) Fsck(ctx context.Context, repoDir string) error\n```\nFsck checks a repository's object store for corruption\n\n```go\nfunc (g *Git) GetDefaultBranch(ctx context.Context, repoDir string) (string, error)\n```\nGetDefaultBranch returns the default branch of a repository\n\n```go\nfunc (g *Git) GetHEAD(ctx context.Context, repoDir string) (string, error)\n```\nGetHEAD returns the SHA of HEAD in the repository\n\n```go\nfunc (g *Git) GetLastFetchTime(repoDir string) (time.Time, error)\n```\nGetLastFetchTime returns the modification time of .git/FETCH\\_HEAD, which indicates when the repository was last fetched. Returns zero time if never fetched.\n\n```go\nfunc (g *Git) GetRemoteBranchSHA(ctx context.Context, repoDir, remote, branch string) (string, error)\n```\nGetRemoteBranchSHA returns the SHA of a remote-tracking branch (e.g., origin/main)\n\n```go\nfunc (g *Git) GetRemoteURL(ctx context.Context, repoDir string) (string, error)\n```\nGetRemoteURL returns the remote origin URL for a repository\n\n```go\nfunc (g *Git) IsGitRepo(dir string) bool\n```\nIsGitRepo checks if a directory is a git repository\n\n```go\nfunc (g *Git) LsRemoteDefaultBranch(ctx context.Context, url string) (string, error)\n```\nLsRemoteDefaultBranch returns the branch the remote's HEAD points at, or \"\" for an empty repo\n\n```go\nfunc (g *Git) LsRemoteHeads(ctx context.Context, url string) (map[string]string, error)\n```\nLsRemoteHeads returns branch name -\u003e head SHA as the remote has them\n\n```go\nfunc (g *Git) LsRemotePulls(ctx context.Context, url string) (map[string]string, error)\n```\nLsRemotePulls returns pull request number -\u003e head SHA as the remote has them\n\n```go\nfunc (g *Git) PullRefs(ctx context.Context, repoDir string) (map[string]string, error)\n```\nPullRefs returns pull request number -\u003e SHA of the local refs/pull/\\*/head refs\n\n```go\nfunc (g *Git) RemoteBranches(ctx context.Context, repoDir string) (map[string]string, error)\n```\nRemoteBranches returns branch name -\u003e SHA of the local origin/\\* remote-tracking refs\n\n```go\nfunc (g *Git) ScrubRemoteURL(ctx context.Context, repoDir string) error\n```\nScrubRemoteURL removes credentials that older versions embedded in the origin URL\n\n```go\nfunc (g *Git) SubmoduleStatus(ctx context.Context, repoDir string) ([]Submodule, error)\n```\nSubmoduleStatus lists every submodule, nested ones too, with its state. Repos without .gitmodules have none.\n\n```go\nfunc (g *Git) SubmoduleUpdate(ctx context.Context, repoDir string) error\n```\nSubmoduleUpdate syncs submodule URLs and checks out all submodules (recursively) of a repository. The token goes along per command, and SSH submodule URLs are fetched over HTTPS, since a backup host usually has no SSH keys. Repos without .gitmodules are a no-op.\n\n```go\nfunc (g *Git) UpdateWorkTree(ctx context.Context, repoDir, branch string) (moved bool, err error)\n```\nUpdateWorkTree moves the checkout to origin/\\\u003cbranch\u003e: it switches to branch if another one is checked out, then fast-forwards it. It never resets anything: with local changes it returns ErrDirtyWorkTree, and a branch that can't fast-forward returns ErrCheckoutFailed. moved is true when HEAD changed. A branch that was never fetched (an empty repo) is left alone.\n\n```go\ntype LFS struct {\n\t// LFSPath is the path to the git-lfs executable\n\tLFSPath string\n\t// Git is the underlying git instance\n\tGit *Git\n\t// Quiet suppresses stdout/stderr output (inherited from Git)\n\tQuiet bool\n}\n```\nLFS provides Git LFS operations\n\n```go\nfunc NewLFS(git *Git) *LFS\n```\nNewLFS creates a new LFS instance\n\n```go\nfunc (l *LFS) EnsureLFS(ctx context.Context) error\n```\nEnsureLFS ensures Git LFS is installed and configured\n\n```go\nfunc (l *LFS) Fetch(ctx context.Context, repoDir string) error\n```\nFetch runs 'git lfs fetch' to download LFS objects\n\n```go\nfunc (l *LFS) FetchAll(ctx context.Context, repoDir string) error\n```\nFetchAll runs 'git lfs fetch --all' to download the LFS objects of every ref, not just the checked-out one, so a backup has all of them\n\n```go\nfunc (l *LFS) Initialize(ctx context.Context) error\n```\nInitialize runs 'git lfs install' to set up Git LFS hooks\n\n```go\nfunc (l *LFS) Install(ctx context.Context) error\n```\nInstall attempts to install git-lfs using the system package manager\n\n```go\nfunc (l *LFS) IsInstalled() bool\n```\nIsInstalled checks if git-lfs is installed\n\n```go\nfunc (l *LFS) MissingLFSObjects(ctx context.Context, repoDir string) ([]string, error)\n```\nMissingLFSObjects returns the LFS objects referenced anywhere in history that are not stored locally with the right content. It needs git-lfs.\n\n```go\nfunc (l *LFS) Pull(ctx context.Context, repoDir string) error\n```\nPull runs 'git lfs pull' to download LFS objects\n\n```go\nfunc (l *LFS) RepoUsesLFS(repoDir string) bool\n```\nRepoUsesLFS checks if a repository uses Git LFS\n\n```go\ntype MockCommander struct {\n\t// RunFunc is called when Run is invoked\n\tRunFunc func(ctx context.Context, dir string, args ...string) error\n\n\t// OutputFunc is called when Output is invoked\n\tOutputFunc func(ctx context.Context, dir string, args ...string) (string, error)\n\n\t// Calls records all method calls for verification\n\tCalls []MockCommanderCall\n}\n```\nMockCommander is a mock implementation of Commander for testing\n\n```go\nfunc NewMockCommander() *MockCommander\n```\nNewMockCommander creates a new mock commander\n\n```go\nfunc (m *MockCommander) CallCount(method string) int\n```\nCallCount returns the number of times a method was called\n\n```go\nfunc (m *MockCommander) Output(ctx context.Context, dir string, args ...string) (string, error)\n```\nOutput implements Commander.Output\n\n```go\nfunc (m *MockCommander) Reset()\n```\nReset clears all recorded calls\n\n```go\nfunc (m *MockCommander) Run(ctx context.Context, dir string, args ...string) error\n```\nRun implements Commander.Run\n\n```go\ntype MockCommanderCall struct {\n\tMethod string\n\tDir    string\n\tArgs   []string\n}\n```\nMockCommanderCall records a method call\n\n```go\ntype Submodule struct {\n\t// Path is relative to the top repo, nested submodules included\n\tPath string\n\t// SHA is the commit the parent records for it\n\tSHA string\n\t// State is ' ' when checked out at SHA, '-' when not checked out,\n\t// '+' when at another commit and 'U' when it has merge conflicts\n\tState byte\n}\n```\nSubmodule is one line of git submodule status\n\n","path":"github.com/Didstopia/githubby/internal/git","name":"git","synopsis":"Package git provides Git operations for repository management","isRedistributable":true}
