git

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package git provides helper functions to execute common Git commands by wrapping the system's git binary using os/exec.

Index

Examples

Constants

This section is empty.

Variables

View Source
var TokenProvider func() string

TokenProvider, when set, returns a GitHub token used to authenticate HTTPS operations against github.com so private repositories can be cloned and pulled non-interactively. The token is supplied to git via GIT_CONFIG_* environment variables (an http extraheader scoped to https://github.com/), so it is never written to a repository's .git/config or exposed in the process argument list.

Functions

func Clone

func Clone(ctx context.Context, url, targetDir string, opts CloneOptions) error

Clone executes a git clone command for the given URL into the target directory.

Example

ExampleClone demonstrates a shallow, single-branch, blobless partial clone — the combination Corral uses to minimise bandwidth and disk for large mirrors.

package main

import (
	"context"
	"log"

	"github.com/sebastienrousseau/corral/internal/git"
)

func main() {
	ctx := context.Background()
	opts := git.CloneOptions{
		SingleBranch: true,
		Blobless:     true,
		Depth:        1,
	}
	if err := git.Clone(ctx, "https://github.com/sebastienrousseau/corral.git", "/tmp/corral", opts); err != nil {
		log.Printf("clone failed: %v", err)
	}
}

func CurrentBranch

func CurrentBranch(targetDir string) (string, error)

CurrentBranch retrieves the name of the currently checked-out branch.

func Pull

func Pull(ctx context.Context, targetDir string, recurseSubmodules bool) error

Pull executes a git pull --rebase --autostash command in the target directory. If recurseSubmodules is true, it appends the --recurse-submodules flag.

Signature verification is explicitly disabled for the merge/rebase so an unattended sync never aborts on unsigned or untrusted commits when the user has merge.verifySignatures / rebase.verifySignatures enabled globally. This overrides those settings for these invocations only and does not change the user's configuration.

Example

ExamplePull demonstrates updating an existing clone with rebase + autostash, recursing into submodules.

package main

import (
	"context"
	"log"

	"github.com/sebastienrousseau/corral/internal/git"
)

func main() {
	ctx := context.Background()
	if err := git.Pull(ctx, "/tmp/corral", true); err != nil {
		log.Printf("pull failed: %v", err)
	}
}

func RemoteOrigin

func RemoteOrigin(targetDir string) (string, error)

RemoteOrigin retrieves the remote origin URL of the target directory.

Types

type CloneOptions added in v0.0.3

type CloneOptions struct {
	// RecurseSubmodules, when true, clones submodules recursively by adding
	// the --recurse-submodules flag.
	RecurseSubmodules bool
	// SingleBranch, when true, clones only the history of the default branch
	// by adding the --single-branch flag.
	SingleBranch bool
	// Blobless, when true, performs a blobless partial clone by adding the
	// --filter=blob:none flag, deferring blob downloads until needed.
	Blobless bool
	// Depth, when greater than zero, creates a shallow clone truncated to the
	// given number of commits by adding the --depth flag.
	Depth int
}

CloneOptions configures optional clone-time performance and layout flags.

Jump to

Keyboard shortcuts

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