gitfacts

package
v1.60.0 Latest Latest
Warning

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

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

Documentation

Overview

Package gitfacts reads cheap git facts straight from the files of a repository: HEAD, config, the gitdir pointer of a linked worktree and the registrations under worktrees/. It never runs git and never walks a tree, which is what makes it safe to call per project on every request; the package that runs the binary is internal/git, and the two deliberately do not meet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OriginName

func OriginName(raw string) string

OriginName is the short display form of a remote url: host and path, no scheme, no user, no .git suffix.

func OriginWebURL

func OriginWebURL(raw string) string

OriginWebURL turns a remote url into the https address a browser can open, or "" when the url has no such form.

func PruneWorktreeRegistration

func PruneWorktreeRegistration(dir string)

PruneWorktreeRegistration removes the metadata directory a linked worktree stands registered under in its main repository, what a later `git worktree prune` would do; without it the main keeps the worktree's branch checked out and refuses it. The registration's gitdir file is read back first, only an entry that names this very worktree is taken; any doubt, a dangling pointer included, leaves the main untouched. The one write of this package, and a file operation like everything else in it.

Types

type Info

type Info struct {
	Repo          bool
	Branch        string   // checked-out branch, or a short hash on a detached HEAD
	Origin        string   // the origin remote's url as written in the config
	Worktree      bool     // dir is a linked worktree (.git is a gitdir pointer file)
	WorktreeMain  string   // main repository path, "" when it cannot be derived
	WorktreePaths []string // worktree directories registered in this repository
}

Info is what the file reads answer about one directory.

func Read

func Read(dir string) Info

Read collects the facts about dir. A directory without a .git answers the zero Info, and every fact that cannot be read stays empty instead of becoming an error: these are chips on a list, not a diagnosis.

Jump to

Keyboard shortcuts

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