git-worktrees 0.7.0__tar.gz → 0.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- git_worktrees-0.9.0/.claude/settings.json +14 -0
- git_worktrees-0.9.0/.codex/config.toml +9 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/.github/workflows/publish.yml +4 -2
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/.github/workflows/tests.yml +3 -0
- git_worktrees-0.9.0/AGENTS.md +621 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/CHANGELOG.md +331 -0
- git_worktrees-0.9.0/Makefile +52 -0
- git_worktrees-0.9.0/PKG-INFO +603 -0
- git_worktrees-0.9.0/README.md +576 -0
- git_worktrees-0.9.0/completions/gw.fish +104 -0
- git_worktrees-0.9.0/conf.d/worktrees.fish +7 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/docs/BENCHMARK.md +4 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/docs/DEVELOPMENT.md +90 -50
- git_worktrees-0.9.0/docs/REFERENCE.md +285 -0
- git_worktrees-0.9.0/docs/commands/branch-prune.md +64 -0
- git_worktrees-0.9.0/docs/commands/branch-status.md +38 -0
- git_worktrees-0.9.0/docs/commands/fast-forward.md +171 -0
- git_worktrees-0.9.0/docs/plans/2026-11-05-worktree-pruning-design.md +464 -0
- git_worktrees-0.9.0/functions/gw.fish +30 -0
- git_worktrees-0.9.0/functions/gwa.fish +3 -0
- git_worktrees-0.9.0/functions/gwbc.fish +3 -0
- git_worktrees-0.9.0/functions/gwbp.fish +3 -0
- git_worktrees-0.9.0/functions/gwbs.fish +3 -0
- git_worktrees-0.9.0/functions/gwff.fish +3 -0
- git_worktrees-0.9.0/functions/gwl.fish +3 -0
- git_worktrees-0.9.0/functions/gwm.fish +3 -0
- git_worktrees-0.9.0/functions/gwp!.fish +3 -0
- git_worktrees-0.9.0/functions/gwp.fish +3 -0
- git_worktrees-0.9.0/functions/gwpa!.fish +3 -0
- git_worktrees-0.9.0/functions/gwpa.fish +3 -0
- git_worktrees-0.9.0/functions/gwr!.fish +3 -0
- git_worktrees-0.9.0/functions/gwr.fish +3 -0
- git_worktrees-0.9.0/functions/gws.fish +3 -0
- git_worktrees-0.9.0/plugin/.claude-plugin/plugin.json +23 -0
- git_worktrees-0.9.0/plugin/.codex-plugin/plugin.json +48 -0
- git_worktrees-0.9.0/plugin/README.md +182 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/plugin/plugin.json +6 -2
- git_worktrees-0.9.0/plugin/skills/ci-checks/SKILL.md +91 -0
- git_worktrees-0.9.0/plugin/skills/describe-pr/SKILL.md +81 -0
- git_worktrees-0.9.0/plugin/skills/describe-pr/format.md +100 -0
- git_worktrees-0.9.0/plugin/skills/fast-forward/SKILL.md +158 -0
- git_worktrees-0.9.0/plugin/skills/new-branch/SKILL.md +51 -0
- git_worktrees-0.9.0/plugin/skills/preflight/SKILL.md +96 -0
- git_worktrees-0.9.0/plugin/skills/preflight/agents/openai.yaml +2 -0
- git_worktrees-0.9.0/plugin/skills/preflight/rules.json +27 -0
- git_worktrees-0.9.0/plugin/skills/prune/SKILL.md +165 -0
- git_worktrees-0.9.0/plugin/skills/ship-it/SKILL.md +411 -0
- git_worktrees-0.9.0/plugin/skills/ship-it/rights.md +99 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/pyproject.toml +9 -14
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/scripts/README.md +1 -1
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/scripts/benchmark.py +1 -2
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/src/worktrees/branch_cli.py +95 -38
- git_worktrees-0.9.0/src/worktrees/branch_forge.py +454 -0
- git_worktrees-0.9.0/src/worktrees/branches.py +160 -0
- git_worktrees-0.9.0/src/worktrees/ci.py +436 -0
- git_worktrees-0.9.0/src/worktrees/cli.py +1900 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/src/worktrees/errors.py +4 -0
- git_worktrees-0.9.0/src/worktrees/fast_forward.py +892 -0
- git_worktrees-0.9.0/src/worktrees/forge.py +140 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/src/worktrees/git.py +34 -17
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/src/worktrees/layout.py +5 -5
- git_worktrees-0.9.0/src/worktrees/merged.py +250 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/src/worktrees/new_branch.py +6 -32
- git_worktrees-0.9.0/src/worktrees/pick.py +338 -0
- git_worktrees-0.9.0/src/worktrees/progress.py +98 -0
- git_worktrees-0.9.0/src/worktrees/prune.py +418 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/src/worktrees/render.py +40 -9
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/src/worktrees/repo.py +242 -108
- git_worktrees-0.9.0/src/worktrees/sync.py +409 -0
- git_worktrees-0.9.0/src/worktrees/verdicts.py +230 -0
- git_worktrees-0.9.0/src/worktrees/worktree.py +196 -0
- git_worktrees-0.9.0/tests/conftest.py +370 -0
- git_worktrees-0.9.0/tests/test_assessment.py +847 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/tests/test_branch_forge.py +85 -41
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/tests/test_branches.py +78 -68
- git_worktrees-0.9.0/tests/test_ci.py +552 -0
- git_worktrees-0.9.0/tests/test_cli.py +1661 -0
- git_worktrees-0.9.0/tests/test_command_defaults.py +212 -0
- git_worktrees-0.9.0/tests/test_completions.py +486 -0
- git_worktrees-0.9.0/tests/test_fast_forward.py +1476 -0
- git_worktrees-0.9.0/tests/test_forge.py +200 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/tests/test_gates.py +123 -19
- git_worktrees-0.9.0/tests/test_git_records.py +146 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/tests/test_new_branch.py +29 -28
- git_worktrees-0.9.0/tests/test_partial_clone.py +372 -0
- git_worktrees-0.9.0/tests/test_path_boundaries.py +246 -0
- git_worktrees-0.9.0/tests/test_plugin.py +621 -0
- git_worktrees-0.9.0/tests/test_removal.py +1115 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/tests/test_render.py +3 -3
- git_worktrees-0.9.0/tests/test_shims.py +666 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/tests/test_spec.py +2 -2
- git_worktrees-0.9.0/tests/test_sync.py +1381 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/tests/test_version.py +5 -3
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/tests/test_worktree.py +244 -123
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/uv.lock +36 -11
- git_worktrees-0.9.0/zsh/plugins/worktrees/completions/_gw +203 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gw +28 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwa +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwbc +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwbp +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwbs +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwff +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwl +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwm +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwp +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwp! +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwpa +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwpa! +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwr +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gwr! +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/functions/gws +1 -0
- git_worktrees-0.9.0/zsh/plugins/worktrees/worktrees.plugin.zsh +15 -0
- git_worktrees-0.7.0/.claude/settings.json +0 -6
- git_worktrees-0.7.0/AGENTS.md +0 -451
- git_worktrees-0.7.0/Makefile +0 -9
- git_worktrees-0.7.0/PKG-INFO +0 -697
- git_worktrees-0.7.0/README.md +0 -671
- git_worktrees-0.7.0/completions/gw.fish +0 -39
- git_worktrees-0.7.0/completions/gwa.fish +0 -13
- git_worktrees-0.7.0/completions/gwbc.fish +0 -13
- git_worktrees-0.7.0/completions/gwbd.fish +0 -14
- git_worktrees-0.7.0/completions/gwbs.fish +0 -13
- git_worktrees-0.7.0/completions/gwh.fish +0 -5
- git_worktrees-0.7.0/completions/gwl.fish +0 -14
- git_worktrees-0.7.0/completions/gwm.fish +0 -10
- git_worktrees-0.7.0/completions/gwp.fish +0 -17
- git_worktrees-0.7.0/completions/gwr.fish +0 -19
- git_worktrees-0.7.0/completions/gwrot.fish +0 -13
- git_worktrees-0.7.0/completions/gws.fish +0 -18
- git_worktrees-0.7.0/conf.d/worktrees.fish +0 -7
- git_worktrees-0.7.0/docs/REFERENCE.md +0 -454
- git_worktrees-0.7.0/docs/commands/branch-delete.md +0 -77
- git_worktrees-0.7.0/docs/commands/branch-status.md +0 -110
- git_worktrees-0.7.0/functions/gwa.fish +0 -18
- git_worktrees-0.7.0/functions/gwl.fish +0 -18
- git_worktrees-0.7.0/functions/gwm.fish +0 -18
- git_worktrees-0.7.0/functions/gwp!.fish +0 -4
- git_worktrees-0.7.0/functions/gwr!.fish +0 -6
- git_worktrees-0.7.0/functions/gwr.fish +0 -18
- git_worktrees-0.7.0/plugin/.claude-plugin/plugin.json +0 -13
- git_worktrees-0.7.0/plugin/.codex-plugin/plugin.json +0 -33
- git_worktrees-0.7.0/plugin/README.md +0 -68
- git_worktrees-0.7.0/plugin/commands/prune.md +0 -26
- git_worktrees-0.7.0/plugin/skills/worktrees/SKILL.md +0 -137
- git_worktrees-0.7.0/src/worktrees/branch_forge.py +0 -156
- git_worktrees-0.7.0/src/worktrees/branches.py +0 -173
- git_worktrees-0.7.0/src/worktrees/cli.py +0 -1645
- git_worktrees-0.7.0/src/worktrees/forge.py +0 -284
- git_worktrees-0.7.0/src/worktrees/merged.py +0 -131
- git_worktrees-0.7.0/src/worktrees/pick.py +0 -244
- git_worktrees-0.7.0/src/worktrees/progress.py +0 -73
- git_worktrees-0.7.0/src/worktrees/prune.py +0 -224
- git_worktrees-0.7.0/src/worktrees/rotate.py +0 -218
- git_worktrees-0.7.0/src/worktrees/verdicts.py +0 -212
- git_worktrees-0.7.0/src/worktrees/worktree.py +0 -261
- git_worktrees-0.7.0/tests/conftest.py +0 -150
- git_worktrees-0.7.0/tests/test_cli.py +0 -1134
- git_worktrees-0.7.0/tests/test_completions.py +0 -281
- git_worktrees-0.7.0/tests/test_forge.py +0 -643
- git_worktrees-0.7.0/tests/test_plugin.py +0 -118
- git_worktrees-0.7.0/tests/test_rotate.py +0 -291
- git_worktrees-0.7.0/tests/test_shims.py +0 -419
- git_worktrees-0.7.0/zsh/plugins/worktrees/completions/_gw +0 -74
- git_worktrees-0.7.0/zsh/plugins/worktrees/completions/_gwa +0 -12
- git_worktrees-0.7.0/zsh/plugins/worktrees/completions/_gwbc +0 -12
- git_worktrees-0.7.0/zsh/plugins/worktrees/completions/_gwbd +0 -22
- git_worktrees-0.7.0/zsh/plugins/worktrees/completions/_gwbs +0 -21
- git_worktrees-0.7.0/zsh/plugins/worktrees/completions/_gwh +0 -6
- git_worktrees-0.7.0/zsh/plugins/worktrees/completions/_gwl +0 -25
- git_worktrees-0.7.0/zsh/plugins/worktrees/completions/_gwm +0 -10
- git_worktrees-0.7.0/zsh/plugins/worktrees/completions/_gwp +0 -16
- git_worktrees-0.7.0/zsh/plugins/worktrees/completions/_gwr +0 -30
- git_worktrees-0.7.0/zsh/plugins/worktrees/completions/_gwrot +0 -12
- git_worktrees-0.7.0/zsh/plugins/worktrees/completions/_gws +0 -17
- git_worktrees-0.7.0/zsh/plugins/worktrees/functions/gwa +0 -14
- git_worktrees-0.7.0/zsh/plugins/worktrees/functions/gwl +0 -14
- git_worktrees-0.7.0/zsh/plugins/worktrees/functions/gwm +0 -14
- git_worktrees-0.7.0/zsh/plugins/worktrees/functions/gwp! +0 -2
- git_worktrees-0.7.0/zsh/plugins/worktrees/functions/gwr +0 -14
- git_worktrees-0.7.0/zsh/plugins/worktrees/functions/gwr! +0 -4
- git_worktrees-0.7.0/zsh/plugins/worktrees/worktrees.plugin.zsh +0 -21
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/.github/workflows/codeql.yml +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/.github/workflows/testpypi.yml +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/.gitignore +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/.pre-commit-config.yaml +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/.python-version +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/.releasetools.yaml +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/LICENSE +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/completions/worktrees.fish +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/hatch_build.py +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/renovate.json +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/scripts/bump_version.py +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/scripts/verify-publish.bash +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/src/worktrees/__init__.py +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/tests/test_benchmark.py +0 -0
- {git_worktrees-0.7.0 → git_worktrees-0.9.0}/tests/test_fixture.py +0 -0
|
@@ -100,9 +100,11 @@ jobs:
|
|
|
100
100
|
- name: Install fish and zsh
|
|
101
101
|
run: sudo apt-get update && sudo apt-get install -y fish zsh
|
|
102
102
|
|
|
103
|
-
# The tag is the last chance to catch a regression,
|
|
103
|
+
# The tag is the last chance to catch a regression, so both suites run.
|
|
104
104
|
- name: Run tests
|
|
105
|
-
run:
|
|
105
|
+
run: |
|
|
106
|
+
uv run --no-sync pytest tests -q
|
|
107
|
+
uv run --no-sync pytest tests -q -m integration
|
|
106
108
|
|
|
107
109
|
- name: Build
|
|
108
110
|
run: uv build
|
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
# Working in this repository
|
|
2
|
+
|
|
3
|
+
A Python CLI for git worktrees. `pyproject.toml` declares one console script,
|
|
4
|
+
`gw`, and its long name `worktrees`; `src/worktrees/` holds the commands;
|
|
5
|
+
`tests/` drives the entry points through `subprocess` so env, cwd, both
|
|
6
|
+
streams and the exit code stay per-test.
|
|
7
|
+
|
|
8
|
+
```console
|
|
9
|
+
uv sync --all-extras
|
|
10
|
+
uv run --no-sync pre-commit install
|
|
11
|
+
uv run --no-sync pytest tests
|
|
12
|
+
uv run --no-sync pytest tests -m integration
|
|
13
|
+
uv run --no-sync pre-commit run --all-files
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
pytest runs one pytest-xdist worker per core. Add `-n0` to run in one process,
|
|
17
|
+
which `-x` and `--pdb` need.
|
|
18
|
+
|
|
19
|
+
`pre-commit run --all-files` reads `git ls-files`, so a file that is new and
|
|
20
|
+
unstaged is invisible to it. Stage before running the hooks, or install them
|
|
21
|
+
and let the commit do it.
|
|
22
|
+
|
|
23
|
+
Read [scripts/README.md](scripts/README.md) before measuring anything. It says
|
|
24
|
+
what is worth timing and what is not, and why every interpreter the benchmark
|
|
25
|
+
touches comes from uv: a run that compares packagers rather than versions
|
|
26
|
+
produces a number that looks like a CPython regression and is not one.
|
|
27
|
+
|
|
28
|
+
## Binaries and shell functions are not interchangeable
|
|
29
|
+
|
|
30
|
+
A shell function of a given name beats a binary of that name in bash, zsh and
|
|
31
|
+
fish, and in fish it beats it in `fish -c` too, where the function is autoloaded
|
|
32
|
+
from `functions/`. So a command that exists as both runs different code from a
|
|
33
|
+
prompt and from a script unless the function is a pure adapter.
|
|
34
|
+
|
|
35
|
+
`gw` is the one name that is both. Its function calls `command gw`, changes
|
|
36
|
+
directory when `gw add`, `gw remove`, `gw select-main` or a terminal
|
|
37
|
+
`gw list` or `gw l` prints a destination, and prints data otherwise. Metadata flags and
|
|
38
|
+
nonterminal input print data. `gw remove` can return a destination after checkout removal and
|
|
39
|
+
failure for later cleanup; the function changes directory and preserves the
|
|
40
|
+
failure status. Every other subcommand passes straight through. The words
|
|
41
|
+
that land are the rows with `lands` set, and `tests/test_shims.py` holds both
|
|
42
|
+
functions to them.
|
|
43
|
+
|
|
44
|
+
`--json` and `--table` print data on the destination stream. A function that
|
|
45
|
+
cannot tell them apart can try to `cd` into a JSON object or suppress its
|
|
46
|
+
output. `fish -c 'gw list --json'` reaches the function too, so this is the
|
|
47
|
+
agent path as much as the human one.
|
|
48
|
+
|
|
49
|
+
| name | ships as |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| `gw`, `worktrees` | a console script; `gw` is also the function that changes directory |
|
|
52
|
+
| `gwa`, `gwp`, `gwp!`, `gwr` and every other shortcut | a plugin function, and nothing else |
|
|
53
|
+
|
|
54
|
+
A binary cannot `cd` its caller. That is the only thing shell code is here for,
|
|
55
|
+
and any logic that reaches a shell file is logic a script cannot call.
|
|
56
|
+
|
|
57
|
+
The `gw` function preserves stdout bytes, including trailing newlines in a path. Fish
|
|
58
|
+
uses `string collect -N` and `$pipestatus[1]`; zsh appends a sentinel inside
|
|
59
|
+
command substitution so it can recover trailing newlines. Both remove only
|
|
60
|
+
the destination record's final newline, require an absolute existing
|
|
61
|
+
directory, and preserve the binary's status. Data output is printed intact.
|
|
62
|
+
Read [the fish function](functions/gw.fish) and
|
|
63
|
+
[the zsh function](zsh/plugins/worktrees/functions/gw) for the implementation.
|
|
64
|
+
|
|
65
|
+
`command` is what stops the function calling itself, in all three shells.
|
|
66
|
+
|
|
67
|
+
Because the function captures stdout, a command that lands prints its `--help`
|
|
68
|
+
on stderr, and argparse is asked whether that stream is a terminal before it
|
|
69
|
+
picks colour. A missing argument prints the error and then the help, both on
|
|
70
|
+
stderr, at exit 2: the function prints nothing captured from a run that
|
|
71
|
+
failed.
|
|
72
|
+
|
|
73
|
+
A shortcut is one call to the `gw` function with fixed words, by its plain
|
|
74
|
+
name so a shortcut to a command that lands still lands: `gwa` calls `gw add`,
|
|
75
|
+
`gwl` calls `gw list`, `gwr!` calls `gw remove --yes`, and
|
|
76
|
+
`gwpa!` calls `gw prune --delete all --yes`. No shortcut has a console script.
|
|
77
|
+
The `shortcuts` field of a row in `cli.py` lists that command's; `gw --help`
|
|
78
|
+
prints them under it, and `tests/test_shims.py` holds every function file in
|
|
79
|
+
both shells to that table. fish completes a shortcut through its `--wraps`,
|
|
80
|
+
zsh through the shortcut's line in `_gw`. A shortcut's `!` is its last
|
|
81
|
+
character, and interactive zsh and bash leave a `!` before a blank or the end
|
|
82
|
+
of the line alone, so no shortcut meets history expansion. `!!` would.
|
|
83
|
+
|
|
84
|
+
## Two commands start branches
|
|
85
|
+
|
|
86
|
+
`gw branch create` and `gw fast-forward` start branches, not worktrees.
|
|
87
|
+
`gw branch create NAME` starts NAME off the head ref, as `origin new-branch`
|
|
88
|
+
does, and keeps argparse's 2 for a usage error where `origin` has a single
|
|
89
|
+
non-zero exit code.
|
|
90
|
+
|
|
91
|
+
`gw fast-forward` starts a branch only when the one you stand on is proved
|
|
92
|
+
finished, by the same `merged.branch_proof` that `gw prune` reads, or when
|
|
93
|
+
its first commits are and its own request merged them: `merged.boundary`
|
|
94
|
+
asks each commit below the tip, from the tip down, since the first of a
|
|
95
|
+
squashed pair is not upstream on its own. A branch whose merged part is
|
|
96
|
+
another branch's, a stacked one whose parent merged, keeps its name and its
|
|
97
|
+
open request, and drops the merged commits in place with the same
|
|
98
|
+
`git rebase --onto`. When the parent gained commits before it merged, its
|
|
99
|
+
squash holds more than the two share, so no local proof marks the shared
|
|
100
|
+
part; `branch_forge.carried_by` asks the forge which merged request carried
|
|
101
|
+
the branch's oldest commit, and that request's commit list marks it, read
|
|
102
|
+
from one page of 100 by choice: a parent seldom drifts further.
|
|
103
|
+
Once a carry finishes, each stash made after the merged part moves to the
|
|
104
|
+
replayed copy of its commit, matched by patch-id:
|
|
105
|
+
`git merge-tree --write-tree` re-bases it without touching the checkout,
|
|
106
|
+
`git stash store` records the copy, and `prune.drop_stash` drops the
|
|
107
|
+
original by sha with the check `gw branch prune` makes.
|
|
108
|
+
A merged branch's name stays with its merged request on the forge, so the
|
|
109
|
+
finished branch keeps its name and commits and the checkout moves to
|
|
110
|
+
`YYYY-MM-DDThh-mm-ssZ/<stem>` in UTC, or to the NAME given, from the head
|
|
111
|
+
ref or `--from`. Commits after the merged part are replayed onto it with
|
|
112
|
+
`git rebase --onto`, so a stop is an ordinary stopped rebase. The stem drops
|
|
113
|
+
a time an earlier rotation put in front, and a name held here or on the
|
|
114
|
+
default remote is refused.
|
|
115
|
+
|
|
116
|
+
It decides on evidence read in the same run. It fetches the default remote
|
|
117
|
+
whatever the TTL and asks the forge for the branch's newest merged request,
|
|
118
|
+
never reading the cached one, since a pull request merged a moment ago is
|
|
119
|
+
the usual reason to run it. Either failing is a refusal whose last line is
|
|
120
|
+
the same command under `WORKTREES_OFFLINE=1`.
|
|
121
|
+
|
|
122
|
+
Every other branch keeps its name. One with no commits of its own
|
|
123
|
+
fast-forwards and one with commits is rebased, both with `--no-autostash`
|
|
124
|
+
unless `--autostash` is given: `merge.autoStash` and `rebase.autoStash`
|
|
125
|
+
would move a dirty tree into the stash list every worktree shares without
|
|
126
|
+
being asked. Under `--autostash`, git's own autostash carries the changes,
|
|
127
|
+
and one that does not re-apply leaves an `autostash` entry that the result
|
|
128
|
+
names by sha as `stash-conflict`. The first conflict stops the rebase and
|
|
129
|
+
leaves it in progress, at exit 1 with the stopped commit and files in
|
|
130
|
+
`--json`, for a person or the agent plugin to finish with
|
|
131
|
+
`git rebase --continue`. A branch already level exits 0. The head branch
|
|
132
|
+
only fast-forwards.
|
|
133
|
+
[fast-forward](docs/commands/fast-forward.md) gives the order of the checks.
|
|
134
|
+
|
|
135
|
+
## Where shell code goes
|
|
136
|
+
|
|
137
|
+
Fisher copies `functions/`, `completions/` and `conf.d/` from the repository
|
|
138
|
+
root and nothing else. Antidote takes a `path:` into the repository and wants a
|
|
139
|
+
`<name>.plugin.zsh` there. So the two live in different places:
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
functions/gw.fish fish, installed by Fisher
|
|
143
|
+
functions/gwa.fish
|
|
144
|
+
completions/gw.fish
|
|
145
|
+
zsh/plugins/worktrees/worktrees.plugin.zsh zsh, installed by Antidote
|
|
146
|
+
zsh/plugins/worktrees/functions/gw
|
|
147
|
+
zsh/plugins/worktrees/functions/gwa
|
|
148
|
+
zsh/plugins/worktrees/completions/_gw
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Neither manager puts a binary on `$PATH`. `gw` arrives through
|
|
152
|
+
`uv tool install` from the published package, which is a separate step.
|
|
153
|
+
|
|
154
|
+
Both plugins export `WORKTREES_PLUGIN_VERSION`, the release they came from:
|
|
155
|
+
`conf.d/worktrees.fish` and `worktrees.plugin.zsh`, one assignment each.
|
|
156
|
+
`gw --help` and `gw version` compare it with `__version__`, in Python; the shell
|
|
157
|
+
files hold the value and no logic. Nothing built can stamp a file a plugin
|
|
158
|
+
manager copies from git, so `scripts/bump_version.py` writes it at release,
|
|
159
|
+
along with the tag in the README's install lines, and `tests/test_version.py`
|
|
160
|
+
fails when a copy disagrees with `pyproject.toml`.
|
|
161
|
+
|
|
162
|
+
Nothing installs this from a checkout on the user's disk. It is consumed as a
|
|
163
|
+
third-party plugin and a third-party tool, so anything that assumes a local
|
|
164
|
+
clone at a known path is wrong here.
|
|
165
|
+
|
|
166
|
+
A completion asks the CLI for its candidates rather than deriving them, and
|
|
167
|
+
`--complete` is how: `gw --complete` prints every subcommand and shorthand,
|
|
168
|
+
`gw list --complete` prints every worktree, both as name and description separated
|
|
169
|
+
by a tab, which fish reads directly and zsh splits for `_describe`. Hidden from
|
|
170
|
+
`--help`, because a person has `gw --help` and `--table` for the same answers.
|
|
171
|
+
|
|
172
|
+
No shell file holds a candidate or a rank. What `completions/gw.fish` and
|
|
173
|
+
`_gw` do carry is each subcommand's flags, and `tests/test_completions.py`
|
|
174
|
+
diffs those against `gw <command> --help` in both directions for both shells:
|
|
175
|
+
a renamed flag fails there rather than going quiet in a completion nobody is
|
|
176
|
+
watching. A shortcut has no completion file of its own.
|
|
177
|
+
|
|
178
|
+
## The agent plugin reads `--json`
|
|
179
|
+
|
|
180
|
+
`plugin/` ships with the CLI: seven skills, each a directory under
|
|
181
|
+
`plugin/skills/` named as its command is, `/worktrees:<name>` in Claude Code
|
|
182
|
+
and `$worktrees:<name>` in Codex. Skills call `gw` from `$PATH`; nothing
|
|
183
|
+
assumes a plugin root or a checkout at a known path.
|
|
184
|
+
|
|
185
|
+
| skill | runs |
|
|
186
|
+
| --- | --- |
|
|
187
|
+
| `new-branch` | `gw sync`, then `gw branch create` |
|
|
188
|
+
| `fast-forward` | `gw fast-forward --autostash --json`, then each rebase conflict until the branch is level |
|
|
189
|
+
| `ci-checks` | `gw ci-checks --json`, `--wait` to wait without polling |
|
|
190
|
+
| `describe-pr` | checks a review's title and body against its diff, and edits them |
|
|
191
|
+
| `prune` | `gw prune --json` and `gw branch status --json`, then the removals approved |
|
|
192
|
+
| `ship-it` | commits, `fast-forward`, a leased or plain push, `gh pr create`, `describe-pr`, `ci-checks`, fixes on the branch, `gh pr merge`, then `fast-forward` in the head branch's checkout, unassisted, for this checkout or each branch it is named; given numbers, those open reviews from `ci-checks` on |
|
|
193
|
+
| `preflight` | `jq` merges `preflight/rules.json` into the user's or the project's `.claude/settings.json`, after asking |
|
|
194
|
+
|
|
195
|
+
`describe-pr` and `ship-it` share `describe-pr/format.md`: the
|
|
196
|
+
review's title and body are the squash commit's subject and body, so one set
|
|
197
|
+
of rules writes both. `tests/test_plugin.py` holds every skill's
|
|
198
|
+
`allowed-tools` to reads, `gw sync` and `gw branch create`: no pattern
|
|
199
|
+
covers a removal, a merge, a push, a rerun or a checkout that moves. Three
|
|
200
|
+
exceptions are each skill's job: `describe-pr` may edit a review,
|
|
201
|
+
`fast-forward` runs `gw fast-forward` and the conflict loop its own test
|
|
202
|
+
lists, and `ship-it`, invoked to publish one change or the reviews it
|
|
203
|
+
names, commits, pushes, opens and edits the review, reruns CI and merges,
|
|
204
|
+
as its own test lists. None pre-approves a removal.
|
|
205
|
+
|
|
206
|
+
A plugin cannot grant a skill more than the turn that invoked it in Claude
|
|
207
|
+
Code, and nothing at all in Codex, so `ship-it/rights.md` lists the rules a
|
|
208
|
+
user adds to their own client configuration, and the skill checks for them
|
|
209
|
+
before it starts. The Claude Code ones live once, in `preflight/rules.json`,
|
|
210
|
+
which `preflight` merges into the settings file the user names. It runs only
|
|
211
|
+
when called by name, in both clients, and pre-approves no write, so the copy
|
|
212
|
+
over the settings file reaches the client's own prompt. Its allow patterns match prefixes, so a test holds the
|
|
213
|
+
skill's commands to never writing `--force`, `--admin`, `--auto` or
|
|
214
|
+
`--delete-branch`.
|
|
215
|
+
|
|
216
|
+
The prune skill reads `gw prune --json` and
|
|
217
|
+
`gw branch status --json`, preserving head/sync state and full rows for eligible, empty,
|
|
218
|
+
stash-blocked and ignored-file cases. `tests/test_plugin.py` extracts the
|
|
219
|
+
actual jq filters and applies them to real CLI output. Checked-out branches
|
|
220
|
+
are absent from the loose-branch list. Paths and restore commands must retain
|
|
221
|
+
exact quoting.
|
|
222
|
+
|
|
223
|
+
The prune skill's assessments sync first when one is due. The skill asks
|
|
224
|
+
before syncing state that is still stale or never synced after that, and
|
|
225
|
+
runs `gw sync` only on the user's answer; under `WORKTREES_OFFLINE` that
|
|
226
|
+
command refuses, and the skill goes on with the evidence there is. Removal approval covers chosen targets
|
|
227
|
+
and explicit deletion categories. Each worktree goes through
|
|
228
|
+
`command gw remove` with its exact quoted JSON path, then selected loose
|
|
229
|
+
branches through `command gw branch prune`. The plugin never targets its current checkout. It reports
|
|
230
|
+
partial checkout, branch and stash outcomes and actual restore commands.
|
|
231
|
+
|
|
232
|
+
The plugin carries the release version in three manifests, and
|
|
233
|
+
`scripts/bump_version.py` stamps all three. `plugin/plugin.json` is the
|
|
234
|
+
portable manifest, the Claude one with only the fields Agent Plugins v1 names;
|
|
235
|
+
the same test holds it to that.
|
|
236
|
+
|
|
237
|
+
## The picker is Python's, and there is no fzf
|
|
238
|
+
|
|
239
|
+
Building the candidate list, matching a query against it, ranking, deciding
|
|
240
|
+
what each row shows, reading the answer back: all of it in the CLI. No shell
|
|
241
|
+
file holds a candidate, a format string or a rank, and nothing spawns an
|
|
242
|
+
external picker.
|
|
243
|
+
|
|
244
|
+
Typing filters the list with the matching `gw list QUERY` uses, so a
|
|
245
|
+
repository with forty worktrees narrows to one in a few keys:
|
|
246
|
+
|
|
247
|
+
```
|
|
248
|
+
WORKTREE BRANCH PATH
|
|
249
|
+
> repo main /home/you/git/repo
|
|
250
|
+
fix-parser fix-parser /home/you/git/.worktrees/fix-parser/repo
|
|
251
|
+
add-tests add-tests /home/you/git/.worktrees/add-tests/repo
|
|
252
|
+
which? [type to filter, up/down and enter, esc to cancel]
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Every printable key goes into the filter, digits included, because names
|
|
256
|
+
carry them: `release-0.6.2`, and every branch `gw fast-forward` names. Rows carry no
|
|
257
|
+
numbers for the same reason. Backspace takes a letter back, up and down move
|
|
258
|
+
the highlight and wrap, and enter takes it. Esc clears the filter; on an
|
|
259
|
+
empty filter it cancels, as ctrl-d does, and the hint names which of the two
|
|
260
|
+
it does now. `gw list QUERY` opens the list filtered by its query, so one esc
|
|
261
|
+
widens it to every worktree.
|
|
262
|
+
|
|
263
|
+
An arrow is `ESC [ A` or, in application mode, `ESC O A`. Any other `ESC [`
|
|
264
|
+
sequence is read to its final byte and dropped, so the `~` that ends the
|
|
265
|
+
delete key is never typed into the filter. A byte after an esc that starts
|
|
266
|
+
no sequence is a key of its own, so two escapes written together are two.
|
|
267
|
+
|
|
268
|
+
The terminal goes into cbreak mode
|
|
269
|
+
through the stdlib's `termios`, so ctrl-c still raises `KeyboardInterrupt`.
|
|
270
|
+
Both switches use `TCSANOW`: `TCSAFLUSH` discards keys typed before the list
|
|
271
|
+
appears, and `TCSADRAIN` blocks on an echo queue nothing reads, which is how
|
|
272
|
+
the pty tests hang.
|
|
273
|
+
|
|
274
|
+
The list is redrawn in place when stderr is a terminal that can move its
|
|
275
|
+
cursor: the cursor climbs over the frame drawn last and erases everything
|
|
276
|
+
under it, since the filter makes the list longer or shorter. The climb counts
|
|
277
|
+
lines, so the frame fits the screen: each row is cut to the terminal's width,
|
|
278
|
+
and the rows shown are a window as tall as the screen that follows the
|
|
279
|
+
highlight. On `TERM=dumb`,
|
|
280
|
+
or a stderr that is not a terminal, the list is printed once, each move
|
|
281
|
+
prints the row it lands on, and each change to the filter prints the rows it
|
|
282
|
+
leaves, so nothing writes a cursor code where it would show up as text.
|
|
283
|
+
|
|
284
|
+
A query that is exactly one worktree's name, branch or path is that worktree
|
|
285
|
+
alone. `gw list one` beside `one-more` is not a question, and neither is
|
|
286
|
+
`gw remove "$(gw list two --json | jq -r '.worktrees[0].path')"`.
|
|
287
|
+
`gw remove NAME` uses exact names, with an exact path resolving one worktree.
|
|
288
|
+
It takes `gw prune`'s rules for that one: nonterminal input, `--json` and
|
|
289
|
+
`--table` print the match's rows and remove nothing, so an assessment never
|
|
290
|
+
asks and never refuses. With `--yes`, several name matches need a picker or a
|
|
291
|
+
nonterminal refusal. It has no `--only`: one target has one verdict.
|
|
292
|
+
|
|
293
|
+
Dropping `fzf` is less code, not more. It removes the spawn and the fallback
|
|
294
|
+
branch a machine without `fzf` would otherwise need.
|
|
295
|
+
|
|
296
|
+
Matching is substring first, then subsequence, which is the one idea worth
|
|
297
|
+
taking from `fzf`: the query's letters appearing in order. Substring looks at
|
|
298
|
+
the branch and the path, which holds the worktree's name. Subsequence looks
|
|
299
|
+
at the branch and the name, never the whole path, where `.worktrees` hands a
|
|
300
|
+
`t`, a `w` and an `o` to any query. About twenty lines, `difflib` not
|
|
301
|
+
required.
|
|
302
|
+
|
|
303
|
+
```
|
|
304
|
+
'parse' -> ['fix-parser']
|
|
305
|
+
'tst' -> ['add-tests', 'try-something']
|
|
306
|
+
'ruff' -> ['renovate/ruff-0.x']
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Two rules about when the list appears:
|
|
310
|
+
|
|
311
|
+
- A query that narrows to one takes it outright, with no prompt at all. No
|
|
312
|
+
query asks however many there are, because being moved without being asked
|
|
313
|
+
is not what `gw list` with no argument means.
|
|
314
|
+
- Without a terminal, listing prints metadata for all matching worktrees.
|
|
315
|
+
Removal pickers refuse at exit 3 rather than blocking.
|
|
316
|
+
|
|
317
|
+
Three more about what is in the list at all:
|
|
318
|
+
|
|
319
|
+
- The main checkout is a destination. It is the one that is always there and
|
|
320
|
+
the one a finished branch leaves you in, so leaving it out leaves out the
|
|
321
|
+
only answer that is always right. `main` finds it whatever branch it stands
|
|
322
|
+
on, because its label carries the word, once.
|
|
323
|
+
- In `gw list`, a linked worktree you are standing in is shown and never
|
|
324
|
+
offered. It carries a `*` in the first column and the highlight skips it,
|
|
325
|
+
because picking it is the one answer that takes you nowhere. Leaving it
|
|
326
|
+
out of the list entirely is worse: the list then shows fewer rows than
|
|
327
|
+
`git worktree list` does, and reads as though something went missing
|
|
328
|
+
rather than as where you already are. The main checkout is offered even
|
|
329
|
+
from inside it, with a `*` after its name, since from a subdirectory it is
|
|
330
|
+
the way back to the top.
|
|
331
|
+
- In `gw remove`, the main checkout is shown dimmed and never highlighted,
|
|
332
|
+
because `git worktree remove` refuses it whatever flag it is given, and
|
|
333
|
+
the highlight starts on the worktree you are standing in. `gw prune` keeps the main
|
|
334
|
+
checkout in its list for the same reason, and never proposes it.
|
|
335
|
+
|
|
336
|
+
`--json` and `--table` answer the same question without any of this, and an
|
|
337
|
+
agent uses those.
|
|
338
|
+
|
|
339
|
+
## One row per command, under every name it answers to
|
|
340
|
+
|
|
341
|
+
`_COMMANDS` in `cli.py` holds the top-level commands; `_BRANCH_COMMANDS`
|
|
342
|
+
holds `branch status` and `branch prune`. `command_rows()` lists the
|
|
343
|
+
executable commands for help and completion checks. A row carries the function, the flags,
|
|
344
|
+
the one-line description, the argument shape, the shorthands, the shell
|
|
345
|
+
plugin's shortcuts and whether the command changes the caller's directory.
|
|
346
|
+
`gw p` and `gw prune` reach the same function because that row says so.
|
|
347
|
+
`gw --help` and bare `gw` print this registry, each shortcut indented under
|
|
348
|
+
its command, and the shell plugin's release line, and nothing else;
|
|
349
|
+
`gw --explain` prints every git command the program can run. Any other
|
|
350
|
+
word that is not a command is a usage error at exit 2 that suggests
|
|
351
|
+
`gw list WORD`, so a worktree name never competes with a shorthand. `gw list
|
|
352
|
+
[QUERY]` uses the picker on terminal input; without a terminal, or with
|
|
353
|
+
`--json` or `--table`, it prints matching metadata. `gw l` is `gw list`, and
|
|
354
|
+
`gwl` is its shortcut. `gw select-main`, `gw main` and `gw m` change into the
|
|
355
|
+
worktree with the head branch checked out, and `gwm` is their shortcut. `gwh`, `gw ls` and the help subcommand are absent.
|
|
356
|
+
|
|
357
|
+
A tool's version is asked through the tool's name, so `gw version` and `gw v` are the two spellings and no parser
|
|
358
|
+
carries a `--version` flag.
|
|
359
|
+
|
|
360
|
+
`_canonical()` raises at import when two rows answer to one name. A dict
|
|
361
|
+
comprehension would keep the last one and leave a command reachable under a
|
|
362
|
+
name that runs a different one.
|
|
363
|
+
|
|
364
|
+
A shorthand is for typing, so it is short and it is not clever: the first
|
|
365
|
+
letters of the word, or the two-letter name the same job has in git and in a
|
|
366
|
+
shell. `rm` means what it means everywhere else.
|
|
367
|
+
|
|
368
|
+
## Colour is a property of the stream, not of the program
|
|
369
|
+
|
|
370
|
+
`render.py` holds both halves of it: the codes, and a table whose columns line
|
|
371
|
+
up. `render.setup()` runs once per invocation and decides per stream.
|
|
372
|
+
|
|
373
|
+
Padding runs on the text and painting after it. The other order counts an
|
|
374
|
+
escape sequence as width, and every column under a coloured cell sits crooked
|
|
375
|
+
by exactly the length of the code.
|
|
376
|
+
|
|
377
|
+
stdout carries the path `cd $(gw add x)` reads and the JSON `jq` parses, so a
|
|
378
|
+
redirect, a pipe, a non-empty `NO_COLOR`, or `TERM=dumb` mean the bytes go out
|
|
379
|
+
as they would have without the module. `NO_COLOR=` is not a request to turn it
|
|
380
|
+
off: that is the no-color.org rule, and it is why `supported` tests the value
|
|
381
|
+
and not the key. `--json` and `gw list --table` are never painted at all, even
|
|
382
|
+
on a terminal: both are what a script reads. The colour is applied at the
|
|
383
|
+
call site that formats a table, and neither path passes a code to one.
|
|
384
|
+
|
|
385
|
+
`progress.py` draws a spinner on stderr and one line per running thread
|
|
386
|
+
saying what it is checking, while `gw sync`, `gw prune`, `gw remove`,
|
|
387
|
+
`gw branch status` and `gw branch prune` assess or mutate. A thread's line
|
|
388
|
+
goes when the thread ends, and every line is cut to the terminal width so
|
|
389
|
+
the redraw can count its rows. It runs only when stderr is a terminal that
|
|
390
|
+
can clear a line, and never under `-q` or `-v`, since the verbose log writes
|
|
391
|
+
to the lines it redraws. Anything else printed on stderr while it spins goes
|
|
392
|
+
through `progress.line`, which clears the spinner first.
|
|
393
|
+
|
|
394
|
+
Every message on stderr goes through `render.fail`, `render.warn` or
|
|
395
|
+
`render.note`, a usage error and a cancelled picker included. On a terminal
|
|
396
|
+
each leads with its symbol, `✗`, `!` or `→`, and its first line makes flags
|
|
397
|
+
and quoted commands bold, paths dim and shas yellow. A path is a word that
|
|
398
|
+
starts with `/`, `~/`, `./` or `../`, taken whole, so a directory named `-x`
|
|
399
|
+
is not a flag and a uuid inside one is not a sha. A failure prints every line
|
|
400
|
+
red; a warning or a note dims the lines after its first.
|
|
401
|
+
|
|
402
|
+
A branch name is wrapped in `render.branch` and a ref such as `origin/main` in
|
|
403
|
+
`render.ref` where the message is built, since no pattern tells a branch from
|
|
404
|
+
prose; the passes after leave those alone. A branch is bold magenta wherever
|
|
405
|
+
it prints: a table, the picker, a message, a result line. A prompt is
|
|
406
|
+
`render.ask`, the question bold and the answers it takes dim. The line that
|
|
407
|
+
puts a branch back is `render.restore`, painted the way a table paints a
|
|
408
|
+
branch and a sha, and it pastes the same. Off a terminal it is the words
|
|
409
|
+
alone, so a test or a log reads what the code wrote. `-v` prints each command once it has run, as
|
|
410
|
+
`render.trace` lays it out: the line that pastes back, what it printed,
|
|
411
|
+
indented, its exit code when that is not 0 or is the only answer, then a
|
|
412
|
+
blank line. Printing after the run keeps a command and its answer together
|
|
413
|
+
when eight threads are asking at once.
|
|
414
|
+
|
|
415
|
+
## Sync runs before a command that is due one
|
|
416
|
+
|
|
417
|
+
`gw sync` fetches every remote with `--prune --tags --no-prune-tags`, the
|
|
418
|
+
default first, updates the default remote's HEAD and queries the forge for
|
|
419
|
+
every local branch tip on eight threads. Every other command but
|
|
420
|
+
`gw version`, `gw ci-checks`, `gw fast-forward`, help and completion runs
|
|
421
|
+
the same `sync.run` first when
|
|
422
|
+
`sync.due` says so: the default remote's refs time is null or at least
|
|
423
|
+
`WORKTREES_SYNC_TTL` seconds old, 60 by default. The forge time is not read,
|
|
424
|
+
since a forge that keeps failing would sync before every command. Without a
|
|
425
|
+
default remote nothing syncs first, because sync records nothing there.
|
|
426
|
+
`gw fast-forward` runs `sync.fetch` on every run instead, which fetches the
|
|
427
|
+
default remote and records the refs time.
|
|
428
|
+
|
|
429
|
+
A failed sync before a command is a warning, and the command goes on with
|
|
430
|
+
the evidence it has; quiet and JSON hide the warning. A failed fetch before
|
|
431
|
+
`gw fast-forward` is a refusal. Nothing it prints
|
|
432
|
+
reaches stdout, so `cd $(gw add x)` and `jq` never see it. A TTL that is not
|
|
433
|
+
whole seconds is a usage error at exit 2.
|
|
434
|
+
|
|
435
|
+
`WORKTREES_OFFLINE`, when non-empty, turns sync off everywhere: nothing syncs
|
|
436
|
+
first, and `gw sync` and `gw ci-checks` refuse at exit 3. Every notice that would end
|
|
437
|
+
`Run: gw sync` goes through `sync.hint`, which leaves that off offline,
|
|
438
|
+
since it names a command that refuses there.
|
|
439
|
+
|
|
440
|
+
`gw ci-checks` reads one review and its checks from the forge each time it
|
|
441
|
+
runs and writes nothing, the sync cache included. It never syncs first: its
|
|
442
|
+
answer comes from the forge, not from local evidence.
|
|
443
|
+
|
|
444
|
+
Sync refuses, before fetching, any remote whose refspec writes outside its own
|
|
445
|
+
`refs/remotes/<name>/`, since a mirror refspec with `--prune` deletes local
|
|
446
|
+
branches. Git refusing a moved tag is a warning; any other refused ref fails
|
|
447
|
+
that remote. The fetch runs in the C locale so sync can read which it was. The
|
|
448
|
+
shared `git-worktrees-sync.json` cache in the Git common directory records
|
|
449
|
+
remote name/URL, successful sync times and source-tip forge evidence. Sync
|
|
450
|
+
replaces it atomically. Remote identity changes invalidate it; malformed or
|
|
451
|
+
mismatched evidence is never proof.
|
|
452
|
+
|
|
453
|
+
`sync._FRESH` is 10 minutes. Warnings compare the oldest non-null component
|
|
454
|
+
time, with exactly 10 minutes still fresh. The never-synced line goes to
|
|
455
|
+
stderr under `-q` and `--json` as well, because a caller acting on the
|
|
456
|
+
verdicts needs to hear that no sync stands behind them. Quiet and JSON
|
|
457
|
+
suppress every other warning, the inferred-head notice included; a removal's
|
|
458
|
+
disclosure still repeats it. `gw sync` and `gw version` print the head line.
|
|
459
|
+
JSON carries `lastSync` and `head`. A repository without remotes, the local
|
|
460
|
+
case, has no sync warning.
|
|
461
|
+
|
|
462
|
+
Partial-clone object reads require Git 2.45.1 onward or the maintenance
|
|
463
|
+
cohorts in `repo.require_offline_git`. Lower reported vendor versions refuse;
|
|
464
|
+
full clones keep older Git compatibility. Offline proof uses read-only
|
|
465
|
+
patch-id input and creates no synthetic commits.
|
|
466
|
+
|
|
467
|
+
The per-worktree checks run on eight threads. Mutations remain serial.
|
|
468
|
+
|
|
469
|
+
`gw ci-checks` takes GitHub's review and checks from one `gh pr view` with
|
|
470
|
+
`statusCheckRollup`, so both describe one head and nothing can go stale
|
|
471
|
+
between them. It keeps the newest run per workflow and name, and a run with
|
|
472
|
+
no start time counts as newest, so a queued re-run supersedes the failure it
|
|
473
|
+
repeats. GitLab needs several calls: the pipeline is read from the project
|
|
474
|
+
that ran it, its jobs across every page, and the merge request again
|
|
475
|
+
afterwards, and a change between the two reads is `stale`. A pipeline for
|
|
476
|
+
another SHA is stale unless it is the merged-result pipeline whose parents
|
|
477
|
+
are the current head and the target's tip. `ci.wait` takes its clock and
|
|
478
|
+
sleep as arguments, so its tests run in-process without waiting.
|
|
479
|
+
|
|
480
|
+
## Every git command is one spec
|
|
481
|
+
|
|
482
|
+
The spec is the command as you would type it, with `$name` where a value goes.
|
|
483
|
+
The module reads as the list of commands the program can run, and `--explain`
|
|
484
|
+
prints the specs themselves.
|
|
485
|
+
|
|
486
|
+
```python
|
|
487
|
+
@git("merge-base --is-ancestor $ref $head", ok=(0, 1))
|
|
488
|
+
def is_ancestor(ref, head): ...
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
@git("--no-optional-locks status --porcelain --ignored=matching")
|
|
492
|
+
def ignored_paths(): ...
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
@git("worktree remove -- $path", mutates=True)
|
|
496
|
+
def worktree_remove(path): ...
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
`shlex.split` runs once, at decoration time, on the literal spec. Only then is
|
|
500
|
+
each token scanned for a placeholder. That ordering is the whole safety
|
|
501
|
+
property: the splitting is over before any value is seen, so a branch named
|
|
502
|
+
`$(id)`, `a"b` or `has space` lands as exactly one argv element. git accepts
|
|
503
|
+
the first two as branch names, and there is a test that creates them.
|
|
504
|
+
|
|
505
|
+
`$` rather than `{}`, because git's revision syntax is full of braces:
|
|
506
|
+
`^{tree}`, `^{commit}` and `@{upstream}` pass through untouched. `$$` is a
|
|
507
|
+
literal `$`, and so is a `$` with no name after it.
|
|
508
|
+
|
|
509
|
+
Three ways to place a value: `$name` anywhere, including inside a token so
|
|
510
|
+
`--format=$fmt` stays one element; `$*name` splats a list at that position;
|
|
511
|
+
and anything the body returns is appended as a tail, for arguments with no
|
|
512
|
+
fixed place. Names bind from `inspect.signature`, so there is no second
|
|
513
|
+
mapping to keep in step, and a spec naming a parameter the function does not
|
|
514
|
+
have raises `NameError` at import.
|
|
515
|
+
|
|
516
|
+
The form catches its own bugs. `-C $path status --porcelain
|
|
517
|
+
--no-optional-locks` is wrong, because `--no-optional-locks` is a git global
|
|
518
|
+
and belongs before the subcommand. That is visible in a spec and invisible in
|
|
519
|
+
a tuple.
|
|
520
|
+
|
|
521
|
+
A command's name says what the caller gets, echoing the git command where the
|
|
522
|
+
two can agree. `worktree_list`, `worktree_prune` and `worktree_remove` read as
|
|
523
|
+
the subcommands they are; `is_ancestor` beats `merge_base`, because
|
|
524
|
+
`merge-base --is-ancestor` answers a yes/no question and that answer is what
|
|
525
|
+
the caller wants.
|
|
526
|
+
|
|
527
|
+
A spec with `ok=` wide enough to swallow an error is a spec that has to be
|
|
528
|
+
tested on what it returns rather than on its exit code. `upstream_of` takes
|
|
529
|
+
`ok=(0, 1, 128)`, so a typo in one of its flags exits 128, reads as "no
|
|
530
|
+
upstream", and turns every branch into `unknown` with nothing failing.
|
|
531
|
+
|
|
532
|
+
The network calls belong to sync. Their results distinguish failed
|
|
533
|
+
refs refresh from partial forge refresh; assessments retain usable local
|
|
534
|
+
proof without asking the network. The cache records each successful
|
|
535
|
+
component's time separately.
|
|
536
|
+
|
|
537
|
+
One `git status --porcelain --ignored=matching` answers both questions a
|
|
538
|
+
worktree is asked. It is a strict superset of plain `--porcelain`, so `dirty`
|
|
539
|
+
is "a line that does not start with `!! `" and `ignored` is the rest. Asking
|
|
540
|
+
both ways was 18 of an assessment's 35 calls over nine worktrees.
|
|
541
|
+
|
|
542
|
+
`guard()` runs on the resolved argv inside the wrapper, not at declaration, so
|
|
543
|
+
no call site can assemble its way past it. `reset --hard`, a forced `checkout`
|
|
544
|
+
or `switch`, `clean -f`, a bare `push --force`, `worktree remove --force`,
|
|
545
|
+
`branch -D` and an `update-ref` delete that names no full sha are refused
|
|
546
|
+
absolutely. There is no flag, and `--yes` least of all.
|
|
547
|
+
|
|
548
|
+
Those seven are `RULES`, a tuple, each row carrying the name `--explain`
|
|
549
|
+
prints, the clause the refusal ends with, and the test. The footer `--explain`
|
|
550
|
+
prints is built from it. A rule written in one place and described in another
|
|
551
|
+
is a rule that goes quiet: the hand-written footer fell a rule behind the
|
|
552
|
+
moment `update-ref` was added, and nothing failed.
|
|
553
|
+
|
|
554
|
+
`verdicts.py` declares no mutating command. A read-only command may not call
|
|
555
|
+
one, the fetch and `set-head` of the sync it runs first aside, which write
|
|
556
|
+
remote-tracking refs and the remote's new tags: a test reads the verbose log
|
|
557
|
+
and asserts it.
|
|
558
|
+
|
|
559
|
+
## Verdicts and deletion are separate
|
|
560
|
+
|
|
561
|
+
`merged.branch_proof` checks matching cached forge proof, first-parent
|
|
562
|
+
membership, local completion proof, then remaining commits or absent evidence.
|
|
563
|
+
The verdicts are `remove`, `empty`, `keep` and `unknown`. A branch merged by
|
|
564
|
+
fast-forward without forge proof is `empty`, because Git cannot distinguish
|
|
565
|
+
it from an unused branch. First-parent history belongs to the assessed head,
|
|
566
|
+
not a divergent local counterpart.
|
|
567
|
+
|
|
568
|
+
Content proof compares changed paths, modes and deletions against the head.
|
|
569
|
+
It cannot settle a stacked branch whose intermediate content the head later
|
|
570
|
+
edited. Cached forge proof verifies source tip, source repository, target
|
|
571
|
+
branch and merge ancestry. Closed unmerged requests are never proof.
|
|
572
|
+
|
|
573
|
+
`eligible` combines proof, protections and `--delete` permissions.
|
|
574
|
+
`prune.removable()` selects only eligible rows. `main`, `master` and the
|
|
575
|
+
head branch are protected. Locked or dirty worktrees, untracked files,
|
|
576
|
+
initialized submodules and a submodule store left by `deinit` block removal;
|
|
577
|
+
`git worktree remove` refuses each. A locked worktree whose directory is away
|
|
578
|
+
is assessed from its record. Ignored paths, empty branches and
|
|
579
|
+
matching stashes require their own permission. `--yes` grants none.
|
|
580
|
+
`gw prune` also protects the current worktree; `gw remove` needs a second terminal
|
|
581
|
+
confirmation for it. `--keep-branch` retains the branch and its stashes,
|
|
582
|
+
needs no completion proof for an attached checkout, and combines only with
|
|
583
|
+
`--delete ignored-files`.
|
|
584
|
+
|
|
585
|
+
The removal snapshot pins the branch and head SHAs, exact path, ignored
|
|
586
|
+
paths and stash identities. Recheck after confirmation precedes plain
|
|
587
|
+
worktree removal, full-SHA ref deletion and approved stash drops. Ignored
|
|
588
|
+
paths are what an ignore pattern names, so a matched directory is one entry;
|
|
589
|
+
the snapshot is a path listing, not a recursive content fingerprint, and a
|
|
590
|
+
file created inside a listed directory after assessment goes with it. The
|
|
591
|
+
disclosure, the protection's count and the JSON `ignored` field cut each
|
|
592
|
+
listed path to its first component below the `.gitignore` whose pattern
|
|
593
|
+
matched it, found with `git check-ignore -v`, and the disclosure quotes a
|
|
594
|
+
path holding a character that would not print, as `git status` does. A pattern from
|
|
595
|
+
`.git/info/exclude` or `core.excludesFile` counts from the top level, so
|
|
596
|
+
`build/out/a.log` reads as `build/`. Stash drops verify SHA and repair a
|
|
597
|
+
concurrent wrong-entry drop using the exact subject. Restoration remains
|
|
598
|
+
possible until Git garbage collection prunes the unreachable stash commit.
|
|
599
|
+
Report checkout, branch and stash outcomes separately after partial failure.
|
|
600
|
+
|
|
601
|
+
Branch assessment and deletion are documented in
|
|
602
|
+
[branch status](docs/commands/branch-status.md) and
|
|
603
|
+
[branch prune](docs/commands/branch-prune.md). Checked-out branches appear
|
|
604
|
+
only as worktrees; `gw branch prune NAME` naming one keeps it and exits 3. Every JSON result is an object with `head` and `lastSync`;
|
|
605
|
+
`gw list --json` stores navigation rows in `worktrees`.
|
|
606
|
+
|
|
607
|
+
## Reproduce a failure before asserting its fix
|
|
608
|
+
|
|
609
|
+
Two holes in git are the reason this exists: a squash merge inverts
|
|
610
|
+
`git branch -d`, and `git worktree remove` deletes ignored files at exit 0
|
|
611
|
+
without a word. Each has a test that reproduces the raw git behaviour and a
|
|
612
|
+
test that asserts the fix. A suite that only asserts the fix passes on unfixed
|
|
613
|
+
code forever.
|
|
614
|
+
|
|
615
|
+
The fixture needs no global git config, no signing key, no forge and no
|
|
616
|
+
network. `GIT_CONFIG_GLOBAL` carries that: without it git still reads
|
|
617
|
+
`$HOME/.gitconfig`, and setting `HOME` alone still leaves
|
|
618
|
+
`$XDG_CONFIG_HOME/git/config`. `WORKTREES_OFFLINE=1` in `conftest.ENV` stops
|
|
619
|
+
a command syncing first, which would fetch a remote at `github.com` for
|
|
620
|
+
real. `Network.env` clears it for the fake network, and `conftest.online`
|
|
621
|
+
for a remote on disk.
|