Help us shape the future of Go! Take the 2026 Go Developer Survey

git

package
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWorktreeDirty means git refused to remove a worktree with modified or untracked files.
	ErrWorktreeDirty = errors.New("git: worktree has uncommitted changes")
	// ErrNoCommit means the commit is not in this repository.
	ErrNoCommit = errors.New("git: commit not in this repository")
	// ErrBranchMoved means the branch tip is not the one the caller saw.
	ErrBranchMoved = errors.New("git: branch moved")
)
View Source
var (
	// ErrNoSnapshot means the requested turn has no snapshot.
	ErrNoSnapshot = errors.New("git: turn has no snapshot")
	// ErrNoTurns means the session has no recorded turns.
	ErrNoTurns = errors.New("git: session has no turns")
	// ErrNotFetched means the pull request refs are not in the repository.
	ErrNotFetched = errors.New("git: pull request refs not fetched")
	// ErrTooLarge means a file is too large to read whole.
	ErrTooLarge = errors.New("git: file too large")
)
View Source
var (
	// ErrNotRepo means the directory is not inside a git work tree.
	ErrNotRepo = errors.New("git: not inside a work tree")
	// ErrBare means the repository has no main checkout.
	ErrBare = errors.New("git: bare repository")
)
View Source
var (
	// ErrExists means the worktree path is already taken.
	ErrExists = errors.New("git: worktree path exists")
	// ErrBadBranch means the branch name is not usable as a branch or a directory.
	ErrBadBranch = errors.New("git: invalid branch name")
	// ErrNoBase means there is no usable base branch.
	ErrNoBase = errors.New("git: no base branch")
)
View Source
var ErrBadSession = errors.New("git: session id is not a UUID")

ErrBadSession means a session id is not a UUID.

View Source
var ErrNoPR = errors.New("git: no such pull request on the remote")

ErrNoPR means the remote has no such pull request.

View Source
var ErrNoRemote = errors.New("git: no such remote")

ErrNoRemote means the named remote is not configured.

View Source
var ErrNotCounted = errors.New("git: the edit does not count")

ErrNotCounted means a file edit does not belong to any worktree's changes: the path is not absolute, lies in a git dir, outside any work tree, or is ignored.

View Source
var ErrRejected = errors.New("git: push rejected")

ErrRejected means the remote refused the push, e.g. a non-fast-forward.

View Source
var ErrTurnNotOpen = errors.New("git: the turn is not open in this worktree")

ErrTurnNotOpen means the turn to end has no start in this worktree, or has an end already.

View Source
var ErrWatchSetClosed = errors.New("watch set closed")

ErrWatchSetClosed is returned by Acquire after Close.

Functions

func Ahead

func Ahead(ctx context.Context, r Repo) (n int, ok bool, err error)

Ahead counts the commits HEAD has that its upstream lacks. ok is false when there is nothing to compare with: a detached HEAD, an unborn branch, no upstream, or an upstream ref that is gone.

func BranchAhead

func BranchAhead(ctx context.Context, r Repo, branch, head string) (tip string, ahead int, err error)

BranchAhead returns the tip of branch and how many commits it has that head does not. A tip equal to head needs no object; a head that is not a commit here is ErrNoCommit.

func DefaultBranch

func DefaultBranch(ctx context.Context, r Repo) (string, error)

DefaultBranch returns the start point for new branches: origin/<name> when origin/HEAD points at an existing branch, else main, else master.

func DeleteBranch

func DeleteBranch(ctx context.Context, r Repo, branch, tip string) error

DeleteBranch deletes branch with `branch -D` when its tip is still tip. The caller has already checked the branch is merged; git still refuses a branch checked out in any worktree.

func DeletePRRefs

func DeletePRRefs(ctx context.Context, r Repo, number int) error

DeletePRRefs removes the refs FetchPR wrote in one transaction. Missing refs are not an error.

func HasUpstream

func HasUpstream(ctx context.Context, r Repo, branch string) (bool, error)

HasUpstream reports whether branch has an upstream configured, whether or not its remote-tracking ref exists. Push sets an upstream exactly when this is false.

func HunkID

func HunkID(path string, h Hunk) string

HunkID identifies a hunk by its path and its changed lines, so it survives moved line numbers, other context and a renamed old path.

func ManagedWorktree

func ManagedWorktree(r Repo, path string) bool

ManagedWorktree reports whether path sits directly under one of the repository's worktree roots, inside or sibling, with symlinks resolved. The main checkout is not one, and neither is a path whose parent is missing.

