gitmulti

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitmulti runs one Git operation across several repositories, collecting each repository's outcome instead of stopping at the first failure.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPushGraph = errors.New("gitmulti: invalid push dependencies")

ErrInvalidPushGraph reports invalid parent indices or cyclic dependencies.

View Source
var ErrNoRepo = errors.New("gitmulti: target has no repository")

ErrNoRepo reports that a target has no repository.

Functions

func MovedSubmodules

func MovedSubmodules(before, after []gitx.Submodule, exclude []string) []string

MovedSubmodules returns paths whose recorded commit changed and still needs checking out, in after order. Paths in exclude are left out. It can be called from any goroutine with read-only inputs.

Types

type BatchResult

type BatchResult struct {
	Repos    []RepoOutcome
	Precheck *PrecheckError // Set when nothing ran because a check failed.
}

BatchResult lists outcomes in target order. Treat Repos and Precheck as read-only when sharing it between goroutines.

func CheckoutAll

func CheckoutAll(ctx context.Context, targets []Target, name string) BatchResult

CheckoutAll checks out name in target order, restoring successful checkouts if another target fails. It can run from any goroutine. Keep targets unchanged and avoid overlapping writes to these repositories.

func CreateBranchAll

func CreateBranchAll(ctx context.Context, targets []Target, name string, checkout bool) BatchResult

CreateBranchAll creates name from each repository's HEAD, optionally switching to it. It can run from any goroutine. Keep targets unchanged and avoid overlapping writes to these repositories.

func MergeAll

func MergeAll(ctx context.Context, targets []Target, rev string, o gitx.MergeOptions) BatchResult

MergeAll merges rev in target order. Failed merges are left in place, and merging continues in the other repositories unless canceled. It can run from any goroutine. Keep targets unchanged and avoid overlapping writes to these repositories.

func (BatchResult) Err

func (b BatchResult) Err() error

Err returns the precheck error or the execution errors in target order.

type CommonBranches

type CommonBranches struct {
	Local  []string // Local names present in every repository.
	Remote []string // Remote-tracking names present in every repository.
	// Checkoutable includes names for which each repo has a local branch or
	// exactly one matching remote-tracking branch.
	Checkoutable []string
	Current      string // The current branch when all agree, else empty.
	Diverged     bool   // Current branches or detached HEADs differ.
}

CommonBranches describes what the repositories share. It can be shared by value with its name lists kept read-only.

func Common

func Common(repos []RepoBranches) CommonBranches

Common computes branch intersections without Git. It can be called from any goroutine with read-only snapshots.

type Drift

type Drift int

Drift describes a submodule's checkout relative to the parent's recorded commit. It can be shared by value.

const (
	DriftNone Drift = iota
	DriftAhead
	DriftBehind
	DriftDiverged
	DriftUnknown
)

func SubmoduleDrift

func SubmoduleDrift(ctx context.Context, sub *gitx.Repo, recorded, checked string) (Drift, error)

SubmoduleDrift reports the ancestry relationship between the checkout and the recorded commit using the submodule's repository. It can be called from any goroutine. A missing commit gives DriftUnknown so callers can fetch it.

type Error

type Error struct{ Failed []Result }

Error lists the targets that failed. errors.Is and errors.As can see each target's error. An Error can be shared between goroutines for read-only use.

func (*Error) Error

func (e *Error) Error() string

Error reports one line per failed target, replacing line breaks with spaces.

func (*Error) Unwrap

func (e *Error) Unwrap() []error

Unwrap returns the original errors, in target order.

type PrecheckError

type PrecheckError struct{ Problems []Problem }

PrecheckError lists the targets blocking a branch batch. Treat Problems and its entries as read-only when sharing it between goroutines.

func (*PrecheckError) Error

func (e *PrecheckError) Error() string

func (*PrecheckError) Unwrap

func (e *PrecheckError) Unwrap() []error

Unwrap returns the underlying repository errors in target order.

type Problem

type Problem struct {
	Target Target
	Kind   ProblemKind
	Paths  []string // Up to twenty paths for ProblemDirty.
	Err    error    // The original error for ProblemError.
}

Problem is one target's reason for blocking a branch batch. Share by value with Paths and Err kept read-only.

type ProblemKind

type ProblemKind int

ProblemKind classifies a precheck problem and can be shared by value.

const (
	ProblemDirty ProblemKind = iota
	ProblemOperation
	ProblemMissingBranch
	ProblemBranchExists
	ProblemError
)

type Progress

type Progress func(t Target, line string)

Progress receives one progress line for a target. Calls within one batch are serialized. If shared across concurrent batches, Progress must be safe for concurrent use. It should return promptly and must not run Git on the target's repository because it can run under the repository's write lock.

type PushPreviewResult

