sync

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 6 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
	IsMerged(repoPath, branch, base string) (bool, error)
	Checkout(repoPath, branch 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) (bool, error)
	StashPop(repoPath string) error
	RebaseAbort(repoPath string) error
	MergeAbort(repoPath string) error
	RevListCount(repoPath, spec string) (int, 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
	SwitchMergedBranch bool
}

Options controls sync behavior.

type RealGitOps

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

RealGitOps implements GitOps using the pkg/git package and the hybrid merge detector for IsMerged checks.

func NewRealGitOps added in v0.6.0

func NewRealGitOps(detector *merge.Detector) *RealGitOps

NewRealGitOps creates a RealGitOps that delegates IsMerged calls to the given merge detector (which combines git + GitHub API checks).

func (*RealGitOps) Checkout added in v0.3.0

func (r *RealGitOps) Checkout(repoPath, branch string) error

Checkout switches to the given branch.

func (*RealGitOps) CurrentBranch

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

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

func (*RealGitOps) DefaultBranch

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

DefaultBranch returns the default branch name.

func (*RealGitOps) Fetch

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

Fetch fetches from the given remote.

func (*RealGitOps) HasRemote

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

HasRemote returns true if the given remote exists.

func (*RealGitOps) IsClean

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

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

func (*RealGitOps) IsMerged added in v0.3.0

func (r *RealGitOps) IsMerged(repoPath, branch, base string) (bool, error)

IsMerged returns true if the given branch has been merged into base. It delegates to the hybrid merge detector which checks both local git state and GitHub PR status.

func (*RealGitOps) MergeAbort

func (r *RealGitOps) MergeAbort(repoPath string) error

MergeAbort aborts an in-progress merge.

func (*RealGitOps) MergeBase

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

MergeBase returns the best common ancestor commit between two refs.

func (*RealGitOps) MergeTree

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

MergeTree performs a three-way merge-tree simulation.

func (*RealGitOps) Pull

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

Pull pulls from the default remote using the given strategy.

func (*RealGitOps) RebaseAbort

func (r *RealGitOps) RebaseAbort(repoPath string) error

RebaseAbort aborts an in-progress rebase.

func (*RealGitOps) RevListCount added in v0.7.0

func (r *RealGitOps) RevListCount(repoPath, spec string) (int, error)

RevListCount returns the number of commits in the given rev-list spec.

func (*RealGitOps) StashPop

func (r *RealGitOps) StashPop(repoPath string) error

StashPop applies and removes the most recent stash entry.

func (*RealGitOps) StashPush

func (r *RealGitOps) StashPush(repoPath string, message string) (bool, error)

StashPush stashes working tree changes with the given message. It returns true if a stash entry was actually created.

type Result

type Result struct {
	RepoPath      string
	RepoName      string
	Status        Status
	Message       string
	CommitsPulled int // number of commits pulled, populated when known
}

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
	// Switched indicates the repo was on a merged branch and switched to default.
	Switched
	// UpToDate indicates the repository was already current with the remote.
	UpToDate
)

func (Status) String added in v0.7.0

func (s Status) String() string

String returns the human-readable name of a Status value.

Jump to

Keyboard shortcuts

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