func MarkdownFiles

func MarkdownFiles(ctx context.Context, root string) ([]string, error)

MarkdownFiles lists the markdown files under root as sorted, slash-separated paths relative to root, whether git tracks, ignores or has never seen them. It skips .git, node_modules, vendor and every folder below root that holds a .git entry (a nested checkout or worktree), and does not follow symlinked folders. At the cap the walk stops: the files found so far (the first in walk order) come back, sorted, without an error. So do the files found when ctx's deadline passes mid-walk. An unreadable folder below root is skipped; an unreadable root, a cancelled ctx and a deadline before any file are errors.

func PruneSession

func PruneSession(ctx context.Context, r Repo, session string) (int, error)

PruneSession deletes every turn ref of the session, in both layouts, and returns how many.

func PruneWorktree

func PruneWorktree(ctx context.Context, r Repo, worktree string) (int, error)

PruneWorktree deletes every turn ref of worktree, in both layouts, and returns how many it removed. worktree is a worktree root as Repo.Root gives it, the form the commits record; a symlinked spelling does not match.

func PushRemote

func PushRemote(ctx context.Context, r Repo, branch string) (string, error)

PushRemote names the remote a push of branch goes to: branch.<b>.pushRemote, else remote.pushDefault, else branch.<b>.remote (unless "."), else origin. It must be a configured remote.

func PushURLs

func PushURLs(ctx context.Context, r Repo, remote string) ([]string, error)

PushURLs returns every URL a push to remote goes to, one per pushurl, with url.<base>.pushInsteadOf and insteadOf applied. Without a pushurl it is the fetch URL. The URLs may carry credentials, so never put them in an error or log.

func RemoteBranches

func RemoteBranches(ctx context.Context, r Repo, remote string) ([]string, error)

RemoteBranches returns the names of the remote-tracking branches of remote, without the remote's name and without HEAD, sorted. A remote with no tracking refs, or one that is not configured, has none.

func RemoteHasBranch

func RemoteHasBranch(ctx context.Context, r Repo, remote, branch string) (bool, error)

RemoteHasBranch reports whether the remote-tracking ref of branch on remote exists, which says nothing about the remote itself until a fetch or push.

func RemoteURL

func RemoteURL(ctx context.Context, r Repo, remote string) (string, error)

RemoteURL returns the URL git would use for remote, with url.<base>.insteadOf applied. The URL may carry credentials, so never put it in an error or log.

func RemoveWorktree

func RemoveWorktree(ctx context.Context, r Repo, path string) error

RemoveWorktree runs `git worktree remove` for path from the main checkout (the common dir for a bare repository). It is never forced, so git refuses a worktree with changes (ErrWorktreeDirty) or a locked one.

func Unpushed

func Unpushed(ctx context.Context, r Repo, remote string) (int, error)

Unpushed counts the commits of HEAD that no remote-tracking branch of remote has, which is every commit before a first push.

func WorktreeChanges

func WorktreeChanges(ctx context.Context, dir string) (int, error)

WorktreeChanges counts the entries `git status` reports in dir: modified, staged and untracked paths, a rename or copy once.

func WorktreeDir

func WorktreeDir(branch string) (string, error)

WorktreeDir turns a branch name into a directory name.

func WorktreePath

func WorktreePath(r Repo, style RootStyle, branch string) (string, error)

WorktreePath is where CreateWorktree puts a worktree for branch under the root of style. It reads nothing from the disk, so a page can preview it on every frame. It fails with ErrBadBranch when the name has no directory form and with ErrBare when the inside root has no main checkout.

Types

type Batch

type Batch struct {
	// Paths are touched paths relative to the worktree root, sorted,
	// deduplicated, never ignored. A removed directory appears as its own path
	// and its children may be absent: treat a vanished path as a prefix. Files a
	// .gitignore change un-ignores are listed only in newly watched
	// directories: treat a touched .gitignore as "everything may have changed".
	Paths    []string
	Git      bool // HEAD, the index, packed-refs or a ref outside refs/aim changed
	Overflow bool // events were lost; treat everything as changed
}

Batch is one debounced set of changes in a worktree.

type BranchSource

type BranchSource struct{ Worktree, Base string }

BranchSource compares the merge base of Base and HEAD with the working tree. An empty Base means the default branch.

type Commit

type Commit struct{ OID, Subject, Body string }

