gitexec

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package gitexec wraps the system git binary. gitdr shells out to real git for faithful clone/bundle semantics (and later git-lfs). Auth is injected via GIT_CONFIG_* env, scoped to the clone host, so tokens never reach argv.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LFSAvailable

func LFSAvailable() bool

LFSAvailable reports whether the git-lfs binary is installed.

Types

type Git

type Git struct {
	// contains filtered or unexported fields
}

Git runs git subcommands.

func New

func New(logger *slog.Logger) *Git

New returns a Git runner. A nil logger falls back to slog.Default().

func (*Git) BundleAll

func (g *Git) BundleAll(ctx context.Context, repoDir, bundlePath string) error

BundleAll bundles every ref plus HEAD inside repoDir so `git clone <bundle>` checks out the default branch on restore.

func (*Git) BundleVerify

func (g *Git) BundleVerify(ctx context.Context, bundlePath string) error

BundleVerify runs `git bundle verify bundlePath`.

From inside a scratch repository, because git refuses otherwise: "need a repository to verify a bundle". Verification checks the bundle's prerequisites against a repository's objects, so git wants one even when — as here — the bundle is self-contained and there is nothing to check against. An empty one answers the question honestly: a bundle that records a complete history verifies against it, and a truncated or corrupt one does not.

Without this, restore failed on every bundle it was given.

func (*Git) CloneFromBundle

func (g *Git) CloneFromBundle(ctx context.Context, bundlePath, dir string) error

CloneFromBundle restores a repo by cloning from a bundle file.

func (*Git) CloneMirror

func (g *Git) CloneMirror(ctx context.Context, repoURL, dir string, opts Options) error

CloneMirror runs `git clone --mirror url dir`.

func (*Git) HasRefs added in v0.1.7

func (g *Git) HasRefs(ctx context.Context, repoDir string) (bool, error)

HasRefs reports whether repoDir contains at least one ref.

A repository created and never pushed to has none, and `git bundle create` refuses to write an empty bundle: "fatal: Refusing to create empty bundle." Without this check that refusal reads as a failed repository, and one unused project in an organisation is enough to make every backup of it fail for ever.

Asked of the local mirror rather than the provider's API, because it is the state that actually matters: a clone that produced no refs is what bundling has to cope with, whatever the API said. `git clone --mirror` fails loudly on a partial fetch, so zero refs after a successful clone means the remote genuinely has none.

func (*Git) LFSCheckout

func (g *Git) LFSCheckout(ctx context.Context, repoDir string) error

LFSCheckout materializes LFS files in the working tree from local objects (no network).

func (*Git) LFSFetchAll

func (g *Git) LFSFetchAll(ctx context.Context, repoDir, repoURL string, opts Options) error

LFSFetchAll downloads all LFS objects referenced by any ref into repoDir, reusing the clone's host-scoped auth.

func (*Git) LFSInstallLocal added in v0.1.5

func (g *Git) LFSInstallLocal(ctx context.Context, repoDir string) error

LFSInstallLocal writes the lfs clean/smudge filters into repoDir's own config.

A repository cloned from a bundle has no filter.lfs.* configuration, and without it "git lfs checkout" exits 0 and does nothing — the working tree keeps 130-byte pointer files. That makes a successful restore depend on whether the operator had already run "git lfs install" on the machine, which in a disaster is exactly the machine that is new.

--skip-repo, because a restored copy needs the filters, not the pre-push hook.

func (*Git) LFSPointersRemaining added in v0.1.5

func (g *Git) LFSPointersRemaining(ctx context.Context, repoDir string) ([]string, error)

LFSPointersRemaining lists tracked paths that are still pointer files.

Checked rather than assumed: "git lfs checkout" reports success whether or not it replaced anything, so its exit code says a command ran, not that the bytes are there. This reads the working tree back and is what lets restore fail instead of handing over pointers.

type Options

type Options struct {
	// AuthHeader, if set, is sent as an HTTP Authorization header (e.g.
	// "Authorization: Basic ...") scoped to the clone host, via env not argv.
	AuthHeader string
}

Options configures a git invocation.

Jump to

Keyboard shortcuts

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