Skip to content

Commit b04cb66

Browse files
committed
Add skip precommit hook option in commit message
1 parent a4be26f commit b04cb66

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,21 @@ Run only tests:
3030
.\tools\ci.ps1 -TestOnly
3131
```
3232

33-
## Pre-commit hook
33+
## Commit hooks
3434

35-
Install local git hook:
35+
Install local git hooks:
3636

3737
```powershell
3838
.\tools\install-hooks.ps1
3939
```
4040

41-
The hook runs `tools/ci.ps1` before every commit.
41+
Installed hooks:
42+
- `pre-commit` (lightweight no-op)
43+
- `commit-msg` (runs `tools/ci.ps1`)
44+
45+
Checks are skipped when:
46+
- commit message contains `[skip precommit hook]` or `[skip pch]`
47+
- there are no working tree changes (for example, `git commit --allow-empty ...`)
4248

4349
## What CI checks
4450

tools/hooks/pre-commit

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
#!/bin/sh
22
set -e
33

4-
# Prevent hook-provided Git env vars from leaking into nested temp-repo tests.
5-
unset GIT_DIR
6-
unset GIT_WORK_TREE
7-
unset GIT_INDEX_FILE
8-
unset GIT_OBJECT_DIRECTORY
9-
unset GIT_ALTERNATE_OBJECT_DIRECTORIES
10-
unset GIT_COMMON_DIR
11-
unset GIT_PREFIX
12-
13-
if command -v pwsh >/dev/null 2>&1; then
14-
pwsh -NoProfile -ExecutionPolicy Bypass -File tools/ci.ps1
15-
elif command -v powershell >/dev/null 2>&1; then
16-
powershell -NoProfile -ExecutionPolicy Bypass -File tools/ci.ps1
17-
else
18-
echo "pre-commit: neither pwsh nor powershell is available"
19-
exit 1
20-
fi
4+
# Validation runs in commit-msg, where Git provides the commit message file.
5+
# Keep pre-commit lightweight and deterministic.
6+
exit 0

tools/install-hooks.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ $hookDir = if ([IO.Path]::IsPathRooted($gitDir)) {
1717
Join-Path $root $gitDir 'hooks'
1818
}
1919

20-
$source = Join-Path $root 'tools\hooks\pre-commit'
21-
$destination = Join-Path $hookDir 'pre-commit'
20+
New-Item -ItemType Directory -Path $hookDir -Force | Out-Null
2221

23-
if (-not (Test-Path $source)) {
24-
throw "Hook source not found: $source"
25-
}
22+
$hookNames = @('pre-commit', 'commit-msg')
23+
foreach ($hookName in $hookNames) {
24+
$source = Join-Path $root ("tools\hooks\{0}" -f $hookName)
25+
$destination = Join-Path $hookDir $hookName
2626

27-
New-Item -ItemType Directory -Path $hookDir -Force | Out-Null
28-
Copy-Item -Path $source -Destination $destination -Force
27+
if (-not (Test-Path $source)) {
28+
throw "Hook source not found: $source"
29+
}
2930

30-
Write-Host "Installed pre-commit hook: $destination"
31+
Copy-Item -Path $source -Destination $destination -Force
32+
Write-Host ("Installed {0} hook: {1}" -f $hookName, $destination)
33+
}

0 commit comments

Comments
 (0)