Commit is one entry of a branch's history.

func HeadCommit

func HeadCommit(ctx context.Context, r Repo) (Commit, error)

HeadCommit returns the commit HEAD points at, with its subject (the body is left empty). An unborn branch is an error.

func Log

func Log(ctx context.Context, r Repo, base string) ([]Commit, error)

Log returns the commits in base..HEAD, oldest first. When there are more than 250 it keeps the newest 250.

type Created

type Created struct {
	Worktree Worktree
	Excluded bool   // this call added /.worktrees/ to info/exclude
	Tools    []Tool // tools that need their own ignore entry (RootInside only)
}

Created is the result of CreateWorktree.

func CreateWorktree

func CreateWorktree(ctx context.Context, r Repo, nw NewWorktree) (Created, error)

CreateWorktree adds a worktree for nw.Branch under the chosen root, creating the branch from the base unless it exists (then the base is ignored). A non-empty Worktree.Path in the result means the worktree exists, even when the error is not nil.

type Engine

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

Engine turns sources into structured diffs. It is safe for concurrent use.

func NewEngine

func NewEngine(o EngineOptions) *Engine

NewEngine returns an engine for the given options.

func (*Engine) Diff

func (e *Engine) Diff(ctx context.Context, src Source) (Result, error)

Diff computes the diff for src.

func (*Engine) FileText

func (e *Engine) FileText(ctx context.Context, worktree string, f FileDiff) (old, nw []string, err error)

FileText returns the lines of both sides of f, read from the object database. An empty id gives an empty side. A side over 8 MiB gives ErrTooLarge.

func (*Engine) Stats

func (e *Engine) Stats(ctx context.Context, src Source) (Stats, error)

Stats totals the diff of src with the listing pass only: no hunks, and no cache. Only branch sources are supported.

func (*Engine) TurnList

func (e *Engine) TurnList(ctx context.Context, worktree, session string) (TurnList, error)

TurnList lists the session's turns in worktree that changed it: a closed turn whose end differs from its start, any turn with a marker, an open turn that is no longer current, and the open current turn while the working tree differs from its start.

func (*Engine) TurnListAt

func (e *Engine) TurnListAt(ctx context.Context, worktree, session, workingTree string) (TurnList, error)

TurnListAt is TurnList for a caller that already has the worktree's current tree id, such as the New side of a live branch diff: the open current turn is compared with it instead of a fresh working-tree snapshot.

func (*Engine) Update

func (e *Engine) Update(ctx context.Context, prev Result, src Source, b Batch) (Result, error)

Update brings prev, the result of Diff for src, up to date after the watcher batch b. It rebuilds the working tree and re-lists only the touched paths; the result equals a fresh Diff. Anything that could change which files pair up, the old side, or which files fall inside the caps runs a full Diff. The Repo opened for a worktree is reused until its git dirs move or an update fails; an update whose context ended keeps it.

type EngineOptions

type EngineOptions struct {
	Limits     Limits // zero fields take the defaults
	TempDir    string // where working-tree snapshots keep their temporary index
	IndexCache string // keeps a refreshed index copy per worktree; empty = none
}

EngineOptions configure NewEngine.

type FileDiff

type FileDiff struct {
	Path, OldPath                string
	Status                       Status
	OldOID, NewOID               string // full ids; "" on the side a file does not exist
	OldMode, NewMode             string
	Binary, Untracked, Truncated bool
	Added, Removed               int
	Hunks                        []Hunk
}

FileDiff is one changed file. OldPath is set for renames and copies only. Untracked marks a file whose path git does not track and the old side lacks, also when git paired it with another file as a rename or copy. Hunks stay empty for binary files, files without line changes and files marked Truncated; cached hunks are shared, so treat them as read-only.

type HeadInfo

type HeadInfo struct {
	Branch   string // without refs/heads/
	Detached bool
	OID      string // full commit id
}

HeadInfo is what a worktree's HEAD points at. A detached HEAD has an empty Branch; an unborn branch has an empty OID.

func Head(ctx context.Context, r Repo) (HeadInfo, error)

Head reports the branch or detached commit checked out in r.

type Hunk

type Hunk struct {
	OldStart, OldLines, NewStart, NewLines int
	Section                                string
	Lines                                  []Line
}

Hunk is one block of changes with its context.

type Limits

type Limits struct{ Files, Bytes, Lines int }

Limits bound the work and memory of one diff.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns 400 files with hunks, 2 MiB of diff text and 5000 changed lines per file.

