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 ¶
This section is empty.
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)
}
}
Output:
func CurrentBranch ¶
CurrentBranch retrieves the name of the currently checked-out branch.
func Pull ¶
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)
}
}
Output:
func RemoteOrigin ¶
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.