requires Python >= 3.11 (ansible-core 2.19); KAMINO_PYTHON (default python3) selects the interpreter, with a clear error when it is missing or too old;
derives the repository from the script's own location, never from the caller's working directory;
rebuilds a .venv made by an older Python;
errors clearly if pre-commit install did not install the pre-commit/commit-msg hooks;
the repository path written into the installed hooks is shell-quoted with printf %q (decision: quote rather than refuse; a path with spaces, quotes, a backtick, $HOME and $(touch ...) works and the injected command does not run);
core.hooksPath: a value that points elsewhere, or a global/system value, fails up front with an explanation. Repo-local values that all resolve to this repository's own hooks directory (or are empty) are lifted for the install and restored afterwards. Any local value counts as present, including an empty or a trailing empty one. The values are read NUL-delimited (git config --local -z --get-all in a while read -d '' loop, no mapfile) and restored element by element, so a value containing a newline survives byte for byte. The EXIT/INT/TERM traps are installed before the unset, and the restore is idempotent;
the usage comment notes that readlink -f/-m are GNU (macOS >= 12.3, or coreutils). No bash 3.2 claim is made: the code avoids bash 4 features but was not run on 3.2.
Changelog fragment says the same (an own-hooks repo-local setting is lifted and restored; only a foreign or global value fails).
tests/scripts/test_dev_setup.py (new, 14 tests). The "Test the repository scripts" lint step and the tests/scripts build_ignore line now come from main (#16); this branch no longer adds its own copy.
Verified
shellcheck: clean on the script.
14 unit tests in tests/scripts/test_dev_setup.py, hermetic (temp dirs, GIT_CONFIG_GLOBAL and HOME in a temp dir, stub python/pip/pre-commit): normal run, idempotent rerun, own absolute and relative hooksPath, foreign hooksPath, global hooksPath (local value restored), multi-valued restore, newline value (compared with git config --local -z --get-all, also after a failing pre-commit), empty and trailing-empty value, restore when pre-commit fails, run from another repository leaves it untouched, crafted path a b $(touch PWNED) "q" touch PWNED2 $HOME (the generated hook still runs, PATH starts with the venv, nothing was executed). Against the previous script 4 of these fail (newline, empty, trailing empty, crafted path).
On the merged tree python3 -I -m unittest discover -s tests/scripts runs 48 tests (main's 34 plus these 14), all pass.
ansible-test sanity --test pep8 --test pylint --test shebang run locally on the new test file: clean.
CI at head 9dfec11, steps observed: Build job (checkout, baked tooling check, Build the Collection, galaxy-importer, ansible-test sanity) success; Lint job (pre-commit, Check image pins, Check image versions were bumped, "Test the repository scripts", gitleaks scan, Conventional Commits) success.
Not verified
bash 3.2 / macOS (not available; no claim made); a real pre-commit install and a real pip install (stubs in the tests); rebuild-on-older-Python against a real old interpreter; a real global hooksPath on a machine (simulated with GIT_CONFIG_GLOBAL).
## What changed (head 9dfec11, main at f271730 merged in)
scripts/dev-setup.sh:
- requires Python >= 3.11 (ansible-core 2.19); `KAMINO_PYTHON` (default `python3`) selects the interpreter, with a clear error when it is missing or too old;
- derives the repository from the script's own location, never from the caller's working directory;
- rebuilds a .venv made by an older Python;
- errors clearly if `pre-commit install` did not install the pre-commit/commit-msg hooks;
- the repository path written into the installed hooks is shell-quoted with `printf %q` (decision: quote rather than refuse; a path with spaces, quotes, a backtick, `$HOME` and `$(touch ...)` works and the injected command does not run);
- `core.hooksPath`: a value that points elsewhere, or a global/system value, fails up front with an explanation. Repo-local values that all resolve to this repository's own hooks directory (or are empty) are lifted for the install and restored afterwards. Any local value counts as present, including an empty or a trailing empty one. The values are read NUL-delimited (`git config --local -z --get-all` in a `while read -d ''` loop, no `mapfile`) and restored element by element, so a value containing a newline survives byte for byte. The EXIT/INT/TERM traps are installed before the unset, and the restore is idempotent;
- the usage comment notes that `readlink -f/-m` are GNU (macOS >= 12.3, or coreutils). No bash 3.2 claim is made: the code avoids bash 4 features but was not run on 3.2.
Changelog fragment says the same (an own-hooks repo-local setting is lifted and restored; only a foreign or global value fails).
- `tests/scripts/test_dev_setup.py` (new, 14 tests). The "Test the repository scripts" lint step and the `tests/scripts` build_ignore line now come from main (#16); this branch no longer adds its own copy.
## Verified
- shellcheck: clean on the script.
- 14 unit tests in `tests/scripts/test_dev_setup.py`, hermetic (temp dirs, `GIT_CONFIG_GLOBAL` and `HOME` in a temp dir, stub python/pip/pre-commit): normal run, idempotent rerun, own absolute and relative hooksPath, foreign hooksPath, global hooksPath (local value restored), multi-valued restore, newline value (compared with `git config --local -z --get-all`, also after a failing pre-commit), empty and trailing-empty value, restore when pre-commit fails, run from another repository leaves it untouched, crafted path `a b $(touch PWNED) "q" `touch PWNED2` $HOME` (the generated hook still runs, PATH starts with the venv, nothing was executed). Against the previous script 4 of these fail (newline, empty, trailing empty, crafted path).
- On the merged tree `python3 -I -m unittest discover -s tests/scripts` runs 48 tests (main's 34 plus these 14), all pass.
- `ansible-test sanity --test pep8 --test pylint --test shebang` run locally on the new test file: clean.
- CI at head 9dfec11, steps observed: Build job (checkout, baked tooling check, Build the Collection, galaxy-importer, `ansible-test sanity`) success; Lint job (pre-commit, Check image pins, Check image versions were bumped, "Test the repository scripts", gitleaks scan, Conventional Commits) success.
## Not verified
- bash 3.2 / macOS (not available; no claim made); a real `pre-commit install` and a real pip install (stubs in the tests); rebuild-on-older-Python against a real old interpreter; a real global hooksPath on a machine (simulated with `GIT_CONFIG_GLOBAL`).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Require Python 3.11+ (PYTHON selects the interpreter), rebuild a virtualenv made
by an older Python, exit early when core.hooksPath is set, fail clearly when a
hook was not installed, and resolve the hook path with --path-format=absolute.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
The script took its repository from the caller's working directory, so running it
from another repository could create or remove that repository's .venv. It now
resolves its own location (symlinks included) and uses git -C for every call.
The interpreter variable is KAMINO_PYTHON, and the usage comment no longer claims it
always selects the venv interpreter. A core.hooksPath that resolves to the
repository's own hooks directory is lifted for the install and restored; any
other value is still rejected.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
Install the EXIT/INT/TERM traps before core.hooksPath is lifted, make the
restore idempotent, and save and restore every local value of a
multi-valued setting in order. When a global or system value still applies
after the local one is lifted, print the script's own message and exit 1
before pre-commit runs. Note that readlink -f/-m are GNU.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
The repository path is shell-quoted (printf %q) where it is written into the
installed hooks, so a path with spaces, quotes or $(...) is data. The local
core.hooksPath values are read with -z and compared and restored element by
element, so a value with a newline survives; the loop avoids mapfile. Any local
value, including an empty or trailing empty one, is lifted for the install and
restored. tests/scripts/test_dev_setup.py covers it with stub tools in throwaway
repositories, and lint.yml now runs tests/scripts.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What changed (head
9dfec11, main atf271730merged in)scripts/dev-setup.sh:
KAMINO_PYTHON(defaultpython3) selects the interpreter, with a clear error when it is missing or too old;pre-commit installdid not install the pre-commit/commit-msg hooks;printf %q(decision: quote rather than refuse; a path with spaces, quotes, a backtick,$HOMEand$(touch ...)works and the injected command does not run);core.hooksPath: a value that points elsewhere, or a global/system value, fails up front with an explanation. Repo-local values that all resolve to this repository's own hooks directory (or are empty) are lifted for the install and restored afterwards. Any local value counts as present, including an empty or a trailing empty one. The values are read NUL-delimited (git config --local -z --get-allin awhile read -d ''loop, nomapfile) and restored element by element, so a value containing a newline survives byte for byte. The EXIT/INT/TERM traps are installed before the unset, and the restore is idempotent;readlink -f/-mare GNU (macOS >= 12.3, or coreutils). No bash 3.2 claim is made: the code avoids bash 4 features but was not run on 3.2.Changelog fragment says the same (an own-hooks repo-local setting is lifted and restored; only a foreign or global value fails).
tests/scripts/test_dev_setup.py(new, 14 tests). The "Test the repository scripts" lint step and thetests/scriptsbuild_ignore line now come from main (#16); this branch no longer adds its own copy.Verified
tests/scripts/test_dev_setup.py, hermetic (temp dirs,GIT_CONFIG_GLOBALandHOMEin a temp dir, stub python/pip/pre-commit): normal run, idempotent rerun, own absolute and relative hooksPath, foreign hooksPath, global hooksPath (local value restored), multi-valued restore, newline value (compared withgit config --local -z --get-all, also after a failing pre-commit), empty and trailing-empty value, restore when pre-commit fails, run from another repository leaves it untouched, crafted patha b $(touch PWNED) "q"touch PWNED2$HOME(the generated hook still runs, PATH starts with the venv, nothing was executed). Against the previous script 4 of these fail (newline, empty, trailing empty, crafted path).python3 -I -m unittest discover -s tests/scriptsruns 48 tests (main's 34 plus these 14), all pass.ansible-test sanity --test pep8 --test pylint --test shebangrun locally on the new test file: clean.9dfec11, steps observed: Build job (checkout, baked tooling check, Build the Collection, galaxy-importer,ansible-test sanity) success; Lint job (pre-commit, Check image pins, Check image versions were bumped, "Test the repository scripts", gitleaks scan, Conventional Commits) success.Not verified
pre-commit installand a real pip install (stubs in the tests); rebuild-on-older-Python against a real old interpreter; a real global hooksPath on a machine (simulated withGIT_CONFIG_GLOBAL).🤖 Generated with Claude Code