starship/starship
VCS modules
Modules that reflect the state of the version-control repository in the current directory. Most use Starship's Context::get_repo() (which returns a gix repository handle) for Git, and shell out to the system hg or fossil for the others.
Active contributors
David Knaack, Matan Kushner, Thomas O'Donnell
Modules
Git
| Module | Default | Purpose | File |
|---|---|---|---|
git_branch |
on main |
Current branch / detached HEAD / remote tracking | src/modules/git_branch.rs |
git_commit |
(<hash>) |
Short SHA, optional tag | src/modules/git_commit.rs |
git_state |
(REBASING 2/5) |
Rebase / merge / cherry-pick / bisect / revert state | src/modules/git_state.rs |
git_metrics |
+12/-3 |
Lines added/deleted between HEAD and worktree | src/modules/git_metrics.rs |
git_status |
[!?$] |
Untracked, modified, staged, stashed, conflicted, ahead/behind | src/modules/git_status.rs (~2.3K lines) |
Git access goes through Context::get_repo → Repo::open (a thread-local gix::Repository). The Repo struct is built once per prompt with these fields:
repo: ThreadSafeRepositorybranch: Option<String>workdir: Option<PathBuf>path: PathBufstate: Option<gix::state::InProgress>remote: Option<Remote>fs_monitor_value_is_true: bool
Both git_status and git_metrics can be expensive on large repos. They use parking_lot::Mutex for poison-free locks because the global rayon pool may run them concurrently. There are TODOs in git_metrics.rs about not yet using gix for sparse-index trees and detecting staged changes — see src/modules/git_metrics.rs.
For repositories that use the experimental reftables backend, git_branch falls back to invoking the system git binary because gix does not yet read reftables (uses_reftables in git_status.rs).
Mercurial
| Module | Purpose | File |
|---|---|---|
hg_branch |
Active branch and topic of the hg repo | src/modules/hg_branch.rs |
hg_state |
Active hg operation (e.g. MERGING) |
src/modules/hg_state.rs |
The hg modules use Context::begin_ancestor_scan to find a .hg/ directory upwards from the cwd, then either parse files inside it or call hg directly via context.exec_cmd.
Fossil
| Module | Purpose | File |
|---|---|---|
fossil_branch |
Active branch / check-out name | src/modules/fossil_branch.rs |
fossil_metrics |
Added/deleted lines in the check-out | src/modules/fossil_metrics.rs |
Both shell out to the fossil binary.
Pijul, VCS aggregator, VCSH
| Module | Purpose | File |
|---|---|---|
pijul_channel |
Current channel of a Pijul repo | src/modules/pijul_channel.rs |
vcs |
"First VCS that matches" — combines git, hg, fossil, pijul detection | src/modules/vcs.rs |
vcsh |
Active VCSH repository name | src/modules/vcsh.rs |
vcs is a meta-module that asks each VCS in turn whether it applies and renders the first match. It is useful for users who routinely work in non-Git repos.
How git_status works
git_status is the largest module in the codebase by far. The high level:
graph TD
Module["git_status::module"] --> Wsl["git_status_wsl<br/>(fast path on WSL/Windows)"]
Module --> Info["GitStatusInfo::load(ctx, repo, cfg)"]
Info --> Stash["count_stash<br/>(.git/refs/stash)"]
Info --> Status["gix::status::Platform"]
Info --> AB["compute_ahead_behind<br/>(gix::merge_base + revwalk)"]
Status --> Counts["{conflicted, deleted, renamed,<br/>modified, typechanged, staged, untracked}"]
Module --> Format["StringFormatter with $all_status<br/>$ahead_behind, etc."]Notable details:
- The platform code (
fn git_status_wsl) shells out togiton WSL wheregixwas historically slower than the system git for status. count_stashreads.git/refs/stashdirectly becausegixdid not initially support it.- The
formatconfig defaults to a long string that includes every state variable; users can simplify by overriding it. - Submodules are intentionally ignored unless
Submodule::AsConfiguredis overridden ingix::status::Platform.
Configuration knobs
Every VCS module supports disabled, a format string, a style, and a symbol. The Git modules additionally support truncation and ignored-bare-repo behavior. The full list lives in src/configs/<name>.rs and is reflected in .github/config-schema.json.
Performance notes
git_statusandgit_metricsare the modules most likely to slow a prompt down. They are off the critical path only if yourformatdoes not reference them.gixis configured withdefault-features = falseplus a curated feature set (seeCargo.toml); the comment there links to issue #4251 explaining why feature creep matters for prompt performance.- The user can globally bound module compute time via
command_timeout(default 500ms) in[StarshipRootConfig].
Entry points for modification
- To change what
git_statusshows for a state (e.g., add a new symbol), edit the appropriate<X>Configfield insrc/configs/git_status.rsand the matching variable mapping ingit_status::module. - To change how the branch is detected, edit
get_current_branchinsrc/context.rs. - To add a new VCS, write a new module and add it to the
vcsaggregator insrc/modules/vcs.rs.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.