gitutil

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package gitutil provides the minimal git introspection the context-sync configurator needs: repo root, origin remote, current branch, HEAD sha, plus an idempotent .gitignore helper anchored at the repo root (DX-10).

It shells out to the `git` binary (already a hard dependency of the workflow) and degrades gracefully: every function returns a usable zero value when not in a repo or when git is unavailable, so callers never crash a hook.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureGitignore

func EnsureGitignore(root, pattern string) (bool, error)

EnsureGitignore makes sure pattern appears in <root>/.gitignore. It reads the file (creating it if absent), checks for an exact-line match, and appends the pattern atomically only if missing. Returns true if it added the pattern.

func Slug added in v0.6.2

func Slug(remoteURL string) string

Slug normalizes a git remote URL to a canonical "owner/repo" project slug (FR-7): the last two path segments, with any ".git" suffix and surrounding noise stripped. It collapses the common remote shapes to the same value:

git@github.com:owner/repo.git        → owner/repo
https://github.com/owner/repo.git    → owner/repo
https://github.com/owner/repo        → owner/repo
ssh://git@host:22/owner/repo.git     → owner/repo

Returns "" when no usable owner/repo can be derived (callers fall back to the repo-root basename for the "Local / no remote" bucket, FR-10).

Types

type Repo

type Repo struct {
	Root      string
	RemoteURL string
	Branch    string
	HeadSha   string
}

Repo describes the git context of a directory.

func Detect

func Detect(dir string) (*Repo, bool)

Detect inspects dir (or cwd when dir is "") and returns its git context. The boolean reports whether dir is inside a git work tree.

Jump to

Keyboard shortcuts

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