Skip to content

Commit 21c9224

Browse files
committed
chore(hooks): skip test suite in pre-commit when no shell files staged
`bin/pre-commit` now scans `git diff --cached` for `.sh`/`.bash`/CLI files; if none are staged it runs `make lint` only and skips the multi-minute test/parallel + shellcheck pass. Saves docs-only commits ~1-3 min.
1 parent c470289 commit 21c9224

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Guard root `package.json` against accidental regression of the docs-split: assert no `dependencies`/`devDependencies`/`peerDependencies`/`scripts` blocks ever return to the published manifest
1313
- `release.sh` now treats `docs/package.json` as a first-class `RELEASE_FILES` entry, so the release flow backs it up, restores it on rollback, and stages it without inline duplication. Backup/restore preserves nested directory paths
1414
- Slim `bashunit::runner::run_test` (~320 lines) by extracting nine pure helpers (`source_login_shell_profiles`, `print_verbose_test_summary`, `export_test_identity`, `apply_interpolated_title`, `detect_runtime_error`, `extract_subshell_type`, `format_subshell_output`, `compute_total_assertions`, `extract_encoded_field`) so the hot path reads as a sequence of named steps. Pure refactor, no behavior change
15+
- Pre-commit hook (`bin/pre-commit`) skips the test suite when no `.sh`/`.bash`/CLI files are staged, falling back to `make lint` only — docs-only commits no longer pay the multi-minute test cost
1516
- Centralize all ANSI escape emission through the existing `_BASHUNIT_COLOR_*` constants. `src/coverage.sh` and the `--watch` screen-clear in `src/main.sh` no longer hardcode escape sequences (#247)
1617
- Speed up coverage report generation (#636): combine executable + hit counting into a single source-file pass (`bashunit::coverage::compute_file_coverage` shared across text/lcov/html reporters), collapse the per-line non-executable pattern checks in `is_executable_line` into a single combined `grep`, replace `echo | sed`/`grep` subshells in `extract_functions` with bash-native regex and parameter expansion, swap per-line `sed` lookups for pre-loaded indexed arrays in `get_hit_lines`/`generate_file_html`, and cache pre-computed file stats across reports
1718

bin/pre-commit

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
#!/usr/bin/env bash
22
echo "Running pre-commit checks"
33

4-
make pre_commit/run
5-
EXIT_CODE=$?
4+
CHANGED_SHELL_FILES=$(git diff --cached --name-only --diff-filter=ACMR \
5+
| grep -E '(\.(sh|bash)$|^bashunit$|^bin/)' || true)
6+
7+
if [ -n "$CHANGED_SHELL_FILES" ]; then
8+
make pre_commit/run
9+
EXIT_CODE=$?
10+
else
11+
echo "No shell files changed; running lint only."
12+
make lint
13+
EXIT_CODE=$?
14+
fi
615

716
if [ "${EXIT_CODE}" -ne 0 ]; then
817
echo "Pre Commit checks failed. Please fix the above issues before committing"

0 commit comments

Comments
 (0)