type PushPreviewResult struct {
	Result
	Preview gitx.PushPreview
	// Unpushed lists child paths whose recorded commits are neither on a
	// remote-tracking ref of the child nor in the child's outgoing preview.
	Unpushed []string
	// NeedsChild lists child paths whose recorded commits are only in the
	// child's outgoing preview. Those children must be pushed first.
	NeedsChild []string
}

PushPreviewResult is the local push preview of one repository. It can be shared by value if its slices and error are treated as read-only.

func PushPreviewAll

func PushPreviewAll(ctx context.Context, targets []PushTarget, limit int) []PushPreviewResult

PushPreviewAll previews targets in input order with at most four concurrent reads. Limit caps each repository's preview. It can be called from any goroutine. Keep targets unchanged during the call.

type PushResult

type PushResult struct {
	Result
	Blocked []string // Submodule paths that kept this parent from being pushed.
}

PushResult is the outcome of pushing one repository. It can be shared by value if its Blocked slice and error are treated as read-only.

func PushAll

func PushAll(ctx context.Context, targets []PushTarget, progress Progress) []PushResult

PushAll pushes serially, with children before parents and input order among each level, and returns results in input order. A parent is pushed even if a child failed; Git's submodule check refuses it only when it records a commit missing from the child's remotes. It can be called from any goroutine. Keep targets unchanged during the call. Progress calls within the batch are serialized.

type PushTarget

type PushTarget struct {
	Target
	Options gitx.RemoteOptions
	Parent  int
	Path    string
}

PushTarget is one repository to push. Parent indexes the containing repository in the batch, or is -1. Path is the slash path in that parent. A PushTarget can be shared by value between goroutines.

type RepoBranches

type RepoBranches struct {
	Target   Target
	Current  string // Local branch name, empty when detached or on error.
	Head     string // Full commit of HEAD, empty for an unborn branch.
	Detached bool
	Branches []gitx.Branch
	Err      error
	// contains filtered or unexported fields
}

RepoBranches is one target's branch state. Share by value and treat its branch and remote slices and error as read-only.

func ReadBranches

func ReadBranches(ctx context.Context, targets []Target, limit int) []RepoBranches

ReadBranches reads every target's branches and HEAD in target order, with at most limit in flight. It can be called from any goroutine. Keep targets unchanged during the call and the result read-only when sharing it.

type RepoOutcome

type RepoOutcome struct {
	Result
	RolledBack  bool   // The target was restored after another target failed.
	RollbackErr error  // Restoration failed. Final is the observed state.
	Final       string // Branch name or short detached commit after the batch.
}

RepoOutcome is one target's branch batch outcome. Share by value, with errors kept read-only.

type Result

type Result struct {
	Target  Target
	Err     error
	Skipped bool
}

Result is one target's outcome. Err is nil on success. Skipped means the operation did not start. Run skips when the context ends and sets Err to ctx.Err(). Branch batches and pushes may also skip after a failed precheck or earlier operation. A Result can be shared by value. Treat its error as read-only when shared.

type Results

type Results []Result

Results are in the order of the given targets. A Results value can be shared between goroutines for read-only use.

func Commit

func Commit(ctx context.Context, targets []Target, msg string, o gitx.CommitOptions) Results

Commit applies the same message and options to each target in order, one at a time. A failure does not stop later commits. Commit can be called from any goroutine. Keep targets unchanged while the call is in progress.

func Fetch

func Fetch(ctx context.Context, targets []Target, o gitx.RemoteOptions, limit int, progress Progress) Results

Fetch fetches every target with the given concurrency limit. It can be called from any goroutine. Keep targets unchanged during the call.

func Run

func Run(ctx context.Context, targets []Target, limit int, fn func(context.Context, Target) error) Results

Run calls fn for every target, at most limit at a time (values below one mean one), and waits for all started calls to return. Each call receives a context derived from ctx. Failures are collected and targets not started when ctx ends are skipped. Run can be called from any goroutine. Keep the input slice unchanged during the call and make fn safe for concurrent use when limit exceeds one.

func (Results) Err

func (rs Results) Err() error

Err returns nil when every target succeeded, otherwise an *Error.

func (Results) Failed

func (rs Results) Failed() []Result

Failed returns the results whose Err is not nil, in order.

type Target

type Target struct {
	Repo *gitx.Repo
	Name string
}

Target is one repository taking part in a batch. Name identifies it to the user in errors. A Target can be shared by value between goroutines.

type UpdateResult

type UpdateResult struct {
	Result
	Range gitx.UpdateResult
}

UpdateResult is one target's update outcome, with the HEAD range it saw. It can be shared by value between goroutines, with its error read-only.

func Update

func Update(ctx context.Context, targets []Target, o gitx.UpdateOptions, limit int, progress Progress) []UpdateResult

Update updates every target from its upstream with the given concurrency limit. It can be called from any goroutine. Keep targets unchanged during the call and treat the returned slice as read-only when sharing it.

Jump to

Keyboard shortcuts

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