gitrepo

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package gitrepo locates a worktree and reads its branch without running git.

The status line renders once a second in every open session, so the hot path reads two small files instead of paying for a subprocess.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBranch

func DefaultBranch(root, override string) string

DefaultBranch resolves what this repo calls its trunk, so master and trunk repos are not silently compared against a main that does not exist.

func IsTrunk

func IsTrunk(trunk, branch string) bool

IsTrunk reports whether a branch is the repo's trunk, accepting both a local name and a remote-qualified one.

Types

type Repo

type Repo struct {
	Root   string
	GitDir string
	Branch string
}

func Locate

func Locate(dir string) (Repo, bool)

Locate walks up from dir looking for .git, honouring the gitdir: pointer file that a linked worktree uses in place of a directory.

func (Repo) Key

func (r Repo) Key() string

Key turns a worktree path into a filename safe on every platform.

Replacing only the path separator is not enough: on Windows that leaves the drive colon in place, and `< > : " / \ | ? *` are all illegal in a filename, so the cache file could never be created. Anything outside the safe set is folded to an underscore, and an FNV suffix keeps two paths that sanitise alike from sharing one cache entry.

func (Repo) Project

func (r Repo) Project() string

Project is the repository every one of its worktrees shares, so sibling worktrees of one repo cannot be mistaken for worktrees of another.

func (Repo) Worktree

func (r Repo) Worktree() string

Worktree is the name git itself uses for this worktree, matching what a harness reports as workspace.git_worktree. A linked worktree keeps its git directory at <main>/.git/worktrees/<name>, so the name is already on disk.

Jump to

Keyboard shortcuts

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