gitops

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gitops wraps the git and gh commands needed to read the default branch of a repo and to land a change on it — pushing directly when allowed, or opening an auto-merge PR when the branch is protected. The flow mirrors the proven all-repos-codegrapher.sh script.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone(cloneURL, dest string) error

Clone clones cloneURL into dest (creating parent dirs).

func DefaultBranch

func DefaultBranch(repoPath string) (string, error)

DefaultBranch returns the remote's default branch (e.g. "main"). It first refreshes origin/HEAD from the remote, because a local clone's cached origin/HEAD can be stale (e.g. the repo was renamed master -> main after the clone was made), which would otherwise yield the wrong branch.

func Fetch

func Fetch(repoPath string) error

Fetch updates remote refs.

func LocalState

func LocalState(repoPath string) (dirty bool, reason string, err error)

LocalState reports whether repoPath has uncommitted changes (including untracked files) or local commits not present on any remote. The reason string names the first condition found.

func Pull

func Pull(repoPath string) error

Pull runs `git pull --quiet` on the currently checked-out branch of repoPath.

func ShowFile

func ShowFile(repoPath, ref, path string) (content string, ok bool, err error)

ShowFile returns the contents of path at ref (e.g. "origin/main"), and a false ok when the file does not exist at that ref.

func WorktreeChanged

func WorktreeChanged(dir string) (bool, error)

WorktreeChanged reports whether the worktree at dir has any uncommitted changes (tracked edits or untracked files), via `git status --porcelain`.

Types

type LandOptions

type LandOptions struct {
	DefaultBranch string
	CommitMessage string
	PRBranch      string
	PRTitle       string
	PRBody        string
}

LandOptions configures how a change is committed and pushed.

type Mutator

type Mutator func(worktreePath string) (changed bool, detail string, err error)

Mutator edits files inside the worktree and reports whether it changed anything along with a human-readable detail.

type Outcome

type Outcome struct {
	Changed bool
	Detail  string
	PRURL   string
}

Outcome describes what Land did.

func Land

func Land(repoPath string, opt LandOptions, mutate Mutator) (Outcome, error)

Land fetches, creates a detached worktree at origin/<default>, runs mutate, and — if it changed files — commits and pushes to the default branch, falling back to a PR with auto-merge when the push is rejected (protected branch).

type RepoStatus

type RepoStatus struct {
	Modified   []string // tracked files with changes
	Untracked  []string // untracked files
	Conflicted []string // merge-conflict paths
	Unpushed   []string // `git log --branches --not --remotes --oneline` lines
	Stashed    []string // `git stash list` lines
}

RepoStatus is git working-tree/history state relevant to sync decisions and to reporting why a repo needs attention.

func Status

func Status(repoPath string) (RepoStatus, error)

Status reads repoPath's working tree, stash, and unpushed-commit state.

func (RepoStatus) Dirty

func (s RepoStatus) Dirty() bool

Dirty reports whether s represents any state — working tree, stash, or unpushed commits — that should block automatically removing an archived repo's local clone.

func (RepoStatus) Summary

func (s RepoStatus) Summary() string

Summary renders a short human-readable description of s, e.g. "3 modified files, 1 untracked file". Empty when nothing is set.

func (RepoStatus) WorkingTreeDirty

func (s RepoStatus) WorkingTreeDirty() bool

WorkingTreeDirty reports whether the working tree itself has changes (modified, untracked, or conflicted files) — the check used to decide whether it is safe to `git pull`.

Jump to

Keyboard shortcuts

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