type Line

type Line struct {
	Kind      LineKind
	Old, New  int // line numbers; 0 on the side the line is not on
	Text      string
	NoNewline bool
}

Line is one line of a hunk.

type LineKind

type LineKind byte

LineKind is the diff marker of a line.

const (
	Context LineKind = ' '
	Add     LineKind = '+'
	Del     LineKind = '-'
)

Line kinds, the characters git prints.

type NewWorktree

type NewWorktree struct {
	Branch string
	Base   string // "" = the default branch; ignored when Branch already exists
	Root   RootStyle
}

NewWorktree describes a worktree to create.

type OpenTurn

type OpenTurn struct {
	Root string // from the start's Worktree trailer
	N    int
}

OpenTurn is a worktree whose turn has no end yet.

func OpenTurns

func OpenTurns(ctx context.Context, r Repo, session string) ([]OpenTurn, error)

OpenTurns lists, in every worktree of r's repository, the session's open turns at its highest number there; start markers are left out.

type PRRefs

type PRRefs struct{ Head, Base string }

PRRefs are the commits FetchPR stored: the pull request's head and the tip of its base branch.

func FetchPR

func FetchPR(ctx context.Context, r Repo, remote string, number int, base string) (PRRefs, error)

FetchPR fetches pull request number's head and its base branch into refs/aim/pr/<number>/. It writes nothing else: no remote-tracking ref, tag, FETCH_HEAD or submodule.

type PRSource

type PRSource struct {
	Worktree string
	Number   int
}

PRSource compares the merge base of a pull request's base and head, as FetchPR stored them, with its head.

type Place

type Place struct {
	Root   string // the worktree's top level
	Common string // the repository's common dir, shared by its worktrees
	Repo   string // the repository's name, Repo.Name
}

Place is the worktree holding a file an agent edited.

func EditPlace

func EditPlace(ctx context.Context, path string) (Place, error)

EditPlace finds the worktree an edited file belongs to. The file need not exist yet: the nearest existing directory above it decides, with symlinks resolved, since git reports real paths. It fails with ErrNotCounted for a path that is not absolute, has a ".git" component, is outside any work tree or is ignored by that worktree's own rules.

type PlaceCache

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

PlaceCache answers EditPlace for many callers: it keeps counted places and ErrNotCounted answers for a minute, and makes lookups of one path in flight share one resolution. Its zero value is not usable; make one with NewPlaceCache.

func NewPlaceCache

func NewPlaceCache(resolve func(context.Context, string) (Place, error), now func() time.Time) *PlaceCache

NewPlaceCache makes a cache over resolve, normally EditPlace, whose entries age by now.

func (*PlaceCache) Place

func (c *PlaceCache) Place(ctx context.Context, path string) (Place, error)

Place is EditPlace through the cache. A kept place whose root is no longer a directory is a miss, so a removed worktree resolves afresh. It stats the root, so call it off the update loop.

type PushResult

type PushResult struct {
	Remote, Branch string
	Dst            string // the remote ref pushed to
	Created        bool   // the remote branch is new
	UpToDate       bool
	SetUpstream    bool
}

PushResult reports what one push did.

func Push

func Push(ctx context.Context, r Repo, branch string) (PushResult, error)

