sync

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package sync implements repository synchronization logic for keeping local git repositories up to date with their remotes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitOps

type GitOps interface {
	Fetch(repoPath, remote string) error
	IsClean(repoPath string) (bool, error)
	CurrentBranch(repoPath string) (string, error)
	DefaultBranch(repoPath string) (string, error)
	HasRemote(repoPath, remote string) bool
	Pull(repoPath string, strategy string) error
	MergeBase(repoPath string, ref1, ref2 string) (string, error)
	MergeTree(repoPath string, base, local, remote string) (string, bool, error)
	StashPush(repoPath string, message string) error
	StashPop(repoPath string) error
	RebaseAbort(repoPath string) error
	MergeAbort(repoPath string) error
}

GitOps defines the git operations needed by the sync logic. This interface enables testing with mocks.

type Options

type Options struct {
	Strategy  string // "rebase", "merge", "ff-only"
	SkipDirty bool
	AutoStash bool
	DryRun    bool
	Verbose   bool
}

Options controls sync behavior.

type RealGitOps

type RealGitOps struct{}

RealGitOps implements GitOps using the pkg/git package.

func (RealGitOps) CurrentBranch

func (RealGitOps) CurrentBranch(repoPath string) (string, error)

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

func (RealGitOps) DefaultBranch

func (RealGitOps) DefaultBranch(repoPath string) (string, error)

DefaultBranch returns the default branch name.

func (RealGitOps) Fetch

func (RealGitOps) Fetch(repoPath, remote string) error

Fetch fetches from the given remote.

func (RealGitOps) HasRemote

func (RealGitOps) HasRemote(repoPath, remote string) bool

HasRemote returns true if the given remote exists.

func (RealGitOps) IsClean

func (RealGitOps) IsClean(repoPath string) (bool, error)

IsClean returns true if the working tree has no uncommitted changes.

func (RealGitOps) MergeAbort

func (RealGitOps) MergeAbort(repoPath string) error

MergeAbort aborts an in-progress merge.

func (RealGitOps) MergeBase

func (RealGitOps) MergeBase(repoPath string, ref1, ref2 string) (string, error)

MergeBase returns the best common ancestor commit between two refs.

func (RealGitOps) MergeTree

func (RealGitOps) MergeTree(repoPath string, base, local, remote string) (string, bool, error)

MergeTree performs a three-way merge-tree simulation.

func (RealGitOps) Pull

func (RealGitOps) Pull(repoPath string, strategy string) error

Pull pulls from the default remote using the given strategy.

func (RealGitOps) RebaseAbort

func (RealGitOps) RebaseAbort(repoPath string) error

RebaseAbort aborts an in-progress rebase.

func (RealGitOps) StashPop

func (RealGitOps) StashPop(repoPath string) error

StashPop applies and removes the most recent stash entry.

func (RealGitOps) StashPush

func (RealGitOps) StashPush(repoPath string, message string) error

StashPush stashes working tree changes with the given message.

type Result

type Result struct {
	RepoPath string
	RepoName string
	Status   Status
	Message  string
}

Result represents the outcome of syncing a single repository.

func All

func All(repos []string, opts Options, git GitOps, workers int, onResult ResultFunc) []Result

All syncs all provided repository paths using the given number of workers and returns results. An optional callback is called sequentially as each repo completes.

type ResultFunc added in v0.2.1

type ResultFunc func(completed, total int, result Result)

ResultFunc is called sequentially as each repo finishes syncing. completed is the number of repos finished so far; total is the total number of repos being synced.

type Status

type Status int

Status represents the outcome of syncing a single repository.

const (
	// Synced indicates the repository was successfully updated.
	Synced Status = iota
	// Skipped indicates the repository was intentionally skipped.
	Skipped
	// Failed indicates an error occurred while syncing.
	Failed
)

Jump to

Keyboard shortcuts

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