gitutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gitutil provides shared git safety primitives used by both the daemon (pull/fetch) and CLI (push/commit) code paths.

Index

Constants

View Source
const MinFetchHeadAge = 2 * time.Minute

MinFetchHeadAge is the minimum age of FETCH_HEAD before we'll fetch again. Prevents redundant fetches if another process fetched recently.

Variables

This section is empty.

Functions

func FetchHeadAge

func FetchHeadAge(repoPath string) (time.Duration, bool)

FetchHeadAge returns how long ago FETCH_HEAD was last modified. Returns (0, false) if FETCH_HEAD doesn't exist or can't be read.

func HasLockFiles

func HasLockFiles(gitDir string) []string

HasLockFiles checks .git/ for stale lock files that block git operations. Returns the names of lock files found (empty slice = safe to proceed).

func IsRebaseInProgress

func IsRebaseInProgress(repoPath string) bool

IsRebaseInProgress checks whether the repo is stuck in a broken rebase state. Returns true if .git/rebase-merge or .git/rebase-apply exists.

func IsSafeForGitOps

func IsSafeForGitOps(repoPath string) error

IsSafeForGitOps combines lock file and rebase state checks into a single pre-flight check. Returns nil if safe to proceed, or an error describing why the repo is blocked.

func RunGit

func RunGit(ctx context.Context, repoPath string, args ...string) (string, error)

RunGit executes a git command with context for timeout/cancellation. Output is auto-sanitized to remove credentials. Use repoPath="" for commands that don't need -C.

func SanitizeOutput

func SanitizeOutput(output string) string

SanitizeOutput removes credentials from git command output. Replaces oauth2:TOKEN@ patterns with oauth2:***@ to prevent credential leaks in logs.

func StripLFSConfig

func StripLFSConfig(repoPath string)

StripLFSConfig removes lfs.repositoryformatversion from local git config. This config is set by git-lfs when filter.lfs.required=true is global, but it causes HTTP 403 on push to GitLab when the server-side ALB doesn't expect LFS-aware clients. Safe to call on any repo — no-op if not set.

Types

This section is empty.

Jump to

Keyboard shortcuts

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