Push sends branch to its push remote, never forcing, always to a remote branch of the same name (git's simple rule), so a branch cut from origin/main cannot land on main. The upstream is set only when the branch has none.

type Repo

type Repo struct {
	Root      string // the worktree's top level, absolute
	GitDir    string // this worktree's git dir, absolute
	CommonDir string // the repository's common dir, absolute
}

Repo locates one worktree and the repository it belongs to.

func Open

func Open(ctx context.Context, dir string) (Repo, error)

Open finds the worktree containing dir.

func (Repo) MainRoot

func (r Repo) MainRoot() (string, error)

MainRoot returns the main checkout: the parent of the common dir when that is a ".git" directory. A checkout with a separate git dir or a submodule has another common dir and reports ErrBare.

func (Repo) Name

func (r Repo) Name() string

Name is the repository's name as the rail shows it: the main checkout's directory name, or for a bare repository the common dir's name without ".git".

type Result

type Result struct {
	Old, New  string // tree ids
	Live      bool   // New is the working tree
	Turn      int    // turn sources: the position shown in the worktree's list
	Turns     int    // turn sources: how many turns the worktree's list held
	Head      string // PR sources: the head commit shown; a merge passes it
	Files     []FileDiff
	Truncated bool
}

Result is a diff between two trees.

type RootBatch

type RootBatch struct {
	Root  string
	Batch Batch
	Err   error
}

RootBatch is one watcher batch, or the report of a watch that failed to start (Err set), tagged with the worktree root it belongs to.

type RootStyle

type RootStyle int

RootStyle says where new worktrees go.

const (
	RootInside  RootStyle = iota // <main checkout>/.worktrees/<name>
	RootSibling                  // <parent>/<main checkout name>.worktrees/<name>
)

type SnapshotOptions

type SnapshotOptions struct {
	TempDir      string // where the temporary index is created
	IndexCache   string // keeps a refreshed index copy per worktree; empty = none
	MaxUntracked int64  // bytes; 0 = 50 MiB, negative = no cap
	Unchanged    bool   // reuse the worktree's latest tree in the session without staging
	Turn         int    // the turn's number; 0 takes one more than the session's highest in the repository
	Ends         int    // a turn of this worktree to end with the same tree when it is open; 0 for none
}

SnapshotOptions tune one snapshot.

type Source

type Source interface {
	// contains filtered or unexported methods
}

Source selects what Engine.Diff compares.

type Stats

type Stats struct{ Files, Added, Removed int }

Stats totals a diff: the changed files and their added and removed lines. Binary files count as files without lines.

type Status

type Status string

Status is how a file differs between the two sides.

const (
	Added       Status = "added"
	Deleted     Status = "deleted"
	Modified    Status = "modified"
	Renamed     Status = "renamed"
	Copied      Status = "copied"
	ModeChanged Status = "mode"
)

File statuses. ModeChanged is a mode change with identical content.

type Tool

type Tool struct {
	Name string
	Path string // the file or directory that triggered it, relative to the root
	Hint string // what to add
}

Tool is a development tool in the main checkout that would pick up files under .worktrees/ unless it gets its own ignore entry.

func DetectTools

func DetectTools(root string) ([]Tool, error)

DetectTools reads files in root, never runs anything, and lists the tools that need an ignore entry for .worktrees. JSON that does not parse counts as needing an entry. A check that fails to read is skipped and joined into the error, so the tools found are still returned.

type TreeOptions

type TreeOptions struct {
	TempDir      string // where the temporary index is created
	IndexCache   string // keeps a refreshed index copy per worktree; empty = none
	MaxUntracked int64  // bytes; 0 = 50 MiB, negative = no cap
}

TreeOptions tune WorkingTree.

type Turn

type Turn struct {
	N          int
	Commit     string // the start
	Tree       string
	Missing    bool   // the start is a "no snapshot" marker
	EndCommit  string // "" while the turn is open
	EndTree    string
	EndMissing bool // the end is a marker
	Current    bool // N is the session's highest turn number in the repository
	Skipped    []string
	Time       time.Time // the start's committer time
}

Turn is one turn of a session in one worktree.

func EndTurn

func EndTurn(ctx context.Context, dir, session string, n int, opts SnapshotOptions) (Turn, error)

EndTurn records the working tree as the end of turn n of the worktree containing dir. A turn with no start there, a start marker or an end is ErrTurnNotOpen.

func MarkMissing

func MarkMissing(ctx context.Context, dir, session string, n int, end bool) (Turn, error)

MarkMissing records that a turn has no snapshot: a commit of the empty tree with the trailer "Snapshot: none". As a start it is turn n (0 for the next), so later turns keep their numbers; as an end (end true) it closes the open turn n.

func Snapshot

func Snapshot(ctx context.Context, dir, session string, opts SnapshotOptions) (Turn, error)

Snapshot records the working tree of the worktree containing dir as the start of turn opts.Turn of the session. The user's index, refs, stash and files are only read. The returned Turn is the start alone: only Turns fills Current and the end fields.

func Turns

func Turns(ctx context.Context, r Repo, session string) ([]Turn, error)

Turns lists the session's turns in r's worktree in ascending order.

type TurnList

type TurnList struct {
	Turns []Turn
	Live  bool // the last is the open current turn and differs from the working tree
}

TurnList is the turns that changed a worktree, oldest first.

type TurnSource

type TurnSource struct {
	Worktree, Session string
	Turn              int
}

TurnSource compares one turn of a worktree with what followed it. Turn is a position in the worktree's TurnList: 1 the oldest, 0 the latest.

type WatchOptions

type WatchOptions struct {
	Debounce time.Duration // quiet time before a batch goes out; 100 ms when zero
	MaxDelay time.Duration // longest an unsent change waits while events keep coming; 1 s when zero
	SeqBase  uint64        // Seq's starting value, so a restarted watcher never repeats one
	// contains filtered or unexported fields
}

WatchOptions tunes the debounce. Zero values select the defaults.

type WatchSet

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

WatchSet owns one Watcher per worktree root, shared by every holder and reference-counted. Its batches arrive on one channel.

func NewWatchSet

func NewWatchSet(ctx context.Context, opts WatchOptions) *WatchSet

NewWatchSet returns an empty set. Watchers use opts, except SeqBase, and stop when ctx ends or Close is called.

func (*WatchSet) Acquire

func (s *WatchSet) Acquire(ctx context.Context, r Repo) (release func(), err error)

Acquire holds a watcher for r.Root, starting one when none exists. The returned release is idempotent and safe to call after Close; the last release stops the watcher. On failure it returns the error and sends one RootBatch with Err set.

func (*WatchSet) Batches

func (s *WatchSet) Batches() <-chan RootBatch

Batches delivers the batches of every watched root. It is closed by Close. A failed Acquire also sends a batch with Err set; that report is dropped when the channel is full, since Acquire returned the same error.

func (*WatchSet) Close

func (s *WatchSet) Close() error

Close stops every watcher, waits for their goroutines and closes Batches. It is safe to call more than once.

func (*WatchSet) Seq

func (s *WatchSet) Seq(root string) (uint64, bool)

Seq returns the change counter of the watcher for root, and false when root is not watched or its watcher has reported an error or overflowed; such a watcher may miss changes until it is restarted.

type Watcher

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

Watcher reports debounced changes of one worktree. Directories git ignores, .git internals and the main checkout's .worktrees get no watch.

func Watch

func Watch(ctx context.Context, r Repo, opts WatchOptions) (*Watcher, error)

Watch starts watching the worktree r. Batches closes when Close is called or ctx ends.

func (*Watcher) Batches

func (w *Watcher) Batches() <-chan Batch

Batches delivers the changes. It is closed by Close or when the context ends.

func (*Watcher) Close

func (w *Watcher) Close() error

Close stops the watcher and waits for its goroutine. It is safe to call more than once.

func (*Watcher) Degraded

func (w *Watcher) Degraded() bool

Degraded reports whether the watcher has reported an error or lost events. Changes may then go unseen, so its Seq proves nothing.

func (*Watcher) Errors

func (w *Watcher) Errors() <-chan error

Errors reports non-fatal problems such as a failed ignore check. It is closed together with Batches; errors are dropped when nobody reads them.

func (*Watcher) Seq

func (w *Watcher) Seq() uint64

Seq counts the events the watcher accepted, from SeqBase, before they are debounced into a batch. It is safe to call from any goroutine.

type WorkTree

type WorkTree struct {
	Tree      string   // tree id of the working tree as git would stage it
	Untracked []string // untracked paths that entered the tree
	Skipped   []string // untracked paths over the size cap, left out
}

WorkTree is a working tree written as a git tree object.

func WorkingTree

func WorkingTree(ctx context.Context, r Repo, o TreeOptions) (WorkTree, error)

WorkingTree writes the worktree's current content as a tree through a temporary copy of its index, so the real index, refs and files are only read.

type Worktree

type Worktree struct {
	Path, Head, Branch      string // Branch is without refs/heads/; "" when detached or bare
	Main, Bare, Detached    bool
	Locked, Prunable        bool
	LockReason, PruneReason string
}

Worktree is one entry of `git worktree list`.

func ListWorktrees

func ListWorktrees(ctx context.Context, r Repo) ([]Worktree, error)

ListWorktrees lists the repository's worktrees; the first is the main checkout.

Directories

Path Synopsis
Package fsnotify provides a cross-platform interface for file system notifications.
Package fsnotify provides a cross-platform interface for file system notifications.
internal
Package internal contains some helpers.
Package internal contains some helpers.
Package invisible finds the characters that draw nothing but change how text reads: format characters, variation selectors and line separators.
Package invisible finds the characters that draw nothing but change how text reads: format characters, variation selectors and line separators.
Package linediff splits texts into lines and finds a shortest line edit script between two of them.
Package linediff splits texts into lines and finds a shortest line edit script between two of them.

Jump to

Keyboard shortcuts

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