Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Requires Node.js >= 22 and git >= 2.41.0.

The Node floor is the `engines` field in `package.json`, and it tracks active LTS: 22 is the oldest line still supported upstream, and CI runs both LTS lines plus Current. Raising it means moving `engines` and the CI matrix together.

The git floor tracks the newest git feature the code calls rather than a support policy. Today that feature is the `%(ahead-behind:<commit-ish>)` format atom, which carries the per-branch behind count (`READY-01`) and which git gained in 2.41.0; next below it are `git merge-tree --write-tree` (2.38.0), which is how the merge itself is built (`MERGE-08`), and `git branch -r --format=` (2.13.0) for the batched branch listing (`PERF-01`). Dropping the newest of the three would move the floor to 2.38.0, not back to 2.13.0. Reaching for a newer git feature means raising the floor in `PRE-02`, `src/git.ts`, and `scripts/postinstall.mjs` together, and naming the feature that moved it so the next person doesn't have to re-derive the number. The postinstall refuses the install below the floor (`PRE-06`) and cannot import the number from the build, so a test pins the two against each other.
The git floor tracks the newest git feature the code calls rather than a support policy. Today that feature is the `%(ahead-behind:<commit-ish>)` format atom, which carries the per-branch behind count (`READY-01`) and which git gained in 2.41.0; next below it are `git merge-tree --write-tree` (2.38.0), which is how the merge itself is built (`MERGE-08`), and `git branch -r --format=` (2.13.0) for the batched branch listing (`PERF-01`). Dropping the newest of the three would move the floor to 2.38.0, not back to 2.13.0. Reaching for a newer git feature means raising the floor in `PRE-02` and in `engines.git` in `package.json` (which `src/git.ts` reads) together, and naming the feature that moved it so the next person doesn't have to re-derive the number.

```bash
git clone https://github.com/gettyimages/git-fi.git
Expand Down Expand Up @@ -64,7 +64,7 @@ justfile Task runner wrapping the npm scripts
src/ TypeScript implementation
test/ Integration suite (Node test runner)
docs/ Docsify documentation site
scripts/ Build-time generators, the npm postinstall, the trial:on/off helper, the docs server
scripts/ Build-time generators, the trial:on/off helper, the docs server
man/ Generated man page (git-fi.1)
completions/ Generated bash + zsh completions (_git-fi, _git_fi, git-fi.bash)
```
Expand All @@ -73,7 +73,7 @@ The man page and shell completions are generated by `scripts/gen-docs.ts`, which

Three completion files ship because `git fi` is dispatched by two different providers: `_git-fi` drives zsh's built-in `_git`; `git-fi.bash` (defining `_git_fi`, git-completion style) drives git's own completion wrapper in bash; and `_git_fi` is the same `_git_fi` body on the zsh fpath, for git's wrapper under zsh. The git-native body (`git-fi.bash.tmpl`) is shared by the last two, so they can't drift. Each file has an `install-completions` target that prints it — `bash`, `zsh`, `zsh-git` respectively — and `--write <dir>` installs the zsh pair onto an fpath directory (`COMPLETE-06`); adding a file here means adding its target in `src/install-completions.ts`.

A global `npm install` copies the zsh pair into `<npm prefix>/share/zsh/site-functions` from `scripts/postinstall.mjs` (`COMPLETE-07`), so completion works with no extra step on the setups that carry that directory on their `fpath`. It's plain `.mjs` and lists the two filenames itself because npm runs `postinstall` before `prepare`, so `dist/` doesn't exist yet on a fresh clone; a test pins its file list to what `--write` installs. That copy exits 0 on any failure and does nothing for a local install. The git floor check ahead of it (`PRE-06`) is the one thing in the file that does fail an install, which is the point: a non-zero postinstall stops the install outright, so a git below the floor never gets a git-fi that cannot run on it.
The published package runs nothing at install time. Install scripts are a common supply-chain attack path, and many users and registries audit or block them, so completion is a command the user runs (`COMPLETE-06`, surfaced in `git fi -h` and the quickstart) and the git floor is checked when git-fi runs (`PRE-02`).

## Contributing

