voohook 0.1.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.
- voohook-0.1.0/LICENSE +21 -0
- voohook-0.1.0/PKG-INFO +184 -0
- voohook-0.1.0/README.md +167 -0
- voohook-0.1.0/pyproject.toml +42 -0
- voohook-0.1.0/setup.cfg +4 -0
- voohook-0.1.0/src/voohook/__init__.py +4 -0
- voohook-0.1.0/src/voohook/__main__.py +8 -0
- voohook-0.1.0/src/voohook/cli.py +121 -0
- voohook-0.1.0/src/voohook/core/__init__.py +20 -0
- voohook-0.1.0/src/voohook/core/config.py +91 -0
- voohook-0.1.0/src/voohook/core/exitcodes.py +12 -0
- voohook-0.1.0/src/voohook/core/git.py +230 -0
- voohook-0.1.0/src/voohook/core/output.py +23 -0
- voohook-0.1.0/src/voohook/submodule/__init__.py +64 -0
- voohook-0.1.0/src/voohook/submodule/cli.py +167 -0
- voohook-0.1.0/src/voohook/submodule/config.py +192 -0
- voohook-0.1.0/src/voohook/submodule/hook.py +361 -0
- voohook-0.1.0/src/voohook/version/__init__.py +54 -0
- voohook-0.1.0/src/voohook/version/cli.py +181 -0
- voohook-0.1.0/src/voohook/version/config.py +332 -0
- voohook-0.1.0/src/voohook/version/flow.py +115 -0
- voohook-0.1.0/src/voohook/version/hook.py +382 -0
- voohook-0.1.0/src/voohook/version/versions.py +114 -0
- voohook-0.1.0/src/voohook/version/yamlfile.py +147 -0
- voohook-0.1.0/src/voohook/version/yamlpath.py +155 -0
- voohook-0.1.0/src/voohook.egg-info/PKG-INFO +184 -0
- voohook-0.1.0/src/voohook.egg-info/SOURCES.txt +29 -0
- voohook-0.1.0/src/voohook.egg-info/dependency_links.txt +1 -0
- voohook-0.1.0/src/voohook.egg-info/entry_points.txt +2 -0
- voohook-0.1.0/src/voohook.egg-info/requires.txt +5 -0
- voohook-0.1.0/src/voohook.egg-info/top_level.txt +1 -0
voohook-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrei Zakhrebetkov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
voohook-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: voohook
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Git hooks that keep your version and your submodule pins honest
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/AndrewZakh/voohook
|
|
7
|
+
Project-URL: Issues, https://github.com/AndrewZakh/voohook/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/AndrewZakh/voohook/releases
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: PyYAML>=5.4
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
15
|
+
Requires-Dist: ruff>=0.8; extra == "dev"
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# voohook
|
|
19
|
+
|
|
20
|
+

