Skip to main content

Module git

Module git 

Source

Functions§

apply_cached
Stage a unified-0 patch into the index. --unidiff-zero is required for git to accept the zero-context hunks absorb works with.
blame_line_shas
The distinct commits that last touched lines start..start+len of file in HEAD, newest blame wins per line. An empty range yields nothing.
branch_sha
The commit a branch points at, or None when the branch does not exist.
checkout
checkout_detached_in
Move an existing worktree’s detached HEAD to commit, without touching any branch.
checkout_silently
Switch without announcing it on stdout, for callers whose stdout carries a value a shell will consume. They report the switch themselves, on stderr.
cherry_pick
Cherry-pick a commit onto the current branch. On conflict git leaves the cherry-pick in progress, so the error surfaces for the caller to tell the user to resolve and git cherry-pick --continue.
commit_body
A commit’s body - everything after the subject line; empty when there is none.
commit_fixup
Commit the staged index as a fixup! of sha, for a later autosquash rebase to fold in. Skips hooks: these are internal, transient commits.
commit_subject
A commit’s subject line.
commits_behind
How many commits parent has that branch does not: nonzero means the branch needs a restack.
config_get
config_get_bool
config_get_regexp
config_set
config_unset
create_branch
create_branch_at
Create a branch pointing at sha without checking it out or touching the working tree - used by split to point new branches at existing commits.
current_branch
delete_branch
Force-delete a branch. Use only once review state confirms it landed: a squash merge leaves the commits non-ancestry-merged, so git branch -d would refuse even though the work is in.
describe_worktree
A worktree path for a message, tagged when it is the main one so the reader knows why removing it is not among the options.
detach_command
How to hand a branch back, as a command the user can paste. Detaching is what the guards lead with because it works on every worktree: git worktree remove refuses on the main one, and moving the operation into the holding worktree only helps when that worktree is the only one in the way.
diff_against_head
A unified-0 diff against HEAD: just the staged changes when cached, otherwise all tracked changes (staged and unstaged). Zero context lines so each hunk’s pre-image range pinpoints exactly the lines it touches.
diff_numstat
Lines added and deleted in branch relative to base, over the symmetric base...branch range a forge uses for a review diff (the branch’s own work since it diverged). Binary files, which --numstat marks with -, count as zero.
display_path
Render a worktree path for a message the user may paste back as a command. Sibling worktrees are the common layout and ../wt-a reads better than a long absolute path. Only exact prefix matches are shortened, so the result is always a usable path - never a guess.
distinct_paths
Collapse worktree paths to the distinct places involved, so a message about three branches held by one worktree suggests freeing it once, not three times.
fetch_branch
Fast-forward a local branch from its remote without checking it out.
fetch_ref
Force-fetch a single ref from remote into the same local ref.
fetch_tracking
Refresh the remote-tracking refs (<remote>/<branch>) for branches that exist on remote, in a single fetch. Branches absent from the remote (a freshly created top of stack that was never pushed) are dropped rather than failing the whole fetch. A no-op when none of them are on the remote.
git_common_path
Resolve path under the repo’s common git dir, which all linked worktrees share, rather than the per-worktree dir git_path returns. Use this for state that guards or mirrors the shared config (branch.*), so every worktree of a repo agrees on one file.
git_common_path_absolute
An absolute path under the repo’s common git dir. Callers that hand a path to another process (a worktree location, a command’s working directory) need it absolute, since a relative one would be read against the wrong directory.
git_path
in_linked_worktree
Whether this command is running inside a linked worktree rather than the main checkout. Best effort: an unreadable root reads as the main worktree, which is where most runs happen.
is_ancestor
is_in_repo
Whether the working directory is inside a git work tree. Used for a clean “not a git repository” message instead of letting git’s raw error surface from the first command that needs the repo.
is_main_worktree
Whether path is the repo’s main worktree. Worth telling apart because git worktree remove refuses on it, so any advice that would free a branch by removing its worktree is a dead end there.
local_branches
log_oneline
(short-sha, subject) for each commit in range (e.g. “main..HEAD”), newest first - one git call, for listing a branch’s own commits.
main_worktree_root
The anchor for repo-wide paths that must resolve the same from every worktree. repo_root answers “where am I”, which inside a linked worktree is that worktree - so a default derived from it would nest a new worktree under the one it was created from. Falls back to the root when the listing cannot be read, which is where a repo with no linked worktrees lands anyway.
merge_base
pull_ff_only
push_force_with_lease
Force-push branches (with lease), returning the branches that actually landed. Normally that is all of them; the exception is the merge-queue backstop below, which drops a held-back branch from the returned set so the caller never reports a branch as both held and pushed.
push_ref
Force-push a single ref to remote (the value is regenerable, so last-writer-wins is fine).
push_set_upstream_force_with_lease
Push branches and set upstream tracking; used before submitting so new branches exist remotely and rebased ones are safely updated.
read_ref_file
The contents of file in the commit reference points at, or None when the ref or file is absent.
rebase
rebase_abort
rebase_autosquash
Rebase base..HEAD, folding fixup! commits into their targets. The generated todo is accepted unedited, so it needs no terminal.
rebase_continue
rebase_in_progress
Whether a rebase is actually paused in this worktree. Distinguishes a real conflict from git-stk merely having left state on file - git refuses to rebase a branch another worktree holds, which fails the run without ever starting a rebase to continue or abort.
rebase_onto
Rebase only the commits after base, replaying base..branch onto parent. Used when the recorded fork point is known so commits that landed upstream by squash or rebase are not replayed.
remote_default_branch
Default branch of remote (from its locally-known HEAD symref), if any.
remote_only_commits
The commits tracking (a <remote>/<branch> ref) has that branch lacks and that have no patch-equivalent already on branch - the commits a force-push would silently drop, e.g. one committed straight on the host’s web UI. (short-sha, subject) oldest-first, the order to cherry-pick them. Empty in the normal post-rebase case, where every remote commit is reproduced locally under a new hash.
remote_url
rename_branch
Rename a branch; git moves its branch.<name>.* config along with it.
repo_root
The repository’s top-level working-tree directory.
reset_hard
Reset the worktree and index to HEAD. Safe to lose nothing only on a clean tree; callers must check worktree_is_clean first.
reset_index
Unstage everything, leaving the worktree contents untouched.
reset_soft
Move HEAD to sha, returning any commits after it to the index.
rev_list
The commits in range (e.g. “main..HEAD”), newest first.
rev_parse
same_path
Whether two paths name the same place. Never compare worktree paths with ==: git reports its own resolved form, which differs from anything we build ourselves - /var against /private/var on macOS, forward against back slashes on Windows - so exact equality quietly reports “different”.
set_verbose
Pass raw git output through instead of capturing it.
stash_pop
Restore the most recently stashed changes.
stash_push
Stash tracked worktree changes; pair with stash_pop.
supports_rebase_update_refs
switched_to
The “switched to ” wording, so stdout and stderr callers agree.
update_ref
Point a branch at a commit, creating it if absent. Does not touch the worktree.
verbose
Public so a command can hold back detail that would otherwise repeat on every run - see the stacked-field notice in providers::github.
worktree_add_detached
Add a detached worktree at path, parked on commit. Detached on purpose: it holds no branch, so it cannot collide with the user’s checkout or any other worktree.
worktree_add_new_branch
Add a worktree at path holding a new branch created off start.
worktree_branches
Branches checked out in linked worktrees other than this one, paired with the directory holding each. Git refuses to switch to, rebase, or delete a branch another worktree holds, so callers check this before those.
worktree_has_changes
Whether a worktree has uncommitted changes. Used before removing one git-stk created, so work in it is never silently discarded.
worktree_holding
The worktree holding branch, if one other than this one does.
worktree_is_clean
Whether the worktree and index have no uncommitted changes.
worktree_remove
Remove a worktree, discarding anything in it. Only for worktrees git-stk created and owns.
write_blob_ref
Store content as a single-file commit and point reference at it, so the data rides along a normal ref push. Orphan each time: the ref just moves to the new commit (callers force-push it, as it is regenerable).