gitx

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitx is Flockdeck's use of git: the status a pane header shows, the review panel's file list, diffs and commit (changes.go, commit.go), push, pull and fetch (remote.go), and the worktrees that let several agents work in parallel without fighting over one checkout (worktree.go). Every command goes through run.go, which gives it a deadline and shapes what it says when it fails.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFrom

func AddFrom(repoDir, path, branch, base string) error

AddFrom creates a worktree at path.

When branch names an existing local branch it is checked out; otherwise a new branch is created, starting at base when one is given and at the current HEAD when it is not. The path and the starting point both arrive from the window, so they are put after a "--": without it git reads anything beginning with a dash as one of its own options. A base of "--force" was not refused, it was obeyed, and the new worktree quietly started from HEAD with a force checkout instead of from wherever the user had named.

func Available

func Available() bool

Available reports whether git is installed.

func BranchExists

func BranchExists(dir, branch string) bool

BranchExists reports whether a local branch is already present.

func CommitAll

func CommitAll(dir, message string) error

CommitAll stages everything and commits it.

Both steps run the user's own programs -- a clean filter such as LFS for the add, the pre-commit hooks for the commit, which as often as not lint or run the tests -- so neither is held to the deadline for reading the repository. A hook still going at twenty seconds was killed there, and the commit it guarded reported as a hang.

func CurrentBranch

func CurrentBranch(dir string) string

CurrentBranch returns the checked-out branch, or "" when detached.

symbolic-ref reads the branch HEAD points at without needing a commit on it, where `rev-parse --abbrev-ref HEAD` fails outright in a repository nobody has committed to yet -- which made a fresh repository look detached, and its first push report "cannot push a detached HEAD".

func DefaultBase

func DefaultBase(repoDir string) string

DefaultBase returns a sensible starting point for a new branch: the current branch of the main worktree.

A rebase in progress there has to be stepped around. It detaches HEAD while it replays commits, so there is no current branch to offer and "HEAD" means whichever commit the replay happens to be sitting on -- a starting point nobody means, and one that will not exist as anything once the rebase finishes. The branch being rebased still points at where it was before the rebase started, which is a real place to branch from.

A branch nobody has committed to yet is not one either: it names no commit, and the panel's pre-filled base made every new worktree in a fresh repository fail with "invalid reference: main". Offering nothing leaves git to start the new branch empty, as it does when no base is given.

func DefaultWorktreePath

func DefaultWorktreePath(repoRoot, branch string) string

DefaultWorktreePath suggests where a new worktree for a branch should live: a sibling of the repository, named after it, so checkouts stay grouped together without nesting inside the repository itself.

A name that is already taken is stepped around rather than suggested. That means two things, and only one of them is visible in the file system: a directory sitting there, which `git worktree add` refuses, and a worktree git still has a record of. The second is what someone who deleted a checkout in their file manager leaves behind, and it fails differently -- "a missing but already registered worktree" -- for a path that looks free.

func Diff

func Diff(dir, path string) (string, error)

Diff returns a unified diff for one file, including untracked files, whose content is shown as an addition.

func Fetch

func Fetch(dir string) (string, error)

Fetch updates the remote-tracking branches.

A bare fetch goes to the current branch's remote, which for a branch tracking a local one -- `git checkout -b feature --track main` -- is the repository itself: "From . * branch main -> FETCH_HEAD", nothing brought down from anywhere, and a toast that read like a fetch. Such a branch fetches from the remote a first push would go to instead; every other branch keeps git's own choice.

func HasRemote

func HasRemote(dir string) bool

HasRemote reports whether the repository has anywhere to push to. A substring test for "origin" used to be enough here, but it also matched a remote merely named "my-origin" and missed a repository whose only remote is called something else entirely.

func IsRepo

func IsRepo(dir string) bool

IsRepo reports whether dir is inside a git repository.

func Prune

func Prune(repoDir string) (int, error)

Prune removes administrative records for worktrees whose directories have been deleted behind git's back, and reports how many went.

The count is what lets the panel say whether the button it just offered did anything. git names each record it removes on stderr, one to a line, so they are counted as lines rather than looked for by the word they start with -- which is translated when git is speaking anything but English.

func Pull

func Pull(dir string) (string, error)

Pull fast-forwards from the upstream. A merge that cannot fast-forward is left for the user to resolve deliberately rather than started here.

The two ways that commonly fails are told apart by asking the repository rather than by reading git's words, which change with its language: a branch with no upstream has nothing to pull from, and one that has moved on as well as fallen behind cannot be fast-forwarded. Both used to arrive as git's advice, cut down to the lines that did not say what to do.

func Push

func Push(dir string) (string, error)

Push sends the current branch to its remote, setting the upstream the first time so a new worktree's branch does not need a separate command.

func Remotes

func Remotes(dir string) []string

Remotes lists the configured remote names.

func Remove

func Remove(repoDir, path string, force bool) error

Remove deletes a worktree. force discards uncommitted changes in it.

When the directory has already been deleted by hand -- which is how these usually disappear -- git refuses to remove a path that is not there. Pruning the record it left behind is what the person pressing remove meant, and it is the only thing left to do.

That prune is why the path is checked against the repository's own list first. It is not selective: it discards the record of every worktree whose directory is missing, including one sitting on a drive that happens to be unplugged. A path git has never heard of should not be able to set that off, and reporting "removed" for it was a lie besides.

func Root

func Root(dir string) (string, error)

Root returns the top level of the working tree containing dir.

git answers with forward slashes even on Windows, so the path is cleaned to the platform's own form: List does the same, and the two are compared against each other to tell the main worktree from the linked ones.

func UpstreamOf

func UpstreamOf(dir string) string

UpstreamOf names the remote branch the checked-out branch tracks, or "" when it tracks nothing.

Push is the only thing that needs this, and asking StatusOf made git walk the entire working tree to answer it -- 190ms on a checkout with 20,000 untracked files, against 44ms here -- for a fact that has nothing to do with what is in the working tree. It also meant a status that timed out on a large checkout read as "no upstream", and Push would then set one: on a branch tracking something other than origin, that quietly repoints it.

Types

type Branch

type Branch struct {
	Name      string
	Upstream  string
	Current   bool
	CheckedIn string // path of the worktree that has it checked out, if any
}

Branch is a local branch and where it stands against its upstream.

func Branches

func Branches(dir string) ([]Branch, error)

Branches lists local branches, most recently used first, so the worktree picker can offer them without the user typing a name.

type FileChange

type FileChange struct {
	Path string
	// Status is the two-letter porcelain code, e.g. " M", "A ", "??".
	Status string
	// Label is that code rendered for people: "modified", "new", …
	Label     string
	Staged    bool
	Unstaged  bool
	Untracked bool
	Added     int
	Removed   int
}

FileChange is one modified file in a working tree.

func Changes

func Changes(dir string) ([]FileChange, error)

Changes lists the files that differ from HEAD, with line counts.

type Status

type Status struct {
	Branch   string
	Head     string // short commit id
	Detached bool
	Upstream string
	Ahead    int
	Behind   int
	// Unborn marks a branch with no commits on it yet, where Head is empty
	// because there is nothing to point at.
	Unborn bool
	// Operation names what a detached checkout is in the middle of --
	// "rebasing" or "bisecting" -- when Branch was read from that operation's
	// state rather than from HEAD, which names no branch while it runs.
	Operation string
	// Dirty counts tracked files with changes; Untracked counts new files.
	Dirty     int
	Untracked int
}

Status summarises a working tree: what is checked out, whether it has uncommitted work, and how it stands against its upstream.

func StatusOf

func StatusOf(dir string) Status

StatusOf reads a working tree's state in a single git call.

`--porcelain=v2 --branch` reports the branch, upstream and ahead/behind counts alongside the file entries, which avoids the several invocations the same information would otherwise take.

func (Status) HasChanges

func (s Status) HasChanges() bool

HasChanges reports whether anything is uncommitted.

type Worktree

type Worktree struct {
	Path     string
	Head     string
	Branch   string // short branch name, empty when detached
	Bare     bool
	Detached bool
	Locked   bool
	// Main reports whether this is the repository's primary worktree.
	Main bool
	// Prunable reports that the worktree's directory is gone -- deleted by
	// hand, or on a drive that is not there -- and only git's record of it is
	// left. Its Status is empty, which is not the same thing as clean.
	Prunable bool
	// Status is filled in by ListDetailed.
	Status Status
}

Worktree is one entry from `git worktree list`.

func List

func List(dir string) ([]Worktree, error)

List returns every worktree of the repository containing dir.

func ListDetailed

func ListDetailed(dir string) ([]Worktree, error)

ListDetailed returns every worktree with its status filled in.

Each worktree needs its own status call, so they are run concurrently: a repository with several worktrees would otherwise make the panel wait for them one after another.

func (Worktree) Label

func (w Worktree) Label() string

Label returns a human-readable name for the worktree.

Jump to

Keyboard shortcuts

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