Expand Down
5 changes: 2 additions & 3 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Before any command executes, git-fi runs the following pre-flight checks:
3. `PRE-03` If `git config push.default` is `upstream` or `tracking`, then git-fi shall abort with: `Your default git push config is set to a hazardous option.`
4. `PRE-04` git-fi shall run `git fetch --quiet --prune --no-tags origin` once per invocation, memoizing to avoid redundant fetches. `--no-tags` because git-fi reads branches and never a tag, so asking for the tag refspec buys nothing it uses. What that saves is server-dependent and can be large: on one GitLab project, paired runs measured 12–15 s with tags against 1–2 s without, repeatably and while transferring no tags at all (the local and remote tag sets were identical); on another project of similar size and tag count on the same host, both forms took about a second. Tag count, missing tags, annotated-vs-lightweight, and repo size were each ruled out as the difference, so the cost is something server-side that git-fi can only decline to pay, not predict. A consequence worth knowing: `git fi` no longer refreshes tags as a side effect, so a stale tag is `git fetch`'s job rather than this one's.
5. `PRE-05` Where `GIT_FI_NO_FETCH` is set, git-fi shall skip the fetch (`PRE-04`) on read-only operations (`list`) and operate on the already-fetched remote-tracking refs. Shell completion sets this so tab-completion stays offline. Mutating operations always fetch regardless, so an integration merge never builds on stale refs. (All environment variables are catalogued in [Environment Variables](#environment-variables).)
6. `PRE-06` Installing git-fi shall check the git version before installing anything, and shall fail the install when git is absent, unreadable, or below the floor (`PRE-02`), naming the version found and giving the reader both ways forward: upgrade git, or install the last release built against the older floor. npm reads a non-zero postinstall as a failed install, so a git-fi that cannot run on the git present never lands; the floor is the one condition worth failing an install over, and the completion install (`COMPLETE-07`) stays soft. This does not replace `PRE-02`: `npm install --ignore-scripts` skips the check entirely, and git can be downgraded after a successful install, so the run-time check is the one that governs a run.

```mermaid
%%{ init: { 'look': 'handDrawn' } }%%
Expand Down Expand Up @@ -89,7 +88,7 @@ Shell Completion

`COMPLETE-06` `install-completions --write <dir>` shall write the zsh completion files into `<dir>`, creating it if absent, and shall name each path written. With no target it shall write both zsh files, so one command covers whichever provider (`COMPLETE-02`) the user's git install dispatches to; with `zsh` or `zsh-git` it shall write that one file, and with `bash` it shall abort — bash completion is sourced from an rc file and has no fpath to land on. It shall report reloading completions as a step for the user to run. git-fi shall not edit the user's rc files or write to any directory the user did not name; when `<dir>` cannot be created or written, it shall abort naming the path and how to install into a directory the user owns.

`COMPLETE-07` Installing git-fi globally shall install the zsh completion files, so `git fi <TAB>` works without a further step. They shall go under npm's own prefix (`<prefix>/share/zsh/site-functions`, the directory Homebrew and `/usr/local` zsh setups carry on their fpath, and the prefix npm already links the man page into); git-fi shall write nothing outside that prefix and shall not edit the user's rc files. A local (non-global) install shall install nothing. A prefix that cannot be resolved or written shall not fail the install: git-fi shall report the `COMPLETE-06` command that finishes the job and exit 0.
`COMPLETE-08` The usage summary (`HELP-01`) and the man page (`HELP-02`) shall show, for each supported shell, the one command that sets up completion. The package runs nothing at install time, so completion is a step the user takes, and the help is where they look for it.

## `TERM`

Expand Down Expand Up @@ -789,7 +788,7 @@ Build Provenance

A developer can put an unpublished checkout on PATH under the same `git fi` name the published install uses. These requirements keep the two tellable apart, so a bug report names the build it came from, and govern what ending that trial hands back.

- `BUILD-01` git-fi shall treat itself as a dev build when a `.git` entry exists at its own package root. A published tarball carries none — npm's `files` list ships `dist`, `man`, `completions`, and the postinstall script — so the marker separates a linked checkout from an installed copy. It shall be read at the package root rather than the working directory, which is a git repository on every ordinary run.
- `BUILD-01` git-fi shall treat itself as a dev build when a `.git` entry exists at its own package root. A published tarball carries none — npm's `files` list ships `dist`, `man`, and `completions` — so the marker separates a linked checkout from an installed copy. It shall be read at the package root rather than the working directory, which is a git repository on every ordinary run.
- `BUILD-02` On a dev build, `--version` (`OPTION-05`) shall report the released version followed by `-dev.g<short-sha>`, naming the commit the build came from, and shall append `.dirty` when the checkout's tree differs from that commit. The `g` prefix is what keeps the identifier valid semver: a sha of all digits would otherwise read as a numeric identifier, which may not carry leading zeros. When no commit can be read, git-fi shall report `-dev` alone rather than dropping the marker.
- `BUILD-03` Ending a trial shall restore the exact published version the trial displaced. `npm link` overwrites the global install, so the version is read before the link and kept under `.trial/`; `trial:off` then installs that version rather than whatever is newest, because a trial borrows an install and should hand back the one it borrowed. Where no published version was recorded — the package was absent, or already linked to a checkout — the trial shall say which of the two it found and install the latest, rather than leave the developer with no `git fi` at all. Where a version was recorded, the trial shall install that version or fail saying so; a recorded version that no longer resolves is not grounds for substituting another. A recorded value that is not a bare version shall be refused rather than passed to the installer, which reads the wider `name@spec` grammar.
- `BUILD-04` Ending a trial shall remove only the rc-file block it wrote, delimited by its own markers, and shall report any remaining line naming the trial's completion directory by its literal path rather than editing it away. That directory is deleted as the trial ends, so a hand-copied `fpath` entry naming it would otherwise be left pointing at nothing, and a line the developer wrote is not the script's to remove. A reference spelled through `~` or a variable is not detected.
Expand Down
9 changes: 4 additions & 5 deletions STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Tracks implementation status of each requirement in [SPEC.md](/SPEC.md).

**Last updated:** 2026-09-23
**Last updated:** 2026-10-22

Locations name the file and the enclosing symbol rather than a line range, so an
edit elsewhere in the same file leaves the row correct. `git grep` the symbol to
Expand All @@ -12,8 +12,8 @@ land on it.

| Status | Count |
|---------|-------|
| Covered | 137 |
| Total | 137 |
| Covered | 138 |
| Total | 138 |

## `PRE`

Expand All @@ -26,7 +26,6 @@ Pre-flight Checks
| PRE-03 | Push config | Covered | `src/git.ts` (`preflightChecks`)|
| PRE-04 | Fetch | Covered | `src/git.ts` (`ensureFetched`) |
| PRE-05 | `GIT_FI_NO_FETCH` skips fetch | Covered | `src/git.ts` (`ensureFetched`) |
| PRE-06 | Install-time git floor | Covered | `scripts/postinstall.mjs` (`refuse`) |

## `OPTION`

Expand Down Expand Up @@ -69,7 +68,7 @@ Shell Completion
| COMPLETE-04 | Offline membership | Covered | `scripts/completion/git-fi.bash.tmpl` (`GIT_FI_NO_FETCH`), `src/git.ts` (`ensureFetched`) |
| COMPLETE-05 | `install-completions` subcommand | Covered | `src/install-completions.ts` (`scriptFor`, `installCompletions`), `src/index.ts` (`parseArgs`) |
| COMPLETE-06 | `--write <dir>` onto the fpath | Covered | `src/install-completions.ts` (`writeToFpath`) |
| COMPLETE-07 | Completion installed on `npm i -g` | Covered | `scripts/postinstall.mjs`, `package.json` (`postinstall`, `files`) |
| COMPLETE-08 | Completion setup shown in help | Covered | `src/help.ts` (`COMPLETION_SETUP`, `renderHelp`), `scripts/gen-docs.ts` |

## `TERM`

Expand Down
18 changes: 17 additions & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ git-fi is a git subcommand: once the `git-fi` binary is on your `PATH`, invoke i
npm install -g @gettyimages/git-fi
```

Then turn on tab completion, so `git fi --add <TAB>` offers your branches. In zsh:

```zsh
git fi install-completions --write "${fpath[1]}"
```

In bash, add `source <(git fi install-completions bash)` to `~/.bashrc`. [Shell completion](#shell-completion) has the details.

To try it without installing, run `npx @gettyimages/git-fi --help` (this runs as `npx @gettyimages/git-fi`, not `git fi`).

On older git, or upgrading from the Ruby gem? See [Troubleshooting](/troubleshooting).
Expand Down Expand Up @@ -94,14 +102,22 @@ git fi --help # opens the man page

### Shell completion

In zsh, `npm install -g` sets this up for you — open a new shell and press `<TAB>`:
In zsh, write both completion files onto your `fpath`. The command creates the directory if needed and names each file it wrote:

```zsh
git fi install-completions --write "${fpath[1]}"
```

Open a new shell and press `<TAB>`:

```zsh
git fi <TAB> # actions, options, subcommands
git fi --add <TAB> # origin branches not yet in fi
git fi --remove <TAB> # only branches currently in fi
```

If `${fpath[1]}` isn't writable (a root-owned `/usr/local`, say), the command stops and shows how to install into a directory you own instead. Run it again after `git fi --update` so completion picks up new flags.

For bash, add one line to `~/.bashrc` (git's bash completion has to be loaded first):

```bash
Expand Down
4 changes: 2 additions & 2 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Your git is older than 2.41.0

The install checks git first and stops if it is older than 2.41.0, naming the version it found. Where the git you have is the one your platform gives you (a long-support distribution, Apple's command line tools), install the last release that runs on git 2.13 and newer:
Every `git fi` command checks git first and stops if it is older than 2.41.0, naming the version it found. Where the git you have is the one your platform gives you (a long-support distribution, Apple's command line tools), install the last release that runs on git 2.13 and newer:

```bash
npm install -g @gettyimages/git-fi@1.2.2
Expand Down Expand Up @@ -55,7 +55,7 @@ npm install -g @gettyimages/git-fi

## Tab completion offers filenames

`npm install -g` writes the zsh completion files into npm's own prefix (`$(npm config get prefix)/share/zsh/site-functions`), the directory Homebrew and `/usr/local` zsh setups already read. If `git fi <TAB>` offers filenames instead, that directory isn't on your `fpath`. Install into one that is; this creates it if needed and tells you what it wrote:
git-fi's completion isn't loaded. Install it into a directory on your `fpath`; this creates the directory if needed and tells you what it wrote:

```zsh
git fi install-completions --write "${fpath[1]}"
Expand Down
7 changes: 7 additions & 0 deletions man/git-fi.1
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,12 @@ Print the shell completion script (zsh\-git: for git's own zsh wrapper)
.TP
.B install\-completions \-\-write <dir>
Write both zsh completion files onto an fpath directory
.SH SHELL COMPLETION
.TP
.B zsh
git fi install\-completions \-\-write "${fpath[1]}"
.TP
.B bash
add to ~/.bashrc: source <(git fi install\-completions bash)
.SH SEE ALSO
Full documentation: https://gettyimages.github.io/git\-fi/
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"gen:docs": "node --import tsx scripts/gen-docs.ts",
"build": "tsc && npm run gen:docs",
"prepare": "tsc",
"postinstall": "node scripts/postinstall.mjs",
"test": "tsc && npm run verify:generated && node scripts/run-tests.mjs",
"verify:generated": "node --import tsx scripts/gen-docs.ts --check",
"prepublishOnly": "npm test",
Expand All @@ -23,8 +22,7 @@
"files": [
"dist",
"man",
"completions",
"scripts/postinstall.mjs"
"completions"
],
"publishConfig": {
"access": "public"
Expand Down
4 changes: 3 additions & 1 deletion scripts/gen-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import { ACTIONS, OPTIONS, SUBCOMMANDS, TAGLINE, DOCS_URL, longForm, type Flag } from "../src/help.js";
import { ACTIONS, OPTIONS, SUBCOMMANDS, COMPLETION_SETUP, TAGLINE, DOCS_URL, longForm, type Flag } from "../src/help.js";

const here = dirname(fileURLToPath(import.meta.url));
const root = join(here, "..");
Expand Down Expand Up @@ -58,6 +58,8 @@ const man =
OPTIONS.map(manEntry).join("\n") + "\n" +
`.SH COMMANDS\n` +
SUBCOMMANDS.map((c) => `.TP\n.B ${roff(c.usage)}\n${roff(c.desc)}`).join("\n") + "\n" +
`.SH SHELL COMPLETION\n` +
COMPLETION_SETUP.map((c) => `.TP\n.B ${c.shell}\n${roff(c.how)}`).join("\n") + "\n" +
`.SH SEE ALSO\n` +
`Full documentation: ${roff(DOCS_URL)}\n`;

Expand Down
Loading
Loading