|
|
21
|
+
|
|
22
|
+
[](https://github.com/AndrewZakh/voohook/tags)
|
|
23
|
+
[](https://github.com/AndrewZakh/voohook/actions/workflows/ci.yml)
|
|
24
|
+
|
|
25
|
+
**Git hooks that keep your version and your submodule pins honest.**
|
|
26
|
+
|
|
27
|
+
> Work in progress: voohook is being assembled from
|
|
28
|
+
> [auto-version-hook](https://github.com/AndrewZakh/auto-version-hook) and
|
|
29
|
+
> [auto-submodule](https://github.com/AndrewZakh/auto-submodule).
|
|
30
|
+
> The migration registry lives in [.jearless/tasks.yml](.jearless/tasks.yml).
|
|
31
|
+
|
|
32
|
+
voohook is a pair of Python git hooks (pre-commit + pre-push) with a shared
|
|
33
|
+
CI validator, built around one idea: `env.yml` at the repository root is the
|
|
34
|
+
single source of truth for *what this repo is* — its version and the exact
|
|
35
|
+
commits its submodules are pinned to. The hooks make sure the truth in the
|
|
36
|
+
file and the truth in git never drift apart.
|
|
37
|
+
|
|
38
|
+
The **v** is for *version* — and the rest of it is the sound the owl makes.
|
|
39
|
+
voohook lives in the same forest as [jearless](https://github.com/AndrewZakh/jearless):
|
|
40
|
+
tree trunks of projects, branches, and small nocturnal tooling.
|
|
41
|
+
|
|
42
|
+
It is the merger of two projects:
|
|
43
|
+
[auto-version-hook](https://github.com/AndrewZakh/auto-version-hook) (branch-driven
|
|
44
|
+
semver bumps, declarative `branch_flow`) and
|
|
45
|
+
[auto-submodule](https://github.com/AndrewZakh/auto-submodule) (submodule pin
|
|
46
|
+
enforcement, dangling-commit pre-push). One stack (Python + PyYAML, nothing else),
|
|
47
|
+
one config file, one install script, one set of exit codes.
|
|
48
|
+
|
|
49
|
+
## Two hooks, one file
|
|
50
|
+
|
|
51
|
+
| | `voohook version` | `voohook submodule` |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| Stage | pre-commit | pre-commit + pre-push |
|
|
54
|
+
| Reads | branch name, `origin/<target>`, `env.yml` | `env.yml` pins, git index, `origin/<lookup_branch>` |
|
|
55
|
+
| Writes | **yes** — bumps the version, `git add`s it | **never** — read-only verdicts |
|
|
56
|
+
| Blocks when | branch name matches no `branch_flow` class | pinned SHA ≠ submodule commit in the index |
|
|
57
|
+
| CI mode | `voohook version --check` | `voohook submodule --check` |
|
|
58
|
+
| Extra | | `voohook submodule --push` — no dangling submodule commits reach the remote |
|
|
59
|
+
|
|
60
|
+
Run both validators in one CI job: `voohook --check` — exit 0 only when both pass.
|
|
61
|
+
|
|
62
|
+
The install target is the umbrella: `.git/hooks/pre-commit` runs
|
|
63
|
+
`exec voohook pre-commit "$@"`, `.git/hooks/pre-push` runs
|
|
64
|
+
`exec voohook pre-push "$@"` — and the scripts never need rewriting: domains
|
|
65
|
+
run in a fixed order (version writes first, submodule verdicts see the final
|
|
66
|
+
index), the first nonzero exit wins, and a domain that is not ported yet
|
|
67
|
+
reports and skips.
|
|
68
|
+
|
|
69
|
+
## Quick start
|
|
70
|
+
|
|
71
|
+
Requires Python 3.11+.
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
pip install git+https://github.com/AndrewZakh/voohook.git
|
|
75
|
+
./scripts/install.sh # installs .git/hooks/pre-commit and .git/hooks/pre-push
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Then:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
$ git checkout -b feature/login
|
|
82
|
+
$ echo done >> app.py && git add app.py
|
|
83
|
+
$ git commit -m "login form"
|
|
84
|
+
voohook: feature/login [feature -> origin/main]: v1.2.3 -> v1.3.3 in env.yml
|
|
85
|
+
voohook: libs/api-clients — unchanged, staying on 12351adf (as in master)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
With the [pre-commit framework](https://pre-commit.com):
|
|
89
|
+
|
|
90
|
+
```yaml
|
|
91
|
+
repos:
|
|
92
|
+
- repo: https://github.com/AndrewZakh/voohook
|
|
93
|
+
rev: latest
|
|
94
|
+
hooks:
|
|
95
|
+
- id: voohook
|
|
96
|
+
- id: voohook-push
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Philosophy
|
|
100
|
+
|
|
101
|
+
Four principles, inherited unchanged from the parent projects:
|
|
102
|
+
|
|
103
|
+
1. **The version is a declared process, not commit-message archaeology.**
|
|
104
|
+
The bump kind comes from branch policy declared up front (`branch_flow`);
|
|
105
|
+
everyone sees the next version before the commit exists (`--dry-run`).
|
|
106
|
+
2. **Semver-compliant by construction.** Regex-driven increments, the base
|
|
107
|
+
never regresses, pre-release decorations survive (`v1.2.3-rc1` → `v1.2.4-rc1`).
|
|
108
|
+
3. **Pins and pointers travel together.** Switching a submodule is always two
|
|
109
|
+
changes in one commit: the submodule itself and the `env.yml` pin.
|
|
110
|
+
4. **Defense in depth: hook + CI.** Local hooks are cheap prevention and can
|
|
111
|
+
be bypassed (`--no-verify`, server-side Merge button); `--check` is the
|
|
112
|
+
independent server-side watchdog that always is strict.
|
|
113
|
+
|
|
114
|
+
## Configuration
|
|
115
|
+
|
|
116
|
+
Everything lives in `env.yml` (submodule pins) and `version-hook.yml`
|
|
117
|
+
(branch flow) — same files, same fields as the parent projects; existing
|
|
118
|
+
configs work unchanged. Whether a unified `voohook.yml` appears later as an
|
|
119
|
+
additive option is tracked as a task in [.jearless/tasks.yml](.jearless/tasks.yml) —
|
|
120
|
+
no TODOs here, the hedgehog keeps the registry.
|
|
121
|
+
|
|
122
|
+
```yaml
|
|
123
|
+
# env.yml
|
|
124
|
+
version: v1.3.3
|
|
125
|
+
submodules:
|
|
126
|
+
- folder: libs/api-clients
|
|
127
|
+
commit_sha: "12351adf"
|
|
128
|
+
lookup_branch: master
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```yaml
|
|
132
|
+
# version-hook.yml — trunk-based default works with zero config
|
|
133
|
+
branch_flow:
|
|
134
|
+
- name: main
|
|
135
|
+
regex: '^(master|main)$'
|
|
136
|
+
protected: true
|
|
137
|
+
policy: keep
|
|
138
|
+
- name: feature
|
|
139
|
+
regex: '^feat(ure)?'
|
|
140
|
+
target: main
|
|
141
|
+
policy: increment
|
|
142
|
+
bump: minor
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Eyeball your branch lifecycle: `voohook version --graph` (Mermaid flowchart).
|
|
146
|
+
|
|
147
|
+
## CI validator
|
|
148
|
+
|
|
149
|
+
Ready-made jobs to copy into the target repository:
|
|
150
|
+
|
|
151
|
+
- [ci/github-actions-version-check.example.yml](ci/github-actions-version-check.example.yml)
|
|
152
|
+
- [ci/github-actions-submodule-check.example.yml](ci/github-actions-submodule-check.example.yml)
|
|
153
|
+
- [ci/gitlab-ci-version-check.example.yml](ci/gitlab-ci-version-check.example.yml)
|
|
154
|
+
- [ci/gitlab-ci-submodule-check.example.yml](ci/gitlab-ci-submodule-check.example.yml)
|
|
155
|
+
|
|
156
|
+
Exit codes everywhere: `0` — fine (warnings allowed); `1` — blocked
|
|
157
|
+
(the hook would rewrite / the pin diverged / unknown branch); `2` — config problems.
|
|
158
|
+
|
|
159
|
+
## Migrating from the parent projects
|
|
160
|
+
|
|
161
|
+
- `auto-version-hook` users: config files and `branch_flow` semantics are
|
|
162
|
+
unchanged — swap the installed command (`auto-version-hook …` → `voohook version …`)
|
|
163
|
+
and the pre-commit repo URL. The old repository stays archived and clonable,
|
|
164
|
+
so existing `rev: latest` hooks keep working until you switch.
|
|
165
|
+
- `auto-submodule` users: `submodule-hook …` → `voohook submodule …`,
|
|
166
|
+
`--push` and `--check` unchanged.
|
|
167
|
+
|
|
168
|
+
## Development
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
python3 -m venv .venv && . .venv/bin/activate
|
|
172
|
+
pip install -e ".[dev]"
|
|
173
|
+
pytest # throwaway git repos, real submodules, end to end
|
|
174
|
+
./scripts/install-dev-hooks.sh
|
|
175
|
+
./scripts/demo.sh # live sandbox with two "developers"
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
The repository eats its own dog food: the version in [env.yml](env.yml) is
|
|
179
|
+
bumped by `voohook version` itself. Tasks are tracked in
|
|
180
|
+
[.jearless/tasks.yml](.jearless/tasks.yml).
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
Licensed under the [MIT license](LICENSE).
|
voohook-0.1.0/README.md
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# voohook
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
[](https://github.com/AndrewZakh/voohook/tags)
|
|
6
|
+
[](https://github.com/AndrewZakh/voohook/actions/workflows/ci.yml)
|
|
7
|
+
|
|
8
|
+
**Git hooks that keep your version and your submodule pins honest.**
|
|
9
|
+
|
|
10
|
+
> Work in progress: voohook is being assembled from
|
|
11
|
+
> [auto-version-hook](https://github.com/AndrewZakh/auto-version-hook) and
|
|
12
|
+
> [auto-submodule](https://github.com/AndrewZakh/auto-submodule).
|
|
13
|
+
> The migration registry lives in [.jearless/tasks.yml](.jearless/tasks.yml).
|
|
14
|
+
|
|
15
|
+
voohook is a pair of Python git hooks (pre-commit + pre-push) with a shared
|
|
16
|
+
CI validator, built around one idea: `env.yml` at the repository root is the
|
|
17
|
+
single source of truth for *what this repo is* — its version and the exact
|
|
18
|
+
commits its submodules are pinned to. The hooks make sure the truth in the
|
|
19
|
+
file and the truth in git never drift apart.
|
|
20
|
+
|
|
21
|
+
The **v** is for *version* — and the rest of it is the sound the owl makes.
|
|
22
|
+
voohook lives in the same forest as [jearless](https://github.com/AndrewZakh/jearless):
|
|
23
|
+
tree trunks of projects, branches, and small nocturnal tooling.
|
|
24
|
+
|
|
25
|
+
It is the merger of two projects:
|
|
26
|
+
[auto-version-hook](https://github.com/AndrewZakh/auto-version-hook) (branch-driven
|
|
27
|
+
semver bumps, declarative `branch_flow`) and
|
|
28
|
+
[auto-submodule](https://github.com/AndrewZakh/auto-submodule) (submodule pin
|
|
29
|
+
enforcement, dangling-commit pre-push). One stack (Python + PyYAML, nothing else),
|
|
30
|
+
one config file, one install script, one set of exit codes.
|
|
31
|
+
|
|
32
|
+
## Two hooks, one file
|
|
33
|
+
|
|
34
|
+
| | `voohook version` | `voohook submodule` |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| Stage | pre-commit | pre-commit + pre-push |
|
|
37
|
+
| Reads | branch name, `origin/<target>`, `env.yml` | `env.yml` pins, git index, `origin/<lookup_branch>` |
|
|
38
|
+
| Writes | **yes** — bumps the version, `git add`s it | **never** — read-only verdicts |
|
|
39
|
+
| Blocks when | branch name matches no `branch_flow` class | pinned SHA ≠ submodule commit in the index |
|
|
40
|
+
| CI mode | `voohook version --check` | `voohook submodule --check` |
|
|
41
|
+
| Extra | | `voohook submodule --push` — no dangling submodule commits reach the remote |
|
|
42
|
+
|
|
43
|
+
Run both validators in one CI job: `voohook --check` — exit 0 only when both pass.
|
|
44
|
+
|
|
45
|
+
The install target is the umbrella: `.git/hooks/pre-commit` runs
|
|
46
|
+
`exec voohook pre-commit "$@"`, `.git/hooks/pre-push` runs
|
|
47
|
+
`exec voohook pre-push "$@"` — and the scripts never need rewriting: domains
|
|
48
|
+
run in a fixed order (version writes first, submodule verdicts see the final
|
|
49
|
+
index), the first nonzero exit wins, and a domain that is not ported yet
|
|
50
|
+
reports and skips.
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
Requires Python 3.11+.
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
pip install git+https://github.com/AndrewZakh/voohook.git
|
|
58
|
+
./scripts/install.sh # installs .git/hooks/pre-commit and .git/hooks/pre-push
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Then:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
$ git checkout -b feature/login
|
|
65
|
+
$ echo done >> app.py && git add app.py
|
|
66
|
+
$ git commit -m "login form"
|
|
67
|
+
voohook: feature/login [feature -> origin/main]: v1.2.3 -> v1.3.3 in env.yml
|
|
68
|
+
voohook: libs/api-clients — unchanged, staying on 12351adf (as in master)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
With the [pre-commit framework](https://pre-commit.com):
|
|
72
|
+
|
|
73
|
+
```yaml
|
|
74
|
+
repos:
|
|
75
|
+
- repo: https://github.com/AndrewZakh/voohook
|
|
76
|
+
rev: latest
|
|
77
|
+
hooks:
|
|
78
|
+
- id: voohook
|
|
79
|
+
- id: voohook-push
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Philosophy
|
|
83
|
+
|
|
84
|
+
Four principles, inherited unchanged from the parent projects:
|
|
85
|
+
|
|
86
|
+
1. **The version is a declared process, not commit-message archaeology.**
|
|
87
|
+
The bump kind comes from branch policy declared up front (`branch_flow`);
|
|
88
|
+
everyone sees the next version before the commit exists (`--dry-run`).
|
|
89
|
+
2. **Semver-compliant by construction.** Regex-driven increments, the base
|
|
90
|
+
never regresses, pre-release decorations survive (`v1.2.3-rc1` → `v1.2.4-rc1`).
|
|
91
|
+
3. **Pins and pointers travel together.** Switching a submodule is always two
|
|
92
|
+
changes in one commit: the submodule itself and the `env.yml` pin.
|
|
93
|
+
4. **Defense in depth: hook + CI.** Local hooks are cheap prevention and can
|
|
94
|
+
be bypassed (`--no-verify`, server-side Merge button); `--check` is the
|
|
95
|
+
independent server-side watchdog that always is strict.
|
|
96
|
+
|
|
97
|
+
## Configuration
|
|
98
|
+
|
|
99
|
+
Everything lives in `env.yml` (submodule pins) and `version-hook.yml`
|
|
100
|
+
(branch flow) — same files, same fields as the parent projects; existing
|
|
101
|
+
configs work unchanged. Whether a unified `voohook.yml` appears later as an
|
|
102
|
+
additive option is tracked as a task in [.jearless/tasks.yml](.jearless/tasks.yml) —
|
|
103
|
+
no TODOs here, the hedgehog keeps the registry.
|
|
104
|
+
|
|
105
|
+
```yaml
|
|
106
|
+
# env.yml
|
|
107
|
+
version: v1.3.3
|
|
108
|
+
submodules:
|
|
109
|
+
- folder: libs/api-clients
|
|
110
|
+
commit_sha: "12351adf"
|
|
111
|
+
lookup_branch: master
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```yaml
|
|
115
|
+
# version-hook.yml — trunk-based default works with zero config
|
|
116
|
+
branch_flow:
|
|
117
|
+
- name: main
|
|
118
|
+
regex: '^(master|main)$'
|
|
119
|
+
protected: true
|
|
120
|
+
policy: keep
|
|
121
|
+
- name: feature
|
|
122
|
+
regex: '^feat(ure)?'
|
|
123
|
+
target: main
|
|
124
|
+
policy: increment
|
|
125
|
+
bump: minor
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Eyeball your branch lifecycle: `voohook version --graph` (Mermaid flowchart).
|
|
129
|
+
|
|
130
|
+
## CI validator
|
|
131
|
+
|
|
132
|
+
Ready-made jobs to copy into the target repository:
|
|
133
|
+
|
|
134
|
+
- [ci/github-actions-version-check.example.yml](ci/github-actions-version-check.example.yml)
|
|
135
|
+
- [ci/github-actions-submodule-check.example.yml](ci/github-actions-submodule-check.example.yml)
|
|
136
|
+
- [ci/gitlab-ci-version-check.example.yml](ci/gitlab-ci-version-check.example.yml)
|
|
137
|
+
- [ci/gitlab-ci-submodule-check.example.yml](ci/gitlab-ci-submodule-check.example.yml)
|
|
138
|
+
|
|
139
|
+
Exit codes everywhere: `0` — fine (warnings allowed); `1` — blocked
|
|
140
|
+
(the hook would rewrite / the pin diverged / unknown branch); `2` — config problems.
|
|
141
|
+
|
|
142
|
+
## Migrating from the parent projects
|
|
143
|
+
|
|
144
|
+
- `auto-version-hook` users: config files and `branch_flow` semantics are
|
|
145
|
+
unchanged — swap the installed command (`auto-version-hook …` → `voohook version …`)
|
|
146
|
+
and the pre-commit repo URL. The old repository stays archived and clonable,
|
|
147
|
+
so existing `rev: latest` hooks keep working until you switch.
|
|
148
|
+
- `auto-submodule` users: `submodule-hook …` → `voohook submodule …`,
|
|
149
|
+
`--push` and `--check` unchanged.
|
|
150
|
+
|
|
151
|
+
## Development
|
|
152
|
+
|
|
153
|
+
```sh
|
|
154
|
+
python3 -m venv .venv && . .venv/bin/activate
|
|
155
|
+
pip install -e ".[dev]"
|
|
156
|
+
pytest # throwaway git repos, real submodules, end to end
|
|
157
|
+
./scripts/install-dev-hooks.sh
|
|
158
|
+
./scripts/demo.sh # live sandbox with two "developers"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The repository eats its own dog food: the version in [env.yml](env.yml) is
|
|
162
|
+
bumped by `voohook version` itself. Tasks are tracked in
|
|
163
|
+
[.jearless/tasks.yml](.jearless/tasks.yml).
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
|
+
Licensed under the [MIT license](LICENSE).
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "voohook"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Git hooks that keep your version and your submodule pins honest"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"PyYAML>=5.4",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Homepage = "https://github.com/AndrewZakh/voohook"
|
|
19
|
+
Issues = "https://github.com/AndrewZakh/voohook/issues"
|
|
20
|
+
Changelog = "https://github.com/AndrewZakh/voohook/releases"
|
|
21
|
+
|
|
22
|
+
[project.optional-dependencies]
|
|
23
|
+
dev = [
|
|
24
|
+
"pytest>=7",
|
|
25
|
+
"ruff>=0.8",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
voohook = "voohook.cli:main"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.packages.find]
|
|
32
|
+
where = ["src"]
|
|
33
|
+
|
|
34
|
+
[tool.pytest.ini_options]
|
|
35
|
+
testpaths = ["tests"]
|
|
36
|
+
|
|
37
|
+
[tool.ruff]
|
|
38
|
+
target-version = "py311"
|
|
39
|
+
line-length = 100
|
|
40
|
+
|
|
41
|
+
[tool.ruff.lint]
|
|
42
|
+
select = ["E4", "E7", "E9", "F", "I"]
|
voohook-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""voohook command line: `voohook version`, `voohook submodule`,
|
|
2
|
+
the umbrella entries `voohook pre-commit` / `voohook pre-push`,
|
|
3
|
+
and the combined CI validator `voohook --check`.
|
|
4
|
+
|
|
5
|
+
The umbrella is the install target: `.git/hooks/pre-commit` runs
|
|
6
|
+
`exec voohook pre-commit "$@"`, `.git/hooks/pre-push` runs
|
|
7
|
+
`exec voohook pre-push "$@"` — both scripts never need rewriting.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Callable, Optional, Sequence
|
|
14
|
+
|
|
15
|
+
from .core import git as core_git
|
|
16
|
+
from .core.exitcodes import EXIT_CONFIG_ERROR, EXIT_OK
|
|
17
|
+
from .core.output import configure_logging, prefixed
|
|
18
|
+
from .submodule import cli as submodule_cli
|
|
19
|
+
from .submodule import pre_commit as submodule_pre_commit
|
|
20
|
+
from .submodule import pre_push as submodule_pre_push
|
|
21
|
+
from .submodule.config import ConfigError as SubmoduleConfigError
|
|
22
|
+
from .submodule.config import load_config as load_submodule_config
|
|
23
|
+
from .version import cli as version_cli
|
|
24
|
+
from .version import pre_commit as version_pre_commit
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
28
|
+
parser = argparse.ArgumentParser(
|
|
29
|
+
prog="voohook",
|
|
30
|
+
description="Git hooks that keep your version and your submodule pins honest.",
|
|
31
|
+
)
|
|
32
|
+
parser.add_argument(
|
|
33
|
+
"--check",
|
|
34
|
+
action="store_true",
|
|
35
|
+
help="CI validator: run both checks, exit 0 only when both pass",
|
|
36
|
+
)
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"--repo", default=".", help="path inside the target repository (used by --check)"
|
|
39
|
+
)
|
|
40
|
+
parser.add_argument("-v", "--verbose", action="count", default=0, help="debug output")
|
|
41
|
+
parser.add_argument("-q", "--quiet", action="store_true", help="warnings only")
|
|
42
|
+
sub = parser.add_subparsers(dest="command")
|
|
43
|
+
version_parser = sub.add_parser(
|
|
44
|
+
"version", help="branch-driven semver bump (pre-commit)"
|
|
45
|
+
)
|
|
46
|
+
version_cli.add_arguments(version_parser)
|
|
47
|
+
submodule_parser = sub.add_parser(
|
|
48
|
+
"submodule", help="submodule pin enforcement (pre-commit / --push)"
|
|
49
|
+
)
|
|
50
|
+
submodule_cli.add_arguments(submodule_parser)
|
|
51
|
+
sub.add_parser(
|
|
52
|
+
"pre-commit", help="the pre-commit hook: version bump, then submodule verdicts"
|
|
53
|
+
)
|
|
54
|
+
pre_push_parser = sub.add_parser(
|
|
55
|
+
"pre-push", help="the pre-push hook: no dangling submodule commits reach the remote"
|
|
56
|
+
)
|
|
57
|
+
# git passes the destination remote name and URL; accepted, not used
|
|
58
|
+
pre_push_parser.add_argument("push_remote", nargs="*", help=argparse.SUPPRESS)
|
|
59
|
+
return parser
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _first_nonzero(stages: Sequence[Callable[[], int]]) -> int:
|
|
63
|
+
"""Run stages in order; the first nonzero exit wins, the rest are skipped."""
|
|
64
|
+
for stage in stages:
|
|
65
|
+
code = stage()
|
|
66
|
+
if code != EXIT_OK:
|
|
67
|
+
return code
|
|
68
|
+
return EXIT_OK
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
72
|
+
args = build_parser().parse_args(argv)
|
|
73
|
+
configure_logging(quiet=args.quiet, verbose=args.verbose)
|
|
74
|
+
|
|
75
|
+
if args.command == "version":
|
|
76
|
+
return version_cli.run(args)
|
|
77
|
+
if args.command == "submodule":
|
|
78
|
+
return submodule_cli.run(args)
|
|
79
|
+
if args.command == "pre-commit":
|
|
80
|
+
# version first: it writes (bump + git add) — the read-only submodule
|
|
81
|
+
# verdicts must see the index exactly as this commit will carry it
|
|
82
|
+
return _first_nonzero([version_pre_commit, submodule_pre_commit])
|
|
83
|
+
if args.command == "pre-push":
|
|
84
|
+
return _first_nonzero([submodule_pre_push])
|
|
85
|
+
|
|
86
|
+
if args.command is None and not args.check:
|
|
87
|
+
build_parser().print_help()
|
|
88
|
+
return EXIT_CONFIG_ERROR
|
|
89
|
+
|
|
90
|
+
return _combined_check(Path(args.repo))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _combined_check(repo: Path) -> int:
|
|
94
|
+
"""`voohook --check`: the version check, then the submodule check —
|
|
95
|
+
exit 0 only when both pass (the first failure wins, like the umbrella)."""
|
|
96
|
+
try:
|
|
97
|
+
root = core_git.repo_root(repo.resolve())
|
|
98
|
+
except core_git.GitError as exc:
|
|
99
|
+
print(prefixed("voohook", str(exc)), file=sys.stderr)
|
|
100
|
+
return EXIT_CONFIG_ERROR
|
|
101
|
+
|
|
102
|
+
code = version_cli.check_flow(root)
|
|
103
|
+
if code != EXIT_OK:
|
|
104
|
+
return code
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
sub_cfg = load_submodule_config(None, repo_root=root)
|
|
108
|
+
except (SubmoduleConfigError, core_git.GitError) as exc:
|
|
109
|
+
print(prefixed("voohook", str(exc)), file=sys.stderr)
|
|
110
|
+
return EXIT_CONFIG_ERROR
|
|
111
|
+
if sub_cfg is None:
|
|
112
|
+
return EXIT_OK # nothing pinned: the submodule check passes quietly
|
|
113
|
+
from .submodule.hook import Reporter
|
|
114
|
+
|
|
115
|
+
return submodule_cli.pre_commit_flow(
|
|
116
|
+
sub_cfg, repo=root, reporter=Reporter(quiet=True), check=True
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
if __name__ == "__main__": # pragma: no cover
|
|
121
|
+
sys.exit(main())
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Shared plumbing for both subcommands: git wrappers, config discovery
|
|
2
|
+
and validation helpers, exit codes, logging conventions.
|
|
3
|
+
|
|
4
|
+
Nothing hook-specific lives here: no branch_flow, no submodule verdicts —
|
|
5
|
+
policy belongs to voohook.version and voohook.submodule.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .config import ConfigError, find_config, load_section
|
|
9
|
+
from .exitcodes import EXIT_BLOCKED, EXIT_CONFIG_ERROR, EXIT_OK
|
|
10
|
+
from .git import GitError
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"ConfigError",
|
|
14
|
+
"GitError",
|
|
15
|
+
"find_config",
|
|
16
|
+
"load_section",
|
|
17
|
+
"EXIT_OK",
|
|
18
|
+
"EXIT_BLOCKED",
|
|
19
|
+
"EXIT_CONFIG_ERROR",
|
|
20
|
+
]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Shared configuration plumbing.
|
|
2
|
+
|
|
3
|
+
Both subcommands keep their own schema and validation; what they share is
|
|
4
|
+
the mechanics: the ConfigError type, config-file discovery
|
|
5
|
+
(--config flag → environment variable → well-known names in the repo root),
|
|
6
|
+
dataclass section loading, and the small field validators.
|
|
7
|
+
Everything here is schema-agnostic.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import re
|
|
14
|
+
from dataclasses import fields
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Optional, Sequence
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ConfigError(ValueError):
|
|
20
|
+
"""Raised on an invalid or missing configuration file."""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
VALID_ON_ERROR = ("fail", "warn")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def find_config(
|
|
27
|
+
explicit: Optional[str],
|
|
28
|
+
env_var: str,
|
|
29
|
+
candidates: Sequence[str],
|
|
30
|
+
repo_root: Path,
|
|
31
|
+
) -> Optional[Path]:
|
|
32
|
+
"""Locate a config file: the --config flag, then $env_var, then the
|
|
33
|
+
well-known names in the repository root (first match wins).
|
|
34
|
+
|
|
35
|
+
None means "no file found" — what that implies (run with defaults?
|
|
36
|
+
nothing to do?) is deliberately the caller's decision: the version hook
|
|
37
|
+
falls back to built-in defaults, the submodule hook quietly exits.
|
|
38
|
+
"""
|
|
39
|
+
explicit_or_env = explicit or os.environ.get(env_var)
|
|
40
|
+
if explicit_or_env:
|
|
41
|
+
path = Path(explicit_or_env)
|
|
42
|
+
if not path.is_file():
|
|
43
|
+
raise ConfigError(f"config file not found: {path}")
|
|
44
|
+
return path
|
|
45
|
+
for name in candidates:
|
|
46
|
+
path = repo_root / name
|
|
47
|
+
if path.is_file():
|
|
48
|
+
return path
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def load_section(target: object, name: str, raw: dict, where: str) -> None:
|
|
53
|
+
"""Fill the dataclass instance ``target`` from the mapping ``raw[name]``.
|
|
54
|
+
|
|
55
|
+
Unknown keys are rejected (config rot must be loud); a non-mapping
|
|
56
|
+
section is an error. Type validation of individual fields stays with the
|
|
57
|
+
caller — the schemas differ per subcommand.
|
|
58
|
+
"""
|
|
59
|
+
section = raw.get(name)
|
|
60
|
+
if section is None:
|
|
61
|
+
return
|
|
62
|
+
if not isinstance(section, dict):
|
|
63
|
+
raise ConfigError(f"{where}: {name} must be a mapping")
|
|
64
|
+
known = {f.name for f in fields(target)}
|
|
65
|
+
for key, value in section.items():
|
|
66
|
+
if key not in known:
|
|
67
|
+
raise ConfigError(f"{where}: unknown option '{name}.{key}'")
|
|
68
|
+
setattr(target, key, value)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def require_non_empty_str(value: object, option: str, where: str) -> None:
|
|
72
|
+
if not isinstance(value, str) or not value:
|
|
73
|
+
raise ConfigError(f"{where}: {option} must be a non-empty string")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def require_bool(value: object, option: str, where: str) -> None:
|
|
77
|
+
if not isinstance(value, bool):
|
|
78
|
+
raise ConfigError(f"{where}: {option} must be a boolean")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def require_regex(value: object, option: str, where: str) -> None:
|
|
82
|
+
require_non_empty_str(value, option, where)
|
|
83
|
+
try:
|
|
84
|
+
re.compile(value) # type: ignore[arg-type]
|
|
85
|
+
except re.error as exc:
|
|
86
|
+
raise ConfigError(f"{where}: {option}: {exc}") from exc
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def validate_on_error(value: object, option: str, where: str) -> None:
|
|
90
|
+
if value not in VALID_ON_ERROR:
|
|
91
|
+
raise ConfigError(f"{where}: {option} must be one of {list(VALID_ON_ERROR)}")
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""The exit-code contract shared by every voohook entry point.
|
|
2
|
+
|
|
3
|
+
0 — fine (warnings allowed);
|
|
4
|
+
1 — blocked: the hook would rewrite the file, the pin diverged, the branch
|
|
5
|
+
is unknown, or dangling submodule commits would be pushed;
|
|
6
|
+
2 — usage or configuration problems (bad arguments, not a git repository,
|
|
7
|
+
broken config).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
EXIT_OK = 0
|
|
11
|
+
EXIT_BLOCKED = 1
|
|
12
|
+
EXIT_CONFIG_ERROR = 2
|