gitbranch

package
v1.132.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package gitbranch resolves the current branch of a git working directory by reading .git metadata directly, without shelling out to the git binary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Current

func Current(dir string) string

Current returns the current branch name (or the short commit for a detached HEAD) for the repository containing dir, walking up parent directories until a .git entry is found. It returns "" when dir is empty or not inside a repository.

Types

type Watcher added in v1.132.0

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher reports changes to the current branch of a working directory.

func Watch added in v1.132.0

func Watch(ctx context.Context, dir string) (*Watcher, error)

Watch starts watching Git metadata until ctx is canceled.

func (*Watcher) Changes added in v1.132.0

func (w *Watcher) Changes() <-chan string

Changes returns branch values when the observed branch changes.

func (*Watcher) Current added in v1.132.0

func (w *Watcher) Current() string

Current returns the last observed branch.

func (*Watcher) SetDir added in v1.132.0

func (w *Watcher) SetDir(dir string) string

SetDir switches the watcher to another working directory.

Jump to

Keyboard shortcuts

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