From c8c5ca1c4122e9928ca353878342b89eaea286b9 Mon Sep 17 00:00:00 2001 From: Rob Hofmann Date: Mon, 9 Nov 2026 02:00:02 +0100 Subject: [PATCH 1/6] Let a repository opt in to fast-forward pushes to its trunk A repository that sets git.allowTrunkPush to true in aisdlc.json may update main or master with a plain push. The pre-push git hook allows only a fast-forward and refuses a delete, a force push, and a push whose remote tip is not in the clone. Deny-IncompletePush.ps1 refuses a force option, a +refspec, a delete, --all, --mirror, --branches and --prune. The blocking gates and the other push checks still run. Only the JSON value true counts. Refs #16 --- .../scripts/AiSdlcConfig.Tests.ps1 | 11 ++++ .../ai-sdlc-gates/scripts/AiSdlcConfig.psm1 | 16 ++++- .../skills/ai-sdlc-gates/sync-manifest.json | 20 +++---- .../ai-sdlc-handbook/references/layout.md | 1 + .../references/orchestration.md | 4 +- .claude/skills/ai-sdlc-hooks/SKILL.md | 9 ++- .../skills/ai-sdlc-hooks/githooks/pre-push | 47 ++++++++++++++- .../scripts/Deny-IncompletePush.Tests.ps1 | 47 +++++++++++++++ .../scripts/Deny-IncompletePush.ps1 | 41 +++++++++++-- .../scripts/PrePushHook.Tests.ps1 | 59 +++++++++++++++++++ .claude/skills/github-pull-requests/SKILL.md | 2 +- CHANGELOG.md | 7 +++ apm.lock.yaml | 44 +++++++------- .../scripts/AiSdlcConfig.Tests.ps1 | 11 ++++ .../ai-sdlc-gates/scripts/AiSdlcConfig.psm1 | 16 ++++- .../skills/ai-sdlc-gates/sync-manifest.json | 20 +++---- .../ai-sdlc-handbook/references/layout.md | 1 + .../references/orchestration.md | 4 +- core/.apm/skills/ai-sdlc-hooks/SKILL.md | 9 ++- .../skills/ai-sdlc-hooks/githooks/pre-push | 47 ++++++++++++++- .../scripts/Deny-IncompletePush.Tests.ps1 | 47 +++++++++++++++ .../scripts/Deny-IncompletePush.ps1 | 41 +++++++++++-- .../scripts/PrePushHook.Tests.ps1 | 59 +++++++++++++++++++ core/apm.yml | 2 +- packs/bicep/apm.yml | 2 +- packs/blazor/apm.yml | 2 +- packs/discovery/apm.yml | 2 +- packs/dotnet/apm.yml | 2 +- packs/github-issues/apm.yml | 2 +- .../.apm/skills/github-pull-requests/SKILL.md | 2 +- packs/github/apm.yml | 2 +- packs/knowledge/apm.yml | 2 +- packs/sonarcloud/apm.yml | 2 +- 33 files changed, 504 insertions(+), 79 deletions(-) diff --git a/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 b/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 index 2ad1609..c4b9161 100644 --- a/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 +++ b/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 @@ -133,6 +133,17 @@ Describe 'AiSdlcConfig' { @($config.dotnet.Keys) | Should -Not -Contain 'docGeneratorEndpoint' } + It 'refuses a push to the trunk unless git.allowTrunkPush is the JSON value true' -ForEach @( + @{ Json = $null; Expected = $false } + @{ Json = '{}'; Expected = $false } + @{ Json = '{ "git": { "allowTrunkPush": false } }'; Expected = $false } + @{ Json = '{ "git": { "allowTrunkPush": "true" } }'; Expected = $false } + @{ Json = '{ "git": { "allowTrunkPush": 1 } }'; Expected = $false } + @{ Json = '{ "git": { "allowTrunkPush": true } }'; Expected = $true } + ) { + Test-AiSdlcTrunkPushAllowed -RepoRoot (New-ConfigRepo -Json $Json -Git) | Should -Be $Expected + } + It 'reads the other repositories whose issues a pull request may name from tracker.acceptedRepositories' { $config = Get-AiSdlcConfig -RepoRoot (New-ConfigRepo -Json '{ "tracker": { "acceptedRepositories": ["contoso/ai-sdlc"] } }') diff --git a/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 b/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 index afaad1b..d403d2d 100644 --- a/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 +++ b/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 @@ -118,6 +118,9 @@ $script:Defaults = [ordered]@{ secretScan = [ordered]@{ allowPaths = @() } + git = [ordered]@{ + allowTrunkPush = $false + } tracker = [ordered]@{ repository = '' keyPattern = '' @@ -270,6 +273,17 @@ function Test-AiSdlcPack { return @($config.packs) -contains $Name } +function Test-AiSdlcTrunkPushAllowed { + # True only when aisdlc.json sets git.allowTrunkPush to the JSON value true. A string such as "true" + # does not count, so a typo never opens the trunk. The push hooks still refuse a delete or a force push. + [CmdletBinding()] + param([string]$RepoRoot) + + $config = Get-AiSdlcConfig -RepoRoot $RepoRoot + $value = $config.git['allowTrunkPush'] + return ($value -is [bool]) -and $value +} + function Get-AiSdlcStoryPattern { [CmdletBinding()] param([string]$RepoRoot) @@ -383,4 +397,4 @@ function Get-AiSdlcPackage { } } -Export-ModuleMember -Function Find-AiSdlcRepoRoot, Get-AiSdlcConfig, Get-AiSdlcPath, Test-AiSdlcPack, Get-AiSdlcStoryPattern, Get-AiSdlcBranchStoryKey, Get-AiSdlcStoryKey, ConvertTo-AiSdlcStoryKey, Get-AiSdlcPackage +Export-ModuleMember -Function Find-AiSdlcRepoRoot, Get-AiSdlcConfig, Get-AiSdlcPath, Test-AiSdlcPack, Test-AiSdlcTrunkPushAllowed,Get-AiSdlcStoryPattern, Get-AiSdlcBranchStoryKey, Get-AiSdlcStoryKey, ConvertTo-AiSdlcStoryKey, Get-AiSdlcPackage diff --git a/.claude/skills/ai-sdlc-gates/sync-manifest.json b/.claude/skills/ai-sdlc-gates/sync-manifest.json index fcfc9ec..5a57ce5 100644 --- a/.claude/skills/ai-sdlc-gates/sync-manifest.json +++ b/.claude/skills/ai-sdlc-gates/sync-manifest.json @@ -21,8 +21,8 @@ ".claude/skills/ai-sdlc-gates/assets/actions/ai-sdlc-pr/action.yml": "f80ed84d896859668d74cd47bf327a714d383f8a", ".claude/skills/ai-sdlc-gates/assets/agents-core.md": "f7e45643bf0f5447d480b588784b2c599cc7f320", ".claude/skills/ai-sdlc-gates/gates.json": "cf6f5a2d284f0b22f0f4a89292037caed3e53c19", - ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1": "afaad1b3853d71d4f1016e2f9f9df4a1ffdbc03d", - ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1": "2ad1609653980ca3bada51c7cd470e4ba6ffcbe9", + ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1": "d403d2dde2dbcbceba925ae845645cc66c7aef40", + ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1": "c4b91617b2558d1769b35b17aa0be30bc52ff4bd", ".claude/skills/ai-sdlc-gates/scripts/apm-version.json": "fbbd8a51e60e3a7e653a35bc9b959f2bf332ab74", ".claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.ps1": "64c6d651e638b0fe15d20cde02418e8021a5cdfc", ".claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.Tests.ps1": "d9ac6b357e1fc4dbf7deacce04ec365b8515e627", @@ -114,9 +114,9 @@ ".claude/skills/ai-sdlc-handbook/references/docs-wiki.md": "038477c9b704a5b545decfe5e3f3f9970d8d1f9d", ".claude/skills/ai-sdlc-handbook/references/first-story.md": "be899eb395dafb2d704b8f0cb46bac1fb5e593c8", ".claude/skills/ai-sdlc-handbook/references/language.md": "ca703edeb9e07e28e32a39fbcc9116b64db444d8", - ".claude/skills/ai-sdlc-handbook/references/layout.md": "eaabf81a917d8b826f26318bcef7934fbbecbdfa", + ".claude/skills/ai-sdlc-handbook/references/layout.md": "b5c6ed0e19978057a68dbf7d18ccb261def0846a", ".claude/skills/ai-sdlc-handbook/references/node-templates.md": "580c9c92c470a6abbaa0145cc3060ff1a11d247c", - ".claude/skills/ai-sdlc-handbook/references/orchestration.md": "5b6c8c38a5d17ca59cc38794a7750355c508d262", + ".claude/skills/ai-sdlc-handbook/references/orchestration.md": "fd693b640ad3cebfa7d12804c56290b036beb9bb", ".claude/skills/ai-sdlc-handbook/references/pattern.md": "f0f2a8cf3dac267cda0fd3783d86bddba5afc7c0", ".claude/skills/ai-sdlc-handbook/references/personas.md": "083c57f3e4e88519a9d42d7e51559c5165faacff", ".claude/skills/ai-sdlc-handbook/references/plan.md": "8c6fde8e741106f8fe625b8b9a4e98b6d5ba912f", @@ -130,13 +130,13 @@ ".claude/skills/ai-sdlc-hooks/githooks/post-commit": "f18058f9a38efc164e13801d61bb05329a056109", ".claude/skills/ai-sdlc-hooks/githooks/post-merge": "bb373f33abd09294cda55d7fc4499f32672eb372", ".claude/skills/ai-sdlc-hooks/githooks/post-rewrite": "e4c187dffeeaba569901f3424fae476b17c14927", - ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "ba5d1df1483ae80b7d6a009aafdb820f3629a2e3", + ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "9ee20d817cb7958fc37649be80486e177b826650", ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1": "52ffd325d13cd403e7bfea0de8098c530c129b65", ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "ef5b30f0811181462d354a61d3e64c19f0c305e2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "e3a58c32a38844707aa0b2f4c14961af3ed2c870", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "c7da2e83782aa42478fc3b416af5926b8bdd376c", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "27c563f6fe7139ae1de16320c4e477b7c5e24e73", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "08f8eb7056942cbc459ecb8bff8a73d004d772c4", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1": "ca703a9e057633e39af161d9e43a042429813acc", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1": "d15bf28d4191b5e2bca8ce59621ad03a1ef6198c", ".claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.ps1": "da6172d61799df3f37c5f70a103cddddb5517cb0", @@ -156,12 +156,12 @@ ".claude/skills/ai-sdlc-hooks/scripts/Invoke-PostEditCheck.Tests.ps1": "3429e18735428ab387ab58ae276d4195b32e7999", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.ps1": "b54f90deb751d0b0dbf8ee8fbc3f39b3300b3b3d", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.Tests.ps1": "77e4b627da13ea9887f3918f66bc5b33dfd91c56", - ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "10a332050267c363ee019fc1911495b8bc3bfb00", + ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "28197207004ab21a5f74e315b797306ad41a6791", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1": "56abaf1de1c17bea94c26e128f8c41e275a74f87", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1": "8db305e438bc7ee404eb5106eacbe5581738f148", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.ps1": "fa3d7f509b6f9a1a935178c1eaf0d1566b7afead", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.Tests.ps1": "21a220ca2ccc65a56ec427a6e74c5a5dbfbfd4ef", - ".claude/skills/ai-sdlc-hooks/SKILL.md": "0bb9a972fbf928e359cbdfa24cc5781d43d0ab54", + ".claude/skills/ai-sdlc-hooks/SKILL.md": "405f4ecc88e513cda8b8d5361d1329d2a74dbc91", ".claude/skills/capture-learning/SKILL.md": "32300ce3189109b0d717f975623e8d7ccec1c821", ".claude/skills/convene-personas/SKILL.md": "449708a02206bec35a83d2f48ca6366c8b78e3a2", ".claude/skills/docs-wiki-conventions/SKILL.md": "0679512fa39815b63da6373ff29bb6eadc52ff24", @@ -399,7 +399,7 @@ ".claude/skills/github-pull-requests/scripts/Update-PullRequest.Tests.ps1": "f63886f04b76fdddda7b23dd886586fb04317194", ".claude/skills/github-pull-requests/scripts/Wait-WorkflowRun.ps1": "27fd4ca10468eb3fecd2580f2f1e493fd115ae9d", ".claude/skills/github-pull-requests/scripts/Wait-WorkflowRun.Tests.ps1": "3cf5da073805761e52b2af1ea7399e71584ee342", - ".claude/skills/github-pull-requests/SKILL.md": "c2d1d10ae6721687e84a21c5bee71d1332387b76", + ".claude/skills/github-pull-requests/SKILL.md": "c42530e8588f05881da325e74a57eb79ae80fe1c", ".claude/skills/write-pipeline/examples/infrastructure/pr.yml": "b3758e9bae5a9c5dec006af329218e2e23244a78", ".claude/skills/write-pipeline/examples/infrastructure/release.yml": "967c35ded6d96c0b881b89a6ef9599960f001719", ".claude/skills/write-pipeline/examples/web-app/build-and-test.yml": "f9155849e3229580d5e91fc8ea257275807cf220", diff --git a/.claude/skills/ai-sdlc-handbook/references/layout.md b/.claude/skills/ai-sdlc-handbook/references/layout.md index eaabf81..b5c6ed0 100644 --- a/.claude/skills/ai-sdlc-handbook/references/layout.md +++ b/.claude/skills/ai-sdlc-handbook/references/layout.md @@ -129,6 +129,7 @@ installs. `AiSdlcConfig.psm1` takes each dependency whose path ends in `packs/ . # `git lfs pre-push` needs the same lines at the end, so they are read once and kept. +trunk_push_allowed() { + command -v pwsh >/dev/null 2>&1 || return 1 + module="$(dirname "$0")/../../ai-sdlc-gates/scripts/AiSdlcConfig.psm1" + [ -f "$module" ] || return 1 + AISDLC_CONFIG_MODULE="$module" AISDLC_REPO_ROOT="$(git rev-parse --show-toplevel)" \ + pwsh -NoProfile -NonInteractive -Command 'try { Import-Module $env:AISDLC_CONFIG_MODULE -Force; if (Test-AiSdlcTrunkPushAllowed -RepoRoot $env:AISDLC_REPO_ROOT) { exit 0 } } catch { }; exit 1' >/dev/null 2>&1 +} + +is_zero_sha() { + case "$1" in + *[!0]*) return 1 ;; + *) return 0 ;; + esac +} + refs=$(cat) +trunk_allowed= while read -r local_ref local_sha remote_ref remote_sha; do case "$remote_ref" in refs/heads/main|refs/heads/master) - echo "pre-push: a push to ${remote_ref#refs/heads/} is refused. A change reaches main only through a pull request that a person reviews and merges. Push the story branch and open or update its pull request instead." >&2 - exit 1 + branch=${remote_ref#refs/heads/} + if [ -z "$trunk_allowed" ]; then + if trunk_push_allowed; then trunk_allowed=yes; else trunk_allowed=no; fi + fi + if [ "$trunk_allowed" != yes ]; then + echo "pre-push: a push to $branch is refused. A change reaches main only through a pull request that a person reviews and merges. Push the story branch and open or update its pull request instead." >&2 + exit 1 + fi + if is_zero_sha "$local_sha"; then + echo "pre-push: git.allowTrunkPush in aisdlc.json allows an update of $branch, not a delete. The delete is refused." >&2 + exit 1 + fi + if ! is_zero_sha "$remote_sha"; then + if ! git cat-file -e "$remote_sha^{commit}" 2>/dev/null; then + echo "pre-push: the remote tip of $branch is not in this clone, so this push cannot be checked as a fast-forward. Fetch first, then push again." >&2 + exit 1 + fi + if ! git merge-base --is-ancestor "$remote_sha" "$local_sha"; then + echo "pre-push: git.allowTrunkPush in aisdlc.json allows a fast-forward of $branch, not a force push. The push is refused." >&2 + exit 1 + fi + fi + echo "pre-push: git.allowTrunkPush in aisdlc.json allows this fast-forward of $branch. The blocking gates still run." ;; esac done <&1 | Out-String + return [pscustomobject]@{ Output = $out; ExitCode = $LASTEXITCODE } + } + } + + It 'allows when the change is complete' -ForEach @( + @{ Command = 'git push origin main' } + @{ Command = 'git push' } + @{ Command = 'git push -u origin HEAD:main' } + @{ Command = 'git push origin master' } + ) { + $r = Invoke-OptedInHook -Command $Command + $r.Output | Should -Not -Match 'permissionDecision' + } + + It 'refuses , which may delete or rewrite the trunk' -ForEach @( + @{ Command = 'git push --force origin main' } + @{ Command = 'git push -f origin main' } + @{ Command = 'git push --force-with-lease origin main' } + @{ Command = 'git push origin +main' } + @{ Command = 'git push origin :main' } + @{ Command = 'git push --delete origin main' } + @{ Command = 'git push --mirror origin' } + @{ Command = 'git push --all origin' } + ) { + $r = Invoke-OptedInHook -Command $Command + $r.Output | Should -Match '"permissionDecision":"deny"' + $r.Output | Should -Match 'allowTrunkPush' + } + + It 'still runs the completeness check on a trunk push' { + $r = Invoke-OptedInHook -Command 'git push origin main' -CheckScript $script:GapCheck + $r.Output | Should -Match '"permissionDecision":"deny"' + $r.Output | Should -Not -Match 'main or master is refused' + } + } + Context 'a push whose commit has no green pre-flight, which Checkpoint Bravo relies on' { It 'refuses a complete change whose commit has no receipt, and names wrap-up' { $r = Invoke-Hook -Payload (New-Payload -Command 'git push -u origin feature/1-x') -CheckScript $script:CleanCheck -Tree $script:UncheckedTree diff --git a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 index e3a58c3..27c563f 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -26,7 +26,10 @@ script. A payload this script cannot read as a git push allows for the same reason; the pre-push git hook stays the backstop that no configuration can miss. Before the completeness check it refuses any push to main or master: a named target, a quoted one, - HEAD while on main, a bare push while on main, and --all, --mirror or --branches. A permission rule + HEAD while on main, a bare push while on main, and --all, --mirror or --branches. A repository that + sets git.allowTrunkPush to true in aisdlc.json may update main or master directly, but only in a plain + push: a force push (-f, --force*, a +refspec), a delete (-d, --delete, :main), --all, --mirror, + --branches and --prune stay refused. The rest of the checks still run on such a push. A permission rule cannot see which branch a bare push targets, so this hook is the guard for Claude Code and Copilot CLI alike. It is registered for the Bash tool and for the PowerShell tool, because a repository that allows git push in PowerShell would otherwise push past it. The PowerShell payload has the same @@ -216,6 +219,26 @@ function Test-TargetsProtectedBranch { return $false } +function Test-RewritesBranch { + # True when the push may delete or rewrite a branch: a force option, a +refspec, a delete, or a + # push of every branch. Only a push without any of these may update the trunk under git.allowTrunkPush. + param([string]$CommandLine) + + $push = [regex]::Match($CommandLine, "$gitPrefix\s+push(?[^;&|]*)") + if (-not $push.Success) { return $true } + $all = @($push.Groups['rest'].Value.Trim() -split '\s+' | Where-Object { $_ } | ForEach-Object { $_ -replace '[''"]', '' }) + foreach ($word in $all) { + if ($word -in @('-f', '--all', '--mirror', '--branches', '--prune', '-d', '--delete')) { return $true } + if ($word -like '--force*') { return $true } + if ($word.StartsWith('-') -and -not $word.StartsWith('--') -and $word -match 'f|d') { return $true } + } + $refspecs = @($all | Where-Object { -not $_.StartsWith('-') } | Select-Object -Skip 1) + foreach ($refspec in $refspecs) { + if ($refspec.StartsWith('+') -or $refspec.StartsWith(':')) { return $true } + } + return $false +} + function Get-PushedCommits { param([string]$CommandLine, [string]$Root) @@ -296,10 +319,18 @@ if (-not $PSBoundParameters.ContainsKey('CurrentBranch')) { $CurrentBranch = try { [string](git -C $targetRoot rev-parse --abbrev-ref HEAD 2>$null) } catch { '' } } if (Test-TargetsProtectedBranch -CommandLine $command -Branch ([string]$CurrentBranch).Trim()) { - Write-Deny ('A push to main or master is refused. A change reaches main only through a pull request that a ' + - 'person reviews and merges (.claude/skills/ai-sdlc-handbook/references/orchestration.md). Push the story ' + - 'branch and open or update its pull request instead.') - exit 0 + $trunkPushAllowed = $targetInstalls -and (Test-AiSdlcTrunkPushAllowed -RepoRoot $targetRoot) + if (-not $trunkPushAllowed) { + Write-Deny ('A push to main or master is refused. A change reaches main only through a pull request that a ' + + 'person reviews and merges (.claude/skills/ai-sdlc-handbook/references/orchestration.md). Push the story ' + + 'branch and open or update its pull request instead.') + exit 0 + } + if (Test-RewritesBranch -CommandLine $command) { + Write-Deny ('git.allowTrunkPush in aisdlc.json allows a plain push to main or master, not a force push, a ' + + 'delete, or a push of every branch. Push the trunk on its own, without those options.') + exit 0 + } } if (-not $targetInstalls) { exit 0 } diff --git a/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 index 10a3320..2819720 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 @@ -68,6 +68,65 @@ Describe 'The pre-push git hook' { $r.Code | Should -Be 0 -Because $r.Output } + Context 'a repository that sets git.allowTrunkPush, which may fast-forward its trunk' { + BeforeAll { + $script:NoPwshHere = -not (Get-Command pwsh -ErrorAction SilentlyContinue) + + # A repository with two commits on main, so a push can be a fast-forward or a rewrite. + function Invoke-TrunkPush { + param([string]$Json, [ValidateSet('FastForward', 'Rewrite', 'Delete', 'UnknownRemote')][string]$Kind) + $root = Join-Path ([System.IO.Path]::GetTempPath()) ('pre-push-' + [guid]::NewGuid().ToString('n')) + New-Item -ItemType Directory -Path $root | Out-Null + git -C $root init --quiet --initial-branch main + git -C $root config user.email probe@example.invalid + git -C $root config user.name probe + if ($Json) { Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value $Json } + git -C $root commit --quiet --allow-empty -m one --no-verify + $first = (git -C $root rev-parse HEAD).Trim() + git -C $root commit --quiet --allow-empty -m two --no-verify + $second = (git -C $root rev-parse HEAD).Trim() + $line = switch ($Kind) { + 'FastForward' { "refs/heads/main $second refs/heads/main $first" } + 'Rewrite' { "refs/heads/main $first refs/heads/main $second" } + 'Delete' { "(delete) $script:Zero refs/heads/main $second" } + 'UnknownRemote' { "refs/heads/main $second refs/heads/main $script:Sha" } + } + Push-Location $root + try { + $output = "$line`n" | & $script:Sh $script:Hook origin 'https://example.invalid/repo' 2>&1 | Out-String + [pscustomobject]@{ Code = $LASTEXITCODE; Output = $output } + } + finally { Pop-Location; Remove-Item -LiteralPath $root -Recurse -Force -ErrorAction SilentlyContinue } + } + $script:OptIn = '{ "git": { "allowTrunkPush": true } }' + } + + It 'allows a fast-forward of main and says which setting allowed it' -Skip:($script:NoSh -or $script:NoPwshHere) { + $r = Invoke-TrunkPush -Json $script:OptIn -Kind FastForward + $r.Code | Should -Be 0 -Because $r.Output + $r.Output | Should -Match 'git.allowTrunkPush in aisdlc.json allows this fast-forward of main' + } + + It 'refuses a of main' -Skip:($script:NoSh -or $script:NoPwshHere) -ForEach @( + @{ Kind = 'Rewrite'; Reason = 'not a force push' } + @{ Kind = 'Delete'; Reason = 'not a delete' } + @{ Kind = 'UnknownRemote'; Reason = 'Fetch first' } + ) { + $r = Invoke-TrunkPush -Json $script:OptIn -Kind $Kind + $r.Code | Should -Be 1 + $r.Output | Should -Match $Reason + } + + It 'still refuses a fast-forward when the setting is ' -Skip:($script:NoSh -or $script:NoPwshHere) -ForEach @( + @{ Name = 'missing'; Json = '{}' } + @{ Name = 'the string "true"'; Json = '{ "git": { "allowTrunkPush": "true" } }' } + ) { + $r = Invoke-TrunkPush -Json $Json -Kind FastForward + $r.Code | Should -Be 1 + $r.Output | Should -Match 'a push to main is refused' + } + } + It 'never falls back to Windows PowerShell, which cannot run a gate that needs PowerShell 7' { foreach ($name in 'pre-push', 'graphify-refresh') { $text = Get-Content -LiteralPath (Join-Path $PSScriptRoot '..' 'githooks' $name) -Raw diff --git a/.claude/skills/github-pull-requests/SKILL.md b/.claude/skills/github-pull-requests/SKILL.md index c2d1d10..c42530e 100644 --- a/.claude/skills/github-pull-requests/SKILL.md +++ b/.claude/skills/github-pull-requests/SKILL.md @@ -20,7 +20,7 @@ Use this at the PR preflight and at the end of the loop. `implement`, `refactor` `write-platform-note`, `write-pipeline`, `write-prd`, `write-hypothesis`, `draw-customer-journey` and `write-research-summary` load it before they push, and `fix-bug` through `implement`. After a standalone run, `write-adr`, `update-constitution`, `write-docs`, `add-gate`, `capture-learning` and `write-api-spec` load it too. The push and the pull request run with no prompt. Checkpoint Bravo is the person's review of the pull request on GitHub ([orchestration.md](/.claude/skills/ai-sdlc-handbook/references/orchestration.md)). -A push to `main` or `master` is always refused. The link from the PR to its story is a tracker update, so it joins the +A push to `main` or `master` is refused, unless the repository sets `git.allowTrunkPush` in `aisdlc.json`. The link from the PR to its story is a tracker update, so it joins the one list of tracker updates for the run. The agent opens the pull request as a request for review; it never approves, reviews with approval, or merges one (C09). A hook refuses `gh pr merge` and a merge call through `gh api`. diff --git a/CHANGELOG.md b/CHANGELOG.md index d6ad234..263d1a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ merge is ready to tag, and no second pull request is needed to name the version. Each entry names its issue, as `#42`. +## v1.3.0 - 2026-11-09 + +- A repository can set `git.allowTrunkPush` to `true` in `aisdlc.json` to update `main` or `master` + with a plain push, without a pull request (#16). The pre-push git hook and `Deny-IncompletePush.ps1` + still refuse a delete and a force push of the trunk, and the blocking gates still run. The git hook + prints one line that names the setting when it lets a push through. + ## v1.2.0 - 2026-11-07 - A reply, work item or page gives the full link to every pull request, issue or page that the reader diff --git a/apm.lock.yaml b/apm.lock.yaml index e06eead..e14fc23 100644 --- a/apm.lock.yaml +++ b/apm.lock.yaml @@ -248,8 +248,8 @@ dependencies: .claude/skills/ai-sdlc-gates/assets/actions/ai-sdlc-pr/action.yml: sha256:ee6430668f2f44b6256275645e10f8ab2167b8b6d49990465c5527d1b334abac .claude/skills/ai-sdlc-gates/assets/agents-core.md: sha256:544bb5b78ceaa2ee9eb20203ecdef5d380ecd9b10265cc90d10385d96ed72509 .claude/skills/ai-sdlc-gates/gates.json: sha256:160f09f14ff6591b024f827c879802cf9218b37785d209da6a1323602d6153e5 - .claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1: sha256:dabc8f1c63a903818c4eb46f27eb35769914dc6a4330dc2865a4b756300cb706 - .claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1: sha256:63d1161e057b49953e5704e55a0d6091c4a1d6526d8818b26ff96cd69aad133c + .claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1: sha256:d7fc0ff34d5e1995c8d1a592827147fab087361097249ca710953d03581ddb0a + .claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1: sha256:967f1efe278a6640b9e24ac249a12a27eacd9e6d11edbe460c7333179353915c .claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.Tests.ps1: sha256:0b95e6de39c913f3bdebc38c6003f12565a225b165c19e73167cf30391ec1a8b .claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.ps1: sha256:fe0a4432d2e5cb3d1830bc178a086c721eea3cbdd744def18586e1d0a9c0a4c1 .claude/skills/ai-sdlc-gates/scripts/Check-AgentHygiene.Tests.ps1: sha256:d4115307bda4dc2794d395bf41cdc4169896f1255e37b5393d71ad3fb6e6495b @@ -331,7 +331,7 @@ dependencies: .claude/skills/ai-sdlc-gates/scripts/gitleaks-rules.json: sha256:6a8a75c5dbcf2378a1c52d046e34ce275aac7ce08a0ae61408d25c18e1e27014 .claude/skills/ai-sdlc-gates/scripts/gitleaks-version.json: sha256:c54acb854f87a1bbdf0e90c670b72b5de3cd37f7e460d82eca599c3c7af23a84 .claude/skills/ai-sdlc-gates/skill-catalog.json: sha256:5537684656bf189a740ba7e9e7050083af05668d00501ce1e9c6909cb8b91203 - .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:6661094ee0cf38a1bccde9a42b3daa41de7ed7ca115e52f7f18cb7ac62f74f82 + .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:c259e68badb668435176e2c300fdce7a8042cba028d4a3113d7d5b4bebe7af14 .claude/skills/ai-sdlc-handbook/SKILL.md: sha256:548e6b9ad79d3d2afa2f5779835988eeb12c49cda08917c4bbaa9ac0486a47a0 .claude/skills/ai-sdlc-handbook/references/README.md: sha256:654afcaa2b81f560eff93dbdef521b09ced06137a1dbb85d70a4e14ef7502248 .claude/skills/ai-sdlc-handbook/references/artifact-graph.md: sha256:d7ddfe20e5ee6565bcf25f9cef0f578da2a4ab1590033d791b8814d4688fd1f0 @@ -343,14 +343,14 @@ dependencies: .claude/skills/ai-sdlc-handbook/references/docs-wiki.md: sha256:2bd6f3a8e64f9db16163519767b822e4ebcffd740e3c5cbff17281ad71d264b7 .claude/skills/ai-sdlc-handbook/references/first-story.md: sha256:831552230cc16386ee01d7c730e288ef19aca5a66fafb00e1dfbbf4e9788caf2 .claude/skills/ai-sdlc-handbook/references/language.md: sha256:e0e32fae9c9fcdd23380d92ec910128254ce248538940541f5789ca78228a023 - .claude/skills/ai-sdlc-handbook/references/layout.md: sha256:a0f86702edb9caf4b52ccda28b3256a17cf30cd008b2200220901699d84896a9 + .claude/skills/ai-sdlc-handbook/references/layout.md: sha256:46beddc0c816665a24a55cf24de14ac3f14aa55a776e7de108d943d9ea5fb642 .claude/skills/ai-sdlc-handbook/references/node-templates.md: sha256:8664ad1f85bff48d6230ed22e3f25683f378822e566c2a1454cbb204f4bb8fad - .claude/skills/ai-sdlc-handbook/references/orchestration.md: sha256:05513a9f99f14f281a91da176e9eb39c95f6d939ff33ecca2390c784190546c4 + .claude/skills/ai-sdlc-handbook/references/orchestration.md: sha256:7fa9639a0f172d98aa6dc198dc9995749c1321c08488c4929485fe8f6a8fff97 .claude/skills/ai-sdlc-handbook/references/pattern.md: sha256:7908f80ee28ff1f7cd9f85b22fcf3e455fe74225d33ff201f8fbce1623d672eb .claude/skills/ai-sdlc-handbook/references/personas.md: sha256:7913c3dca6bad93b45624349a12bf976f894eb6ca05c7baa1fa7e3ba802ca69a .claude/skills/ai-sdlc-handbook/references/plan.md: sha256:b632fe2da2369f494ebe2606c4bdc8726eabe3b7615b6ddb0b58fa9b3897a216 .claude/skills/ai-sdlc-handbook/references/skill-usage.md: sha256:9d5414b38d9d6f5bd7dfa9857e8e441bf040b0020f46ac8d3b29b0a476161c61 - .claude/skills/ai-sdlc-hooks/SKILL.md: sha256:68e5154f4e734b93e56b0c2d575b427096dc57c56d217c84a61e27041417ee3f + .claude/skills/ai-sdlc-hooks/SKILL.md: sha256:2874ddb81894e253ff335649672acee9c1578962357c8b849963c4193e220547 .claude/skills/ai-sdlc-hooks/gates.json: sha256:dfc8b0003e930167e0fccc366867f423bc0850f3c69477c0e7119aed710bf902 .claude/skills/ai-sdlc-hooks/githooks/git-lfs-hook: sha256:3265310500749e7181a5625517f94e2efa62d48be987ebc9b0396d38e2eeffa6 .claude/skills/ai-sdlc-hooks/githooks/graphify-refresh: sha256:1bc6c7f181aab3a0fdd34bf8907a4884bea2412a56ebdc77a673707e17c046f3 @@ -358,13 +358,13 @@ dependencies: .claude/skills/ai-sdlc-hooks/githooks/post-commit: sha256:4f73a74133b0272725117fa9d962353abb6ed98d9cf5e731cd212fd5ace23271 .claude/skills/ai-sdlc-hooks/githooks/post-merge: sha256:b9f1f47cd3894406451e00c177912baeed66470b0cc18d581a5461330c7c0868 .claude/skills/ai-sdlc-hooks/githooks/post-rewrite: sha256:b7ee1a97b08a9826678829b6c49457fdc4b5ebd53eaf8cdd70f33d26e61c4a79 - .claude/skills/ai-sdlc-hooks/githooks/pre-push: sha256:26e2917ccf0bab590b04ee318a877b22f22245b2d451ee3b23e96b420ed67582 + .claude/skills/ai-sdlc-hooks/githooks/pre-push: sha256:f71a2b92ba190e7bf7b2ccc42a3f7705524db7f5cadbf31ee7abd39c9ae3ca79 .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1: sha256:004bc7f1a68e953c8e657b49e74755b69a14138dfb0db61162ab15420f2b24be .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1: sha256:b3569de6e27c3dcaffbc082311e6882bd722d440e5e855245da2410033202c7e .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1: sha256:4c4e1f6b673671125290d78815c72277665a8a618b55fd589f75f3a36e3b80aa .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1: sha256:46d1d83e38e75db41b1f370bc6f49f4800f0234765eac63c53e37b5af7000453 - .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1: sha256:af45b08394b26ff61cbee86d213615ac1243a53cb28a61277ee79bfdfe075505 - .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1: sha256:c75085d41a94f60036ff18b9bcaa642c4220c3617925b345a1177b9bc557e2ff + .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1: sha256:e5e9ac9b062db0ee474e545a6248ec5aff3bd0b95801ef3ade59072adcc53889 + .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1: sha256:114309237becb627f5847187057717d90fbd031ebffcedc74406d3ec58f5f762 .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1: sha256:1c46576b9633bd12286efa11cc9f7c6c2f982f29859f9a33272f76452888e77b .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1: sha256:fccaa2da3a0254cc8a7740974f07b1c0fc1e67106ae7191d9710cbf699da1ba7 .claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.Tests.ps1: sha256:151c3ee69c88db0d85cf4c94207b04dfc4eabe857e178051044ed4fdcee58f33 @@ -384,7 +384,7 @@ dependencies: .claude/skills/ai-sdlc-hooks/scripts/Invoke-PostEditCheck.ps1: sha256:d60cdd2d341487ded3b9fafe40da49f2adfb1cf8f20cf3f8559ea2e80a5f93c6 .claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.Tests.ps1: sha256:9c9859767d2534c45e1c72b47f4b5c64aaa16c32c580df3b5d8bc3dce5cdb2c4 .claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.ps1: sha256:abf763c6cde97dbfc83b25f140e768d66fd9edd3961605b7d058b08a31882875 - .claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1: sha256:a40742b677d79726a6206b7b2dc232bff1df0e663f741af03ced2141016eaba0 + .claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1: sha256:ef41c8fce0c879024fe134dbad9e208111831bd7d85b1db8f4f117c3ac037d18 .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1: sha256:4f2fe5313c8763f8128ad0e0347da1f2dd485393d20dc5e3a5d75e08aa157ad3 .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1: sha256:0381e47c6b1070c7b230f81f243e25b1a8bfa68b5e8e9ae2ad6e225b0ddb36b6 .claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.Tests.ps1: sha256:52f81e945390e61222a2668c8525cb17f17226267e24c52d7792263a07576543 @@ -493,7 +493,7 @@ dependencies: deployed_file_hashes: .claude/skills/fix-pr-feedback/SKILL.md: sha256:8257f6f84ec21ee12016fc27e0f3508bcf16cf59b9dd91f35ace0682fbaa3c2c .claude/skills/github-actions-conventions/SKILL.md: sha256:0ebf2363a0ff9aa3b8fdecef9d9ffb817cf3aba483d8efae0611b2c5c3b65d87 - .claude/skills/github-pull-requests/SKILL.md: sha256:36ef2c7fff5c21ee87893b1c066e1b150c3cbbf3cecabfbc13f81ec3d89cf68b + .claude/skills/github-pull-requests/SKILL.md: sha256:1e5cba7164be10f0cacc91b2ed3abc64dc6a91fc447d0b079d55f174a0432f5c .claude/skills/github-pull-requests/gates.json: sha256:ac2029c1077f9ff7ba5892b815e009e0470bd924c8b361321bfd2bd1a26f5f89 .claude/skills/github-pull-requests/references/delivery-metrics.md: sha256:e68cda7b7772b71f456a3c48f316ae80ae8fbd7c63275a1f9780234376c68ca4 .claude/skills/github-pull-requests/scripts/Get-PrMetrics.Tests.ps1: sha256:1a0f480b221481d73bf6d54d463dd0251b89d88b959b545d7e7d3b420e090d2c @@ -804,7 +804,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:dabc8f1c63a903818c4eb46f27eb35769914dc6a4330dc2865a4b756300cb706 + content_hash: sha256:d7fc0ff34d5e1995c8d1a592827147fab087361097249ca710953d03581ddb0a - kind: project-relative target: claude value: .claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 @@ -813,7 +813,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:63d1161e057b49953e5704e55a0d6091c4a1d6526d8818b26ff96cd69aad133c + content_hash: sha256:967f1efe278a6640b9e24ac249a12a27eacd9e6d11edbe460c7333179353915c - kind: project-relative target: claude value: .claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.Tests.ps1 @@ -1551,7 +1551,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:6661094ee0cf38a1bccde9a42b3daa41de7ed7ca115e52f7f18cb7ac62f74f82 + content_hash: sha256:c259e68badb668435176e2c300fdce7a8042cba028d4a3113d7d5b4bebe7af14 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook @@ -1668,7 +1668,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:a0f86702edb9caf4b52ccda28b3256a17cf30cd008b2200220901699d84896a9 + content_hash: sha256:46beddc0c816665a24a55cf24de14ac3f14aa55a776e7de108d943d9ea5fb642 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook/references/node-templates.md @@ -1686,7 +1686,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:05513a9f99f14f281a91da176e9eb39c95f6d939ff33ecca2390c784190546c4 + content_hash: sha256:7fa9639a0f172d98aa6dc198dc9995749c1321c08488c4929485fe8f6a8fff97 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook/references/pattern.md @@ -1740,7 +1740,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:68e5154f4e734b93e56b0c2d575b427096dc57c56d217c84a61e27041417ee3f + content_hash: sha256:2874ddb81894e253ff335649672acee9c1578962357c8b849963c4193e220547 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/gates.json @@ -1812,7 +1812,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:26e2917ccf0bab590b04ee318a877b22f22245b2d451ee3b23e96b420ed67582 + content_hash: sha256:f71a2b92ba190e7bf7b2ccc42a3f7705524db7f5cadbf31ee7abd39c9ae3ca79 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1 @@ -1857,7 +1857,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:af45b08394b26ff61cbee86d213615ac1243a53cb28a61277ee79bfdfe075505 + content_hash: sha256:e5e9ac9b062db0ee474e545a6248ec5aff3bd0b95801ef3ade59072adcc53889 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -1866,7 +1866,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:c75085d41a94f60036ff18b9bcaa642c4220c3617925b345a1177b9bc557e2ff + content_hash: sha256:114309237becb627f5847187057717d90fbd031ebffcedc74406d3ec58f5f762 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1 @@ -2046,7 +2046,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:a40742b677d79726a6206b7b2dc232bff1df0e663f741af03ced2141016eaba0 + content_hash: sha256:ef41c8fce0c879024fe134dbad9e208111831bd7d85b1db8f4f117c3ac037d18 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1 @@ -2325,7 +2325,7 @@ deployments: owners: - ./packs/github active_owner: ./packs/github - content_hash: sha256:36ef2c7fff5c21ee87893b1c066e1b150c3cbbf3cecabfbc13f81ec3d89cf68b + content_hash: sha256:1e5cba7164be10f0cacc91b2ed3abc64dc6a91fc447d0b079d55f174a0432f5c - kind: project-relative target: claude value: .claude/skills/github-pull-requests/gates.json diff --git a/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 b/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 index 2ad1609..c4b9161 100644 --- a/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 +++ b/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 @@ -133,6 +133,17 @@ Describe 'AiSdlcConfig' { @($config.dotnet.Keys) | Should -Not -Contain 'docGeneratorEndpoint' } + It 'refuses a push to the trunk unless git.allowTrunkPush is the JSON value true' -ForEach @( + @{ Json = $null; Expected = $false } + @{ Json = '{}'; Expected = $false } + @{ Json = '{ "git": { "allowTrunkPush": false } }'; Expected = $false } + @{ Json = '{ "git": { "allowTrunkPush": "true" } }'; Expected = $false } + @{ Json = '{ "git": { "allowTrunkPush": 1 } }'; Expected = $false } + @{ Json = '{ "git": { "allowTrunkPush": true } }'; Expected = $true } + ) { + Test-AiSdlcTrunkPushAllowed -RepoRoot (New-ConfigRepo -Json $Json -Git) | Should -Be $Expected + } + It 'reads the other repositories whose issues a pull request may name from tracker.acceptedRepositories' { $config = Get-AiSdlcConfig -RepoRoot (New-ConfigRepo -Json '{ "tracker": { "acceptedRepositories": ["contoso/ai-sdlc"] } }') diff --git a/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 b/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 index afaad1b..d403d2d 100644 --- a/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 +++ b/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 @@ -118,6 +118,9 @@ $script:Defaults = [ordered]@{ secretScan = [ordered]@{ allowPaths = @() } + git = [ordered]@{ + allowTrunkPush = $false + } tracker = [ordered]@{ repository = '' keyPattern = '' @@ -270,6 +273,17 @@ function Test-AiSdlcPack { return @($config.packs) -contains $Name } +function Test-AiSdlcTrunkPushAllowed { + # True only when aisdlc.json sets git.allowTrunkPush to the JSON value true. A string such as "true" + # does not count, so a typo never opens the trunk. The push hooks still refuse a delete or a force push. + [CmdletBinding()] + param([string]$RepoRoot) + + $config = Get-AiSdlcConfig -RepoRoot $RepoRoot + $value = $config.git['allowTrunkPush'] + return ($value -is [bool]) -and $value +} + function Get-AiSdlcStoryPattern { [CmdletBinding()] param([string]$RepoRoot) @@ -383,4 +397,4 @@ function Get-AiSdlcPackage { } } -Export-ModuleMember -Function Find-AiSdlcRepoRoot, Get-AiSdlcConfig, Get-AiSdlcPath, Test-AiSdlcPack, Get-AiSdlcStoryPattern, Get-AiSdlcBranchStoryKey, Get-AiSdlcStoryKey, ConvertTo-AiSdlcStoryKey, Get-AiSdlcPackage +Export-ModuleMember -Function Find-AiSdlcRepoRoot, Get-AiSdlcConfig, Get-AiSdlcPath, Test-AiSdlcPack, Test-AiSdlcTrunkPushAllowed,Get-AiSdlcStoryPattern, Get-AiSdlcBranchStoryKey, Get-AiSdlcStoryKey, ConvertTo-AiSdlcStoryKey, Get-AiSdlcPackage diff --git a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json index fcfc9ec..5a57ce5 100644 --- a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json +++ b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json @@ -21,8 +21,8 @@ ".claude/skills/ai-sdlc-gates/assets/actions/ai-sdlc-pr/action.yml": "f80ed84d896859668d74cd47bf327a714d383f8a", ".claude/skills/ai-sdlc-gates/assets/agents-core.md": "f7e45643bf0f5447d480b588784b2c599cc7f320", ".claude/skills/ai-sdlc-gates/gates.json": "cf6f5a2d284f0b22f0f4a89292037caed3e53c19", - ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1": "afaad1b3853d71d4f1016e2f9f9df4a1ffdbc03d", - ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1": "2ad1609653980ca3bada51c7cd470e4ba6ffcbe9", + ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1": "d403d2dde2dbcbceba925ae845645cc66c7aef40", + ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1": "c4b91617b2558d1769b35b17aa0be30bc52ff4bd", ".claude/skills/ai-sdlc-gates/scripts/apm-version.json": "fbbd8a51e60e3a7e653a35bc9b959f2bf332ab74", ".claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.ps1": "64c6d651e638b0fe15d20cde02418e8021a5cdfc", ".claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.Tests.ps1": "d9ac6b357e1fc4dbf7deacce04ec365b8515e627", @@ -114,9 +114,9 @@ ".claude/skills/ai-sdlc-handbook/references/docs-wiki.md": "038477c9b704a5b545decfe5e3f3f9970d8d1f9d", ".claude/skills/ai-sdlc-handbook/references/first-story.md": "be899eb395dafb2d704b8f0cb46bac1fb5e593c8", ".claude/skills/ai-sdlc-handbook/references/language.md": "ca703edeb9e07e28e32a39fbcc9116b64db444d8", - ".claude/skills/ai-sdlc-handbook/references/layout.md": "eaabf81a917d8b826f26318bcef7934fbbecbdfa", + ".claude/skills/ai-sdlc-handbook/references/layout.md": "b5c6ed0e19978057a68dbf7d18ccb261def0846a", ".claude/skills/ai-sdlc-handbook/references/node-templates.md": "580c9c92c470a6abbaa0145cc3060ff1a11d247c", - ".claude/skills/ai-sdlc-handbook/references/orchestration.md": "5b6c8c38a5d17ca59cc38794a7750355c508d262", + ".claude/skills/ai-sdlc-handbook/references/orchestration.md": "fd693b640ad3cebfa7d12804c56290b036beb9bb", ".claude/skills/ai-sdlc-handbook/references/pattern.md": "f0f2a8cf3dac267cda0fd3783d86bddba5afc7c0", ".claude/skills/ai-sdlc-handbook/references/personas.md": "083c57f3e4e88519a9d42d7e51559c5165faacff", ".claude/skills/ai-sdlc-handbook/references/plan.md": "8c6fde8e741106f8fe625b8b9a4e98b6d5ba912f", @@ -130,13 +130,13 @@ ".claude/skills/ai-sdlc-hooks/githooks/post-commit": "f18058f9a38efc164e13801d61bb05329a056109", ".claude/skills/ai-sdlc-hooks/githooks/post-merge": "bb373f33abd09294cda55d7fc4499f32672eb372", ".claude/skills/ai-sdlc-hooks/githooks/post-rewrite": "e4c187dffeeaba569901f3424fae476b17c14927", - ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "ba5d1df1483ae80b7d6a009aafdb820f3629a2e3", + ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "9ee20d817cb7958fc37649be80486e177b826650", ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1": "52ffd325d13cd403e7bfea0de8098c530c129b65", ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "ef5b30f0811181462d354a61d3e64c19f0c305e2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "e3a58c32a38844707aa0b2f4c14961af3ed2c870", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "c7da2e83782aa42478fc3b416af5926b8bdd376c", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "27c563f6fe7139ae1de16320c4e477b7c5e24e73", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "08f8eb7056942cbc459ecb8bff8a73d004d772c4", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1": "ca703a9e057633e39af161d9e43a042429813acc", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1": "d15bf28d4191b5e2bca8ce59621ad03a1ef6198c", ".claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.ps1": "da6172d61799df3f37c5f70a103cddddb5517cb0", @@ -156,12 +156,12 @@ ".claude/skills/ai-sdlc-hooks/scripts/Invoke-PostEditCheck.Tests.ps1": "3429e18735428ab387ab58ae276d4195b32e7999", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.ps1": "b54f90deb751d0b0dbf8ee8fbc3f39b3300b3b3d", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.Tests.ps1": "77e4b627da13ea9887f3918f66bc5b33dfd91c56", - ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "10a332050267c363ee019fc1911495b8bc3bfb00", + ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "28197207004ab21a5f74e315b797306ad41a6791", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1": "56abaf1de1c17bea94c26e128f8c41e275a74f87", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1": "8db305e438bc7ee404eb5106eacbe5581738f148", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.ps1": "fa3d7f509b6f9a1a935178c1eaf0d1566b7afead", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.Tests.ps1": "21a220ca2ccc65a56ec427a6e74c5a5dbfbfd4ef", - ".claude/skills/ai-sdlc-hooks/SKILL.md": "0bb9a972fbf928e359cbdfa24cc5781d43d0ab54", + ".claude/skills/ai-sdlc-hooks/SKILL.md": "405f4ecc88e513cda8b8d5361d1329d2a74dbc91", ".claude/skills/capture-learning/SKILL.md": "32300ce3189109b0d717f975623e8d7ccec1c821", ".claude/skills/convene-personas/SKILL.md": "449708a02206bec35a83d2f48ca6366c8b78e3a2", ".claude/skills/docs-wiki-conventions/SKILL.md": "0679512fa39815b63da6373ff29bb6eadc52ff24", @@ -399,7 +399,7 @@ ".claude/skills/github-pull-requests/scripts/Update-PullRequest.Tests.ps1": "f63886f04b76fdddda7b23dd886586fb04317194", ".claude/skills/github-pull-requests/scripts/Wait-WorkflowRun.ps1": "27fd4ca10468eb3fecd2580f2f1e493fd115ae9d", ".claude/skills/github-pull-requests/scripts/Wait-WorkflowRun.Tests.ps1": "3cf5da073805761e52b2af1ea7399e71584ee342", - ".claude/skills/github-pull-requests/SKILL.md": "c2d1d10ae6721687e84a21c5bee71d1332387b76", + ".claude/skills/github-pull-requests/SKILL.md": "c42530e8588f05881da325e74a57eb79ae80fe1c", ".claude/skills/write-pipeline/examples/infrastructure/pr.yml": "b3758e9bae5a9c5dec006af329218e2e23244a78", ".claude/skills/write-pipeline/examples/infrastructure/release.yml": "967c35ded6d96c0b881b89a6ef9599960f001719", ".claude/skills/write-pipeline/examples/web-app/build-and-test.yml": "f9155849e3229580d5e91fc8ea257275807cf220", diff --git a/core/.apm/skills/ai-sdlc-handbook/references/layout.md b/core/.apm/skills/ai-sdlc-handbook/references/layout.md index eaabf81..b5c6ed0 100644 --- a/core/.apm/skills/ai-sdlc-handbook/references/layout.md +++ b/core/.apm/skills/ai-sdlc-handbook/references/layout.md @@ -129,6 +129,7 @@ installs. `AiSdlcConfig.psm1` takes each dependency whose path ends in `packs/ . # `git lfs pre-push` needs the same lines at the end, so they are read once and kept. +trunk_push_allowed() { + command -v pwsh >/dev/null 2>&1 || return 1 + module="$(dirname "$0")/../../ai-sdlc-gates/scripts/AiSdlcConfig.psm1" + [ -f "$module" ] || return 1 + AISDLC_CONFIG_MODULE="$module" AISDLC_REPO_ROOT="$(git rev-parse --show-toplevel)" \ + pwsh -NoProfile -NonInteractive -Command 'try { Import-Module $env:AISDLC_CONFIG_MODULE -Force; if (Test-AiSdlcTrunkPushAllowed -RepoRoot $env:AISDLC_REPO_ROOT) { exit 0 } } catch { }; exit 1' >/dev/null 2>&1 +} + +is_zero_sha() { + case "$1" in + *[!0]*) return 1 ;; + *) return 0 ;; + esac +} + refs=$(cat) +trunk_allowed= while read -r local_ref local_sha remote_ref remote_sha; do case "$remote_ref" in refs/heads/main|refs/heads/master) - echo "pre-push: a push to ${remote_ref#refs/heads/} is refused. A change reaches main only through a pull request that a person reviews and merges. Push the story branch and open or update its pull request instead." >&2 - exit 1 + branch=${remote_ref#refs/heads/} + if [ -z "$trunk_allowed" ]; then + if trunk_push_allowed; then trunk_allowed=yes; else trunk_allowed=no; fi + fi + if [ "$trunk_allowed" != yes ]; then + echo "pre-push: a push to $branch is refused. A change reaches main only through a pull request that a person reviews and merges. Push the story branch and open or update its pull request instead." >&2 + exit 1 + fi + if is_zero_sha "$local_sha"; then + echo "pre-push: git.allowTrunkPush in aisdlc.json allows an update of $branch, not a delete. The delete is refused." >&2 + exit 1 + fi + if ! is_zero_sha "$remote_sha"; then + if ! git cat-file -e "$remote_sha^{commit}" 2>/dev/null; then + echo "pre-push: the remote tip of $branch is not in this clone, so this push cannot be checked as a fast-forward. Fetch first, then push again." >&2 + exit 1 + fi + if ! git merge-base --is-ancestor "$remote_sha" "$local_sha"; then + echo "pre-push: git.allowTrunkPush in aisdlc.json allows a fast-forward of $branch, not a force push. The push is refused." >&2 + exit 1 + fi + fi + echo "pre-push: git.allowTrunkPush in aisdlc.json allows this fast-forward of $branch. The blocking gates still run." ;; esac done <&1 | Out-String + return [pscustomobject]@{ Output = $out; ExitCode = $LASTEXITCODE } + } + } + + It 'allows when the change is complete' -ForEach @( + @{ Command = 'git push origin main' } + @{ Command = 'git push' } + @{ Command = 'git push -u origin HEAD:main' } + @{ Command = 'git push origin master' } + ) { + $r = Invoke-OptedInHook -Command $Command + $r.Output | Should -Not -Match 'permissionDecision' + } + + It 'refuses , which may delete or rewrite the trunk' -ForEach @( + @{ Command = 'git push --force origin main' } + @{ Command = 'git push -f origin main' } + @{ Command = 'git push --force-with-lease origin main' } + @{ Command = 'git push origin +main' } + @{ Command = 'git push origin :main' } + @{ Command = 'git push --delete origin main' } + @{ Command = 'git push --mirror origin' } + @{ Command = 'git push --all origin' } + ) { + $r = Invoke-OptedInHook -Command $Command + $r.Output | Should -Match '"permissionDecision":"deny"' + $r.Output | Should -Match 'allowTrunkPush' + } + + It 'still runs the completeness check on a trunk push' { + $r = Invoke-OptedInHook -Command 'git push origin main' -CheckScript $script:GapCheck + $r.Output | Should -Match '"permissionDecision":"deny"' + $r.Output | Should -Not -Match 'main or master is refused' + } + } + Context 'a push whose commit has no green pre-flight, which Checkpoint Bravo relies on' { It 'refuses a complete change whose commit has no receipt, and names wrap-up' { $r = Invoke-Hook -Payload (New-Payload -Command 'git push -u origin feature/1-x') -CheckScript $script:CleanCheck -Tree $script:UncheckedTree diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 index e3a58c3..27c563f 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -26,7 +26,10 @@ script. A payload this script cannot read as a git push allows for the same reason; the pre-push git hook stays the backstop that no configuration can miss. Before the completeness check it refuses any push to main or master: a named target, a quoted one, - HEAD while on main, a bare push while on main, and --all, --mirror or --branches. A permission rule + HEAD while on main, a bare push while on main, and --all, --mirror or --branches. A repository that + sets git.allowTrunkPush to true in aisdlc.json may update main or master directly, but only in a plain + push: a force push (-f, --force*, a +refspec), a delete (-d, --delete, :main), --all, --mirror, + --branches and --prune stay refused. The rest of the checks still run on such a push. A permission rule cannot see which branch a bare push targets, so this hook is the guard for Claude Code and Copilot CLI alike. It is registered for the Bash tool and for the PowerShell tool, because a repository that allows git push in PowerShell would otherwise push past it. The PowerShell payload has the same @@ -216,6 +219,26 @@ function Test-TargetsProtectedBranch { return $false } +function Test-RewritesBranch { + # True when the push may delete or rewrite a branch: a force option, a +refspec, a delete, or a + # push of every branch. Only a push without any of these may update the trunk under git.allowTrunkPush. + param([string]$CommandLine) + + $push = [regex]::Match($CommandLine, "$gitPrefix\s+push(?[^;&|]*)") + if (-not $push.Success) { return $true } + $all = @($push.Groups['rest'].Value.Trim() -split '\s+' | Where-Object { $_ } | ForEach-Object { $_ -replace '[''"]', '' }) + foreach ($word in $all) { + if ($word -in @('-f', '--all', '--mirror', '--branches', '--prune', '-d', '--delete')) { return $true } + if ($word -like '--force*') { return $true } + if ($word.StartsWith('-') -and -not $word.StartsWith('--') -and $word -match 'f|d') { return $true } + } + $refspecs = @($all | Where-Object { -not $_.StartsWith('-') } | Select-Object -Skip 1) + foreach ($refspec in $refspecs) { + if ($refspec.StartsWith('+') -or $refspec.StartsWith(':')) { return $true } + } + return $false +} + function Get-PushedCommits { param([string]$CommandLine, [string]$Root) @@ -296,10 +319,18 @@ if (-not $PSBoundParameters.ContainsKey('CurrentBranch')) { $CurrentBranch = try { [string](git -C $targetRoot rev-parse --abbrev-ref HEAD 2>$null) } catch { '' } } if (Test-TargetsProtectedBranch -CommandLine $command -Branch ([string]$CurrentBranch).Trim()) { - Write-Deny ('A push to main or master is refused. A change reaches main only through a pull request that a ' + - 'person reviews and merges (.claude/skills/ai-sdlc-handbook/references/orchestration.md). Push the story ' + - 'branch and open or update its pull request instead.') - exit 0 + $trunkPushAllowed = $targetInstalls -and (Test-AiSdlcTrunkPushAllowed -RepoRoot $targetRoot) + if (-not $trunkPushAllowed) { + Write-Deny ('A push to main or master is refused. A change reaches main only through a pull request that a ' + + 'person reviews and merges (.claude/skills/ai-sdlc-handbook/references/orchestration.md). Push the story ' + + 'branch and open or update its pull request instead.') + exit 0 + } + if (Test-RewritesBranch -CommandLine $command) { + Write-Deny ('git.allowTrunkPush in aisdlc.json allows a plain push to main or master, not a force push, a ' + + 'delete, or a push of every branch. Push the trunk on its own, without those options.') + exit 0 + } } if (-not $targetInstalls) { exit 0 } diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 index 10a3320..2819720 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 @@ -68,6 +68,65 @@ Describe 'The pre-push git hook' { $r.Code | Should -Be 0 -Because $r.Output } + Context 'a repository that sets git.allowTrunkPush, which may fast-forward its trunk' { + BeforeAll { + $script:NoPwshHere = -not (Get-Command pwsh -ErrorAction SilentlyContinue) + + # A repository with two commits on main, so a push can be a fast-forward or a rewrite. + function Invoke-TrunkPush { + param([string]$Json, [ValidateSet('FastForward', 'Rewrite', 'Delete', 'UnknownRemote')][string]$Kind) + $root = Join-Path ([System.IO.Path]::GetTempPath()) ('pre-push-' + [guid]::NewGuid().ToString('n')) + New-Item -ItemType Directory -Path $root | Out-Null + git -C $root init --quiet --initial-branch main + git -C $root config user.email probe@example.invalid + git -C $root config user.name probe + if ($Json) { Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value $Json } + git -C $root commit --quiet --allow-empty -m one --no-verify + $first = (git -C $root rev-parse HEAD).Trim() + git -C $root commit --quiet --allow-empty -m two --no-verify + $second = (git -C $root rev-parse HEAD).Trim() + $line = switch ($Kind) { + 'FastForward' { "refs/heads/main $second refs/heads/main $first" } + 'Rewrite' { "refs/heads/main $first refs/heads/main $second" } + 'Delete' { "(delete) $script:Zero refs/heads/main $second" } + 'UnknownRemote' { "refs/heads/main $second refs/heads/main $script:Sha" } + } + Push-Location $root + try { + $output = "$line`n" | & $script:Sh $script:Hook origin 'https://example.invalid/repo' 2>&1 | Out-String + [pscustomobject]@{ Code = $LASTEXITCODE; Output = $output } + } + finally { Pop-Location; Remove-Item -LiteralPath $root -Recurse -Force -ErrorAction SilentlyContinue } + } + $script:OptIn = '{ "git": { "allowTrunkPush": true } }' + } + + It 'allows a fast-forward of main and says which setting allowed it' -Skip:($script:NoSh -or $script:NoPwshHere) { + $r = Invoke-TrunkPush -Json $script:OptIn -Kind FastForward + $r.Code | Should -Be 0 -Because $r.Output + $r.Output | Should -Match 'git.allowTrunkPush in aisdlc.json allows this fast-forward of main' + } + + It 'refuses a of main' -Skip:($script:NoSh -or $script:NoPwshHere) -ForEach @( + @{ Kind = 'Rewrite'; Reason = 'not a force push' } + @{ Kind = 'Delete'; Reason = 'not a delete' } + @{ Kind = 'UnknownRemote'; Reason = 'Fetch first' } + ) { + $r = Invoke-TrunkPush -Json $script:OptIn -Kind $Kind + $r.Code | Should -Be 1 + $r.Output | Should -Match $Reason + } + + It 'still refuses a fast-forward when the setting is ' -Skip:($script:NoSh -or $script:NoPwshHere) -ForEach @( + @{ Name = 'missing'; Json = '{}' } + @{ Name = 'the string "true"'; Json = '{ "git": { "allowTrunkPush": "true" } }' } + ) { + $r = Invoke-TrunkPush -Json $Json -Kind FastForward + $r.Code | Should -Be 1 + $r.Output | Should -Match 'a push to main is refused' + } + } + It 'never falls back to Windows PowerShell, which cannot run a gate that needs PowerShell 7' { foreach ($name in 'pre-push', 'graphify-refresh') { $text = Get-Content -LiteralPath (Join-Path $PSScriptRoot '..' 'githooks' $name) -Raw diff --git a/core/apm.yml b/core/apm.yml index 67577ca..e1afdc7 100644 --- a/core/apm.yml +++ b/core/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-core -version: "1.2.0" +version: "1.3.0" description: The AI-SDLC core for every repository - workflow skills, review agents, hooks, core gates and the handbook. diff --git a/packs/bicep/apm.yml b/packs/bicep/apm.yml index c7f228c..c1ac72e 100644 --- a/packs/bicep/apm.yml +++ b/packs/bicep/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-bicep -version: "1.2.0" +version: "1.3.0" description: The Bicep pack - Bicep conventions for infrastructure templates. diff --git a/packs/blazor/apm.yml b/packs/blazor/apm.yml index 3bd8572..43124e6 100644 --- a/packs/blazor/apm.yml +++ b/packs/blazor/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-blazor -version: "1.2.0" +version: "1.3.0" description: The Blazor pack - portal UI conventions, component authorization and the Razor gates. diff --git a/packs/discovery/apm.yml b/packs/discovery/apm.yml index ad872ca..8144e4d 100644 --- a/packs/discovery/apm.yml +++ b/packs/discovery/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-discovery -version: "1.2.0" +version: "1.3.0" description: The discovery pack - the discovery workflows that write a research summary, a journey map and a hypothesis canvas as markdown files in the repository. diff --git a/packs/dotnet/apm.yml b/packs/dotnet/apm.yml index b4b8d41..a490cde 100644 --- a/packs/dotnet/apm.yml +++ b/packs/dotnet/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-dotnet -version: "1.2.0" +version: "1.3.0" description: The .NET pack - C# conventions, test-first, the .NET gates and the code graph. diff --git a/packs/github-issues/apm.yml b/packs/github-issues/apm.yml index 8133401..5cd691b 100644 --- a/packs/github-issues/apm.yml +++ b/packs/github-issues/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-github-issues -version: "1.2.0" +version: "1.3.0" description: The GitHub Issues pack - issue conventions and the issue contract gates. diff --git a/packs/github/.apm/skills/github-pull-requests/SKILL.md b/packs/github/.apm/skills/github-pull-requests/SKILL.md index c2d1d10..c42530e 100644 --- a/packs/github/.apm/skills/github-pull-requests/SKILL.md +++ b/packs/github/.apm/skills/github-pull-requests/SKILL.md @@ -20,7 +20,7 @@ Use this at the PR preflight and at the end of the loop. `implement`, `refactor` `write-platform-note`, `write-pipeline`, `write-prd`, `write-hypothesis`, `draw-customer-journey` and `write-research-summary` load it before they push, and `fix-bug` through `implement`. After a standalone run, `write-adr`, `update-constitution`, `write-docs`, `add-gate`, `capture-learning` and `write-api-spec` load it too. The push and the pull request run with no prompt. Checkpoint Bravo is the person's review of the pull request on GitHub ([orchestration.md](/.claude/skills/ai-sdlc-handbook/references/orchestration.md)). -A push to `main` or `master` is always refused. The link from the PR to its story is a tracker update, so it joins the +A push to `main` or `master` is refused, unless the repository sets `git.allowTrunkPush` in `aisdlc.json`. The link from the PR to its story is a tracker update, so it joins the one list of tracker updates for the run. The agent opens the pull request as a request for review; it never approves, reviews with approval, or merges one (C09). A hook refuses `gh pr merge` and a merge call through `gh api`. diff --git a/packs/github/apm.yml b/packs/github/apm.yml index d6ea747..c892d1f 100644 --- a/packs/github/apm.yml +++ b/packs/github/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-github -version: "1.2.0" +version: "1.3.0" description: The GitHub pack - pull requests, review threads, pull request delivery metrics and the GitHub Actions workflows. diff --git a/packs/knowledge/apm.yml b/packs/knowledge/apm.yml index 92e0efe..f125836 100644 --- a/packs/knowledge/apm.yml +++ b/packs/knowledge/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-knowledge -version: "1.2.0" +version: "1.3.0" description: The knowledge pack - the conventions and the workflow for platform knowledge notes in the knowledge repository. diff --git a/packs/sonarcloud/apm.yml b/packs/sonarcloud/apm.yml index 35e8520..ecff446 100644 --- a/packs/sonarcloud/apm.yml +++ b/packs/sonarcloud/apm.yml @@ -1,5 +1,5 @@ name: ai-sdlc-sonarcloud -version: "1.2.0" +version: "1.3.0" description: The SonarQube Cloud pack - the SonarQube MCP server for the agent session, and the gate that keeps the token and the organization out of the repository. dependencies: mcp: From b35adb1f4dfdbe93535ce3d8e7396fac9cc74805 Mon Sep 17 00:00:00 2001 From: Rob Hofmann Date: Mon, 9 Nov 2026 02:36:54 +0100 Subject: [PATCH 2/6] Check every push in a command, and refuse an unsafe push to main under git.allowTrunkPush The agent hook now judges each push in a command, so a second push in a chain cannot reach main unseen. With git.allowTrunkPush it refuses --no-verify, a git option before push other than -C, and a push to main chained with other commands. Plain words in the docs, the hooks skill back under its size limit, and the lock file at 1.3.0. Refs #16 --- .../skills/ai-sdlc-gates/sync-manifest.json | 10 ++-- .../ai-sdlc-handbook/references/layout.md | 2 +- .../references/orchestration.md | 2 +- .claude/skills/ai-sdlc-hooks/SKILL.md | 8 ++-- .../scripts/Deny-IncompletePush.Tests.ps1 | 13 +++++ .../scripts/Deny-IncompletePush.ps1 | 48 ++++++++++++------- CHANGELOG.md | 6 ++- apm.lock.yaml | 32 ++++++------- .../skills/ai-sdlc-gates/sync-manifest.json | 10 ++-- .../ai-sdlc-handbook/references/layout.md | 2 +- .../references/orchestration.md | 2 +- core/.apm/skills/ai-sdlc-hooks/SKILL.md | 8 ++-- .../scripts/Deny-IncompletePush.Tests.ps1 | 13 +++++ .../scripts/Deny-IncompletePush.ps1 | 48 ++++++++++++------- 14 files changed, 126 insertions(+), 78 deletions(-) diff --git a/.claude/skills/ai-sdlc-gates/sync-manifest.json b/.claude/skills/ai-sdlc-gates/sync-manifest.json index 5a57ce5..b8b70ca 100644 --- a/.claude/skills/ai-sdlc-gates/sync-manifest.json +++ b/.claude/skills/ai-sdlc-gates/sync-manifest.json @@ -114,9 +114,9 @@ ".claude/skills/ai-sdlc-handbook/references/docs-wiki.md": "038477c9b704a5b545decfe5e3f3f9970d8d1f9d", ".claude/skills/ai-sdlc-handbook/references/first-story.md": "be899eb395dafb2d704b8f0cb46bac1fb5e593c8", ".claude/skills/ai-sdlc-handbook/references/language.md": "ca703edeb9e07e28e32a39fbcc9116b64db444d8", - ".claude/skills/ai-sdlc-handbook/references/layout.md": "b5c6ed0e19978057a68dbf7d18ccb261def0846a", + ".claude/skills/ai-sdlc-handbook/references/layout.md": "1c7fd6a6eaca9256c87810dcdf6bc8ee36052e08", ".claude/skills/ai-sdlc-handbook/references/node-templates.md": "580c9c92c470a6abbaa0145cc3060ff1a11d247c", - ".claude/skills/ai-sdlc-handbook/references/orchestration.md": "fd693b640ad3cebfa7d12804c56290b036beb9bb", + ".claude/skills/ai-sdlc-handbook/references/orchestration.md": "22373827d6ecd454d93cfb652f76c5204f3215e2", ".claude/skills/ai-sdlc-handbook/references/pattern.md": "f0f2a8cf3dac267cda0fd3783d86bddba5afc7c0", ".claude/skills/ai-sdlc-handbook/references/personas.md": "083c57f3e4e88519a9d42d7e51559c5165faacff", ".claude/skills/ai-sdlc-handbook/references/plan.md": "8c6fde8e741106f8fe625b8b9a4e98b6d5ba912f", @@ -135,8 +135,8 @@ ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "ef5b30f0811181462d354a61d3e64c19f0c305e2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "27c563f6fe7139ae1de16320c4e477b7c5e24e73", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "08f8eb7056942cbc459ecb8bff8a73d004d772c4", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "b7d9b30fe95de0dbc3854bfcc857519a80164462", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "ab703afb6d25cfb03e4b52c10f7cdcc9cbb791ef", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1": "ca703a9e057633e39af161d9e43a042429813acc", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1": "d15bf28d4191b5e2bca8ce59621ad03a1ef6198c", ".claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.ps1": "da6172d61799df3f37c5f70a103cddddb5517cb0", @@ -161,7 +161,7 @@ ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1": "8db305e438bc7ee404eb5106eacbe5581738f148", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.ps1": "fa3d7f509b6f9a1a935178c1eaf0d1566b7afead", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.Tests.ps1": "21a220ca2ccc65a56ec427a6e74c5a5dbfbfd4ef", - ".claude/skills/ai-sdlc-hooks/SKILL.md": "405f4ecc88e513cda8b8d5361d1329d2a74dbc91", + ".claude/skills/ai-sdlc-hooks/SKILL.md": "a5b99bcdf6bf93721136ee3a3e7075632fdf068d", ".claude/skills/capture-learning/SKILL.md": "32300ce3189109b0d717f975623e8d7ccec1c821", ".claude/skills/convene-personas/SKILL.md": "449708a02206bec35a83d2f48ca6366c8b78e3a2", ".claude/skills/docs-wiki-conventions/SKILL.md": "0679512fa39815b63da6373ff29bb6eadc52ff24", diff --git a/.claude/skills/ai-sdlc-handbook/references/layout.md b/.claude/skills/ai-sdlc-handbook/references/layout.md index b5c6ed0..1c7fd6a 100644 --- a/.claude/skills/ai-sdlc-handbook/references/layout.md +++ b/.claude/skills/ai-sdlc-handbook/references/layout.md @@ -129,7 +129,7 @@ installs. `AiSdlcConfig.psm1` takes each dependency whose path ends in `packs/[^;&|]*)") - if (-not $push.Success) { return $false } - $all = @($push.Groups['rest'].Value.Trim() -split '\s+' | Where-Object { $_ } | ForEach-Object { $_ -replace '[''"]', '' }) - if (@($all | Where-Object { $_ -in @('--all', '--mirror', '--branches') }).Count -gt 0) { return $true } - $words = @($all | Where-Object { -not $_.StartsWith('-') }) - $refspecs = @($words | Select-Object -Skip 1) - if ($refspecs.Count -eq 0) { return $Branch -in $protectedBranches } - foreach ($refspec in $refspecs) { - $target = ($refspec.TrimStart('+') -split ':')[-1] -replace '^refs/heads/', '' - if ($target -in $protectedBranches) { return $true } - if ($target -eq 'HEAD' -and $Branch -in $protectedBranches) { return $true } + # Every push in the command counts, so a second push in a chain cannot reach main unseen. + foreach ($push in [regex]::Matches($CommandLine, "$gitPrefix\s+push(?[^;&|]*)")) { + $all = @($push.Groups['rest'].Value.Trim() -split '\s+' | Where-Object { $_ } | ForEach-Object { $_ -replace '[''"]', '' }) + if (@($all | Where-Object { $_ -in @('--all', '--mirror', '--branches') }).Count -gt 0) { return $true } + $words = @($all | Where-Object { -not $_.StartsWith('-') }) + $refspecs = @($words | Select-Object -Skip 1) + if ($refspecs.Count -eq 0) { + if ($Branch -in $protectedBranches) { return $true } + continue + } + foreach ($refspec in $refspecs) { + $target = ($refspec.TrimStart('+') -split ':')[-1] -replace '^refs/heads/', '' + if ($target -in $protectedBranches) { return $true } + if ($target -eq 'HEAD' -and $Branch -in $protectedBranches) { return $true } + } } return $false } function Test-RewritesBranch { - # True when the push may delete or rewrite a branch: a force option, a +refspec, a delete, or a - # push of every branch. Only a push without any of these may update the trunk under git.allowTrunkPush. + # True when the push may delete or rewrite a branch, or when the hook cannot judge it: a force option, + # a +refspec, a delete, a push of every branch, --no-verify (which skips the pre-push git hook), a git + # option before push other than -C, or a command that holds anything besides this one push. Only a + # plain push that is the whole command may update the trunk under git.allowTrunkPush. param([string]$CommandLine) - $push = [regex]::Match($CommandLine, "$gitPrefix\s+push(?[^;&|]*)") + $single = $CommandLine.Trim() -replace '\s+2>&1(?:\s*\|\s*(?i:Out-String))?$', '' + if ($single -match '[;&|<>\r\n`]|\$\(') { return $true } + if ([regex]::Matches($single, '(?:^|\s)' + $gitName + '(?:\s|$)').Count -ne 1) { return $true } + $push = [regex]::Match($single, '^&?\s*' + $gitName + '(?:\s+-C\s+(?:"[^"]*"|''[^'']*''|\S+))?\s+push(?(?:\s.*)?)$') if (-not $push.Success) { return $true } $all = @($push.Groups['rest'].Value.Trim() -split '\s+' | Where-Object { $_ } | ForEach-Object { $_ -replace '[''"]', '' }) foreach ($word in $all) { - if ($word -in @('-f', '--all', '--mirror', '--branches', '--prune', '-d', '--delete')) { return $true } + if ($word -in @('-f', '--all', '--mirror', '--branches', '--prune', '-d', '--delete', '--no-verify')) { return $true } if ($word -like '--force*') { return $true } if ($word.StartsWith('-') -and -not $word.StartsWith('--') -and $word -match 'f|d') { return $true } } @@ -328,7 +339,8 @@ if (Test-TargetsProtectedBranch -CommandLine $command -Branch ([string]$CurrentB } if (Test-RewritesBranch -CommandLine $command) { Write-Deny ('git.allowTrunkPush in aisdlc.json allows a plain push to main or master, not a force push, a ' + - 'delete, or a push of every branch. Push the trunk on its own, without those options.') + 'delete, a push of every branch, --no-verify, a git option before push, or a push chained with other ' + + 'commands. Run the push of main on its own, as git push [remote] [branch].') exit 0 } } diff --git a/CHANGELOG.md b/CHANGELOG.md index 263d1a4..fbac36d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,10 @@ Each entry names its issue, as `#42`. - A repository can set `git.allowTrunkPush` to `true` in `aisdlc.json` to update `main` or `master` with a plain push, without a pull request (#16). The pre-push git hook and `Deny-IncompletePush.ps1` - still refuse a delete and a force push of the trunk, and the blocking gates still run. The git hook - prints one line that names the setting when it lets a push through. + still refuse a delete and a force push of `main`, and the blocking gates still run. The git hook + prints one line that names the setting when it lets a push through. The agent hook now checks every + push in a command, and with the setting it refuses `--no-verify`, a git option before `push`, and a + push to `main` that is chained with other commands. ## v1.2.0 - 2026-11-07 diff --git a/apm.lock.yaml b/apm.lock.yaml index e14fc23..e4b0dd0 100644 --- a/apm.lock.yaml +++ b/apm.lock.yaml @@ -3,7 +3,7 @@ apm_version: 0.31.0 dependencies: - repo_url: _local/core name: ai-sdlc-core - version: 1.2.0 + version: 1.3.0 package_type: apm_package deployed_files: - .claude/agents/architect.md @@ -331,7 +331,7 @@ dependencies: .claude/skills/ai-sdlc-gates/scripts/gitleaks-rules.json: sha256:6a8a75c5dbcf2378a1c52d046e34ce275aac7ce08a0ae61408d25c18e1e27014 .claude/skills/ai-sdlc-gates/scripts/gitleaks-version.json: sha256:c54acb854f87a1bbdf0e90c670b72b5de3cd37f7e460d82eca599c3c7af23a84 .claude/skills/ai-sdlc-gates/skill-catalog.json: sha256:5537684656bf189a740ba7e9e7050083af05668d00501ce1e9c6909cb8b91203 - .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:c259e68badb668435176e2c300fdce7a8042cba028d4a3113d7d5b4bebe7af14 + .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:7931f8a164d131c90e9522d72f875afa1657632772986c6104298c8d1fa05f22 .claude/skills/ai-sdlc-handbook/SKILL.md: sha256:548e6b9ad79d3d2afa2f5779835988eeb12c49cda08917c4bbaa9ac0486a47a0 .claude/skills/ai-sdlc-handbook/references/README.md: sha256:654afcaa2b81f560eff93dbdef521b09ced06137a1dbb85d70a4e14ef7502248 .claude/skills/ai-sdlc-handbook/references/artifact-graph.md: sha256:d7ddfe20e5ee6565bcf25f9cef0f578da2a4ab1590033d791b8814d4688fd1f0 @@ -343,14 +343,14 @@ dependencies: .claude/skills/ai-sdlc-handbook/references/docs-wiki.md: sha256:2bd6f3a8e64f9db16163519767b822e4ebcffd740e3c5cbff17281ad71d264b7 .claude/skills/ai-sdlc-handbook/references/first-story.md: sha256:831552230cc16386ee01d7c730e288ef19aca5a66fafb00e1dfbbf4e9788caf2 .claude/skills/ai-sdlc-handbook/references/language.md: sha256:e0e32fae9c9fcdd23380d92ec910128254ce248538940541f5789ca78228a023 - .claude/skills/ai-sdlc-handbook/references/layout.md: sha256:46beddc0c816665a24a55cf24de14ac3f14aa55a776e7de108d943d9ea5fb642 + .claude/skills/ai-sdlc-handbook/references/layout.md: sha256:4ac735eea3800a51727efd56ca61f3ed4137c8cca960da5b74f21d1115e78f63 .claude/skills/ai-sdlc-handbook/references/node-templates.md: sha256:8664ad1f85bff48d6230ed22e3f25683f378822e566c2a1454cbb204f4bb8fad - .claude/skills/ai-sdlc-handbook/references/orchestration.md: sha256:7fa9639a0f172d98aa6dc198dc9995749c1321c08488c4929485fe8f6a8fff97 + .claude/skills/ai-sdlc-handbook/references/orchestration.md: sha256:6a1d6b6cc434f2e312994bd77daaa1fef4e007e03777ac63f3ca74edaa0cc485 .claude/skills/ai-sdlc-handbook/references/pattern.md: sha256:7908f80ee28ff1f7cd9f85b22fcf3e455fe74225d33ff201f8fbce1623d672eb .claude/skills/ai-sdlc-handbook/references/personas.md: sha256:7913c3dca6bad93b45624349a12bf976f894eb6ca05c7baa1fa7e3ba802ca69a .claude/skills/ai-sdlc-handbook/references/plan.md: sha256:b632fe2da2369f494ebe2606c4bdc8726eabe3b7615b6ddb0b58fa9b3897a216 .claude/skills/ai-sdlc-handbook/references/skill-usage.md: sha256:9d5414b38d9d6f5bd7dfa9857e8e441bf040b0020f46ac8d3b29b0a476161c61 - .claude/skills/ai-sdlc-hooks/SKILL.md: sha256:2874ddb81894e253ff335649672acee9c1578962357c8b849963c4193e220547 + .claude/skills/ai-sdlc-hooks/SKILL.md: sha256:2b7cddccaff175fd0ffd44524dfddc2b1894f74c1fbdf91d02659573a25b07f8 .claude/skills/ai-sdlc-hooks/gates.json: sha256:dfc8b0003e930167e0fccc366867f423bc0850f3c69477c0e7119aed710bf902 .claude/skills/ai-sdlc-hooks/githooks/git-lfs-hook: sha256:3265310500749e7181a5625517f94e2efa62d48be987ebc9b0396d38e2eeffa6 .claude/skills/ai-sdlc-hooks/githooks/graphify-refresh: sha256:1bc6c7f181aab3a0fdd34bf8907a4884bea2412a56ebdc77a673707e17c046f3 @@ -363,8 +363,8 @@ dependencies: .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1: sha256:b3569de6e27c3dcaffbc082311e6882bd722d440e5e855245da2410033202c7e .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1: sha256:4c4e1f6b673671125290d78815c72277665a8a618b55fd589f75f3a36e3b80aa .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1: sha256:46d1d83e38e75db41b1f370bc6f49f4800f0234765eac63c53e37b5af7000453 - .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1: sha256:e5e9ac9b062db0ee474e545a6248ec5aff3bd0b95801ef3ade59072adcc53889 - .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1: sha256:114309237becb627f5847187057717d90fbd031ebffcedc74406d3ec58f5f762 + .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1: sha256:410738323ed709a4c1e41018001177902ede76bd9f2875852a34cfc23fdadca3 + .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1: sha256:68c6409ed97e1547c5eb9688e4266487604fd992dc77a29e8da62f8b82afbfa1 .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1: sha256:1c46576b9633bd12286efa11cc9f7c6c2f982f29859f9a33272f76452888e77b .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1: sha256:fccaa2da3a0254cc8a7740974f07b1c0fc1e67106ae7191d9710cbf699da1ba7 .claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.Tests.ps1: sha256:151c3ee69c88db0d85cf4c94207b04dfc4eabe857e178051044ed4fdcee58f33 @@ -427,7 +427,7 @@ dependencies: local_path: ./core - repo_url: _local/discovery name: ai-sdlc-discovery - version: 1.2.0 + version: 1.3.0 package_type: apm_package deployed_files: - .claude/skills/draw-customer-journey @@ -444,7 +444,7 @@ dependencies: local_path: ./packs/discovery - repo_url: _local/github name: ai-sdlc-github - version: 1.2.0 + version: 1.3.0 package_type: apm_package deployed_files: - .claude/skills/fix-pr-feedback @@ -534,7 +534,7 @@ dependencies: local_path: ./packs/github - repo_url: _local/github-issues name: ai-sdlc-github-issues - version: 1.2.0 + version: 1.3.0 package_type: apm_package deployed_files: - .claude/agents/draft-reviewer.md @@ -1551,7 +1551,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:c259e68badb668435176e2c300fdce7a8042cba028d4a3113d7d5b4bebe7af14 + content_hash: sha256:7931f8a164d131c90e9522d72f875afa1657632772986c6104298c8d1fa05f22 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook @@ -1668,7 +1668,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:46beddc0c816665a24a55cf24de14ac3f14aa55a776e7de108d943d9ea5fb642 + content_hash: sha256:4ac735eea3800a51727efd56ca61f3ed4137c8cca960da5b74f21d1115e78f63 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook/references/node-templates.md @@ -1686,7 +1686,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:7fa9639a0f172d98aa6dc198dc9995749c1321c08488c4929485fe8f6a8fff97 + content_hash: sha256:6a1d6b6cc434f2e312994bd77daaa1fef4e007e03777ac63f3ca74edaa0cc485 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook/references/pattern.md @@ -1740,7 +1740,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:2874ddb81894e253ff335649672acee9c1578962357c8b849963c4193e220547 + content_hash: sha256:2b7cddccaff175fd0ffd44524dfddc2b1894f74c1fbdf91d02659573a25b07f8 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/gates.json @@ -1857,7 +1857,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:e5e9ac9b062db0ee474e545a6248ec5aff3bd0b95801ef3ade59072adcc53889 + content_hash: sha256:410738323ed709a4c1e41018001177902ede76bd9f2875852a34cfc23fdadca3 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -1866,7 +1866,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:114309237becb627f5847187057717d90fbd031ebffcedc74406d3ec58f5f762 + content_hash: sha256:68c6409ed97e1547c5eb9688e4266487604fd992dc77a29e8da62f8b82afbfa1 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1 diff --git a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json index 5a57ce5..b8b70ca 100644 --- a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json +++ b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json @@ -114,9 +114,9 @@ ".claude/skills/ai-sdlc-handbook/references/docs-wiki.md": "038477c9b704a5b545decfe5e3f3f9970d8d1f9d", ".claude/skills/ai-sdlc-handbook/references/first-story.md": "be899eb395dafb2d704b8f0cb46bac1fb5e593c8", ".claude/skills/ai-sdlc-handbook/references/language.md": "ca703edeb9e07e28e32a39fbcc9116b64db444d8", - ".claude/skills/ai-sdlc-handbook/references/layout.md": "b5c6ed0e19978057a68dbf7d18ccb261def0846a", + ".claude/skills/ai-sdlc-handbook/references/layout.md": "1c7fd6a6eaca9256c87810dcdf6bc8ee36052e08", ".claude/skills/ai-sdlc-handbook/references/node-templates.md": "580c9c92c470a6abbaa0145cc3060ff1a11d247c", - ".claude/skills/ai-sdlc-handbook/references/orchestration.md": "fd693b640ad3cebfa7d12804c56290b036beb9bb", + ".claude/skills/ai-sdlc-handbook/references/orchestration.md": "22373827d6ecd454d93cfb652f76c5204f3215e2", ".claude/skills/ai-sdlc-handbook/references/pattern.md": "f0f2a8cf3dac267cda0fd3783d86bddba5afc7c0", ".claude/skills/ai-sdlc-handbook/references/personas.md": "083c57f3e4e88519a9d42d7e51559c5165faacff", ".claude/skills/ai-sdlc-handbook/references/plan.md": "8c6fde8e741106f8fe625b8b9a4e98b6d5ba912f", @@ -135,8 +135,8 @@ ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "ef5b30f0811181462d354a61d3e64c19f0c305e2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "27c563f6fe7139ae1de16320c4e477b7c5e24e73", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "08f8eb7056942cbc459ecb8bff8a73d004d772c4", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "b7d9b30fe95de0dbc3854bfcc857519a80164462", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "ab703afb6d25cfb03e4b52c10f7cdcc9cbb791ef", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1": "ca703a9e057633e39af161d9e43a042429813acc", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1": "d15bf28d4191b5e2bca8ce59621ad03a1ef6198c", ".claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.ps1": "da6172d61799df3f37c5f70a103cddddb5517cb0", @@ -161,7 +161,7 @@ ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1": "8db305e438bc7ee404eb5106eacbe5581738f148", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.ps1": "fa3d7f509b6f9a1a935178c1eaf0d1566b7afead", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.Tests.ps1": "21a220ca2ccc65a56ec427a6e74c5a5dbfbfd4ef", - ".claude/skills/ai-sdlc-hooks/SKILL.md": "405f4ecc88e513cda8b8d5361d1329d2a74dbc91", + ".claude/skills/ai-sdlc-hooks/SKILL.md": "a5b99bcdf6bf93721136ee3a3e7075632fdf068d", ".claude/skills/capture-learning/SKILL.md": "32300ce3189109b0d717f975623e8d7ccec1c821", ".claude/skills/convene-personas/SKILL.md": "449708a02206bec35a83d2f48ca6366c8b78e3a2", ".claude/skills/docs-wiki-conventions/SKILL.md": "0679512fa39815b63da6373ff29bb6eadc52ff24", diff --git a/core/.apm/skills/ai-sdlc-handbook/references/layout.md b/core/.apm/skills/ai-sdlc-handbook/references/layout.md index b5c6ed0..1c7fd6a 100644 --- a/core/.apm/skills/ai-sdlc-handbook/references/layout.md +++ b/core/.apm/skills/ai-sdlc-handbook/references/layout.md @@ -129,7 +129,7 @@ installs. `AiSdlcConfig.psm1` takes each dependency whose path ends in `packs/[^;&|]*)") - if (-not $push.Success) { return $false } - $all = @($push.Groups['rest'].Value.Trim() -split '\s+' | Where-Object { $_ } | ForEach-Object { $_ -replace '[''"]', '' }) - if (@($all | Where-Object { $_ -in @('--all', '--mirror', '--branches') }).Count -gt 0) { return $true } - $words = @($all | Where-Object { -not $_.StartsWith('-') }) - $refspecs = @($words | Select-Object -Skip 1) - if ($refspecs.Count -eq 0) { return $Branch -in $protectedBranches } - foreach ($refspec in $refspecs) { - $target = ($refspec.TrimStart('+') -split ':')[-1] -replace '^refs/heads/', '' - if ($target -in $protectedBranches) { return $true } - if ($target -eq 'HEAD' -and $Branch -in $protectedBranches) { return $true } + # Every push in the command counts, so a second push in a chain cannot reach main unseen. + foreach ($push in [regex]::Matches($CommandLine, "$gitPrefix\s+push(?[^;&|]*)")) { + $all = @($push.Groups['rest'].Value.Trim() -split '\s+' | Where-Object { $_ } | ForEach-Object { $_ -replace '[''"]', '' }) + if (@($all | Where-Object { $_ -in @('--all', '--mirror', '--branches') }).Count -gt 0) { return $true } + $words = @($all | Where-Object { -not $_.StartsWith('-') }) + $refspecs = @($words | Select-Object -Skip 1) + if ($refspecs.Count -eq 0) { + if ($Branch -in $protectedBranches) { return $true } + continue + } + foreach ($refspec in $refspecs) { + $target = ($refspec.TrimStart('+') -split ':')[-1] -replace '^refs/heads/', '' + if ($target -in $protectedBranches) { return $true } + if ($target -eq 'HEAD' -and $Branch -in $protectedBranches) { return $true } + } } return $false } function Test-RewritesBranch { - # True when the push may delete or rewrite a branch: a force option, a +refspec, a delete, or a - # push of every branch. Only a push without any of these may update the trunk under git.allowTrunkPush. + # True when the push may delete or rewrite a branch, or when the hook cannot judge it: a force option, + # a +refspec, a delete, a push of every branch, --no-verify (which skips the pre-push git hook), a git + # option before push other than -C, or a command that holds anything besides this one push. Only a + # plain push that is the whole command may update the trunk under git.allowTrunkPush. param([string]$CommandLine) - $push = [regex]::Match($CommandLine, "$gitPrefix\s+push(?[^;&|]*)") + $single = $CommandLine.Trim() -replace '\s+2>&1(?:\s*\|\s*(?i:Out-String))?$', '' + if ($single -match '[;&|<>\r\n`]|\$\(') { return $true } + if ([regex]::Matches($single, '(?:^|\s)' + $gitName + '(?:\s|$)').Count -ne 1) { return $true } + $push = [regex]::Match($single, '^&?\s*' + $gitName + '(?:\s+-C\s+(?:"[^"]*"|''[^'']*''|\S+))?\s+push(?(?:\s.*)?)$') if (-not $push.Success) { return $true } $all = @($push.Groups['rest'].Value.Trim() -split '\s+' | Where-Object { $_ } | ForEach-Object { $_ -replace '[''"]', '' }) foreach ($word in $all) { - if ($word -in @('-f', '--all', '--mirror', '--branches', '--prune', '-d', '--delete')) { return $true } + if ($word -in @('-f', '--all', '--mirror', '--branches', '--prune', '-d', '--delete', '--no-verify')) { return $true } if ($word -like '--force*') { return $true } if ($word.StartsWith('-') -and -not $word.StartsWith('--') -and $word -match 'f|d') { return $true } } @@ -328,7 +339,8 @@ if (Test-TargetsProtectedBranch -CommandLine $command -Branch ([string]$CurrentB } if (Test-RewritesBranch -CommandLine $command) { Write-Deny ('git.allowTrunkPush in aisdlc.json allows a plain push to main or master, not a force push, a ' + - 'delete, or a push of every branch. Push the trunk on its own, without those options.') + 'delete, a push of every branch, --no-verify, a git option before push, or a push chained with other ' + + 'commands. Run the push of main on its own, as git push [remote] [branch].') exit 0 } } From b65bc80be62a7a95b4d528f3df0649ce4596133e Mon Sep 17 00:00:00 2001 From: Rob Hofmann Date: Mon, 9 Nov 2026 02:41:35 +0100 Subject: [PATCH 3/6] Allow only a short list of push options on a push to main under git.allowTrunkPush git accepts a shortened long option, such as --dele for --delete, so the agent hook now allows only -u, -q, -v and a few long options written in full, and refuses every other option. Refs #16 --- .../skills/ai-sdlc-gates/sync-manifest.json | 4 ++-- .../scripts/Deny-IncompletePush.Tests.ps1 | 8 ++++++++ .../scripts/Deny-IncompletePush.ps1 | 19 +++++++++++++------ apm.lock.yaml | 12 ++++++------ .../skills/ai-sdlc-gates/sync-manifest.json | 4 ++-- .../scripts/Deny-IncompletePush.Tests.ps1 | 8 ++++++++ .../scripts/Deny-IncompletePush.ps1 | 19 +++++++++++++------ 7 files changed, 52 insertions(+), 22 deletions(-) diff --git a/.claude/skills/ai-sdlc-gates/sync-manifest.json b/.claude/skills/ai-sdlc-gates/sync-manifest.json index b8b70ca..c349b59 100644 --- a/.claude/skills/ai-sdlc-gates/sync-manifest.json +++ b/.claude/skills/ai-sdlc-gates/sync-manifest.json @@ -135,8 +135,8 @@ ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "ef5b30f0811181462d354a61d3e64c19f0c305e2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "b7d9b30fe95de0dbc3854bfcc857519a80164462", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "ab703afb6d25cfb03e4b52c10f7cdcc9cbb791ef", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "16b2a3b9b0e0286c542785eda4387dc3d1db3e6c", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "d801962e9efc387cc577b5b6db372aa2ff8fa9f5", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1": "ca703a9e057633e39af161d9e43a042429813acc", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1": "d15bf28d4191b5e2bca8ce59621ad03a1ef6198c", ".claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.ps1": "da6172d61799df3f37c5f70a103cddddb5517cb0", diff --git a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 index ab703af..d801962 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 @@ -257,6 +257,8 @@ exit 0 @{ Command = 'git push origin master' } @{ Command = 'git -C C:/repo push origin main' } @{ Command = 'git push origin main 2>&1' } + @{ Command = 'git push --set-upstream --follow-tags origin main' } + @{ Command = 'git push -uq origin main' } ) { $r = Invoke-OptedInHook -Command $Command $r.Output | Should -Not -Match 'permissionDecision' @@ -277,6 +279,12 @@ exit 0 @{ Command = 'git push origin main; git push origin :main' } @{ Command = 'git push origin main | tee out.txt' } @{ Command = 'git push $(echo origin) main' } + @{ Command = 'git push --dele origin main' } + @{ Command = 'git push --no-verif origin main' } + @{ Command = 'git push --forc origin main' } + @{ Command = 'git push --mirr origin' } + @{ Command = 'git push -uf origin main' } + @{ Command = 'git push --repo=other main' } ) { $r = Invoke-OptedInHook -Command $Command $r.Output | Should -Match '"permissionDecision":"deny"' diff --git a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 index b7d9b30..16b2a3b 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -28,9 +28,11 @@ Before the completeness check it refuses any push to main or master: a named target, a quoted one, HEAD while on main, a bare push while on main, and --all, --mirror or --branches. A repository that sets git.allowTrunkPush to true in aisdlc.json may update main or master directly, but only in a plain - push that is the whole command: a force push (-f, --force*, a +refspec), a delete (-d, --delete, - :main), --all, --mirror, --branches, --prune, --no-verify, a git option before push other than -C, - and a push chained with any other command stay refused. The rest of the checks still run on such a + push that is the whole command: a +refspec, a delete refspec (:main), any push option outside a short + allow list (-u, -q, -v, --set-upstream, --quiet, --verbose, --progress, --no-progress, --porcelain, + --atomic, --follow-tags, each written in full), a git option before push other than -C, and a push + chained with any other command stay refused. So --force, --delete, --mirror and --no-verify are refused, + also when shortened. The rest of the checks still run on such a push. A permission rule cannot see which branch a bare push targets, so this hook is the guard for Claude Code and Copilot CLI alike. It is registered for the Bash tool and for the PowerShell tool, because a repository @@ -238,10 +240,15 @@ function Test-RewritesBranch { $push = [regex]::Match($single, '^&?\s*' + $gitName + '(?:\s+-C\s+(?:"[^"]*"|''[^'']*''|\S+))?\s+push(?(?:\s.*)?)$') if (-not $push.Success) { return $true } $all = @($push.Groups['rest'].Value.Trim() -split '\s+' | Where-Object { $_ } | ForEach-Object { $_ -replace '[''"]', '' }) + # Options pass only from a short allow list, written in full. git accepts a shortened long option, + # such as --dele for --delete, so a deny list of names would miss one. + $safeLong = @('--set-upstream', '--quiet', '--verbose', '--progress', '--no-progress', '--porcelain', '--atomic', '--follow-tags') foreach ($word in $all) { - if ($word -in @('-f', '--all', '--mirror', '--branches', '--prune', '-d', '--delete', '--no-verify')) { return $true } - if ($word -like '--force*') { return $true } - if ($word.StartsWith('-') -and -not $word.StartsWith('--') -and $word -match 'f|d') { return $true } + if (-not $word.StartsWith('-')) { continue } + if ($word.StartsWith('--')) { + if ($word -notin $safeLong) { return $true } + } + elseif ($word -notmatch '^-[uqv]+$') { return $true } } $refspecs = @($all | Where-Object { -not $_.StartsWith('-') } | Select-Object -Skip 1) foreach ($refspec in $refspecs) { diff --git a/apm.lock.yaml b/apm.lock.yaml index e4b0dd0..813bd37 100644 --- a/apm.lock.yaml +++ b/apm.lock.yaml @@ -331,7 +331,7 @@ dependencies: .claude/skills/ai-sdlc-gates/scripts/gitleaks-rules.json: sha256:6a8a75c5dbcf2378a1c52d046e34ce275aac7ce08a0ae61408d25c18e1e27014 .claude/skills/ai-sdlc-gates/scripts/gitleaks-version.json: sha256:c54acb854f87a1bbdf0e90c670b72b5de3cd37f7e460d82eca599c3c7af23a84 .claude/skills/ai-sdlc-gates/skill-catalog.json: sha256:5537684656bf189a740ba7e9e7050083af05668d00501ce1e9c6909cb8b91203 - .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:7931f8a164d131c90e9522d72f875afa1657632772986c6104298c8d1fa05f22 + .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:b0ff0d55f4b76147c4b24bd91a6df38b51f188b6347c643b0ae5f5c636891361 .claude/skills/ai-sdlc-handbook/SKILL.md: sha256:548e6b9ad79d3d2afa2f5779835988eeb12c49cda08917c4bbaa9ac0486a47a0 .claude/skills/ai-sdlc-handbook/references/README.md: sha256:654afcaa2b81f560eff93dbdef521b09ced06137a1dbb85d70a4e14ef7502248 .claude/skills/ai-sdlc-handbook/references/artifact-graph.md: sha256:d7ddfe20e5ee6565bcf25f9cef0f578da2a4ab1590033d791b8814d4688fd1f0 @@ -363,8 +363,8 @@ dependencies: .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1: sha256:b3569de6e27c3dcaffbc082311e6882bd722d440e5e855245da2410033202c7e .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1: sha256:4c4e1f6b673671125290d78815c72277665a8a618b55fd589f75f3a36e3b80aa .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1: sha256:46d1d83e38e75db41b1f370bc6f49f4800f0234765eac63c53e37b5af7000453 - .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1: sha256:410738323ed709a4c1e41018001177902ede76bd9f2875852a34cfc23fdadca3 - .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1: sha256:68c6409ed97e1547c5eb9688e4266487604fd992dc77a29e8da62f8b82afbfa1 + .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1: sha256:3b60e8acbba450d078f6535b2173baefd91e473c926990f162e1ee23410eef5b + .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1: sha256:d68695e5221c253610946f5da7d36df2c0928461646eea038cfa786e3917c5f2 .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1: sha256:1c46576b9633bd12286efa11cc9f7c6c2f982f29859f9a33272f76452888e77b .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1: sha256:fccaa2da3a0254cc8a7740974f07b1c0fc1e67106ae7191d9710cbf699da1ba7 .claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.Tests.ps1: sha256:151c3ee69c88db0d85cf4c94207b04dfc4eabe857e178051044ed4fdcee58f33 @@ -1551,7 +1551,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:7931f8a164d131c90e9522d72f875afa1657632772986c6104298c8d1fa05f22 + content_hash: sha256:b0ff0d55f4b76147c4b24bd91a6df38b51f188b6347c643b0ae5f5c636891361 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook @@ -1857,7 +1857,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:410738323ed709a4c1e41018001177902ede76bd9f2875852a34cfc23fdadca3 + content_hash: sha256:3b60e8acbba450d078f6535b2173baefd91e473c926990f162e1ee23410eef5b - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -1866,7 +1866,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:68c6409ed97e1547c5eb9688e4266487604fd992dc77a29e8da62f8b82afbfa1 + content_hash: sha256:d68695e5221c253610946f5da7d36df2c0928461646eea038cfa786e3917c5f2 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1 diff --git a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json index b8b70ca..c349b59 100644 --- a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json +++ b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json @@ -135,8 +135,8 @@ ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "ef5b30f0811181462d354a61d3e64c19f0c305e2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "b7d9b30fe95de0dbc3854bfcc857519a80164462", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "ab703afb6d25cfb03e4b52c10f7cdcc9cbb791ef", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "16b2a3b9b0e0286c542785eda4387dc3d1db3e6c", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "d801962e9efc387cc577b5b6db372aa2ff8fa9f5", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1": "ca703a9e057633e39af161d9e43a042429813acc", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1": "d15bf28d4191b5e2bca8ce59621ad03a1ef6198c", ".claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.ps1": "da6172d61799df3f37c5f70a103cddddb5517cb0", diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 index ab703af..d801962 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 @@ -257,6 +257,8 @@ exit 0 @{ Command = 'git push origin master' } @{ Command = 'git -C C:/repo push origin main' } @{ Command = 'git push origin main 2>&1' } + @{ Command = 'git push --set-upstream --follow-tags origin main' } + @{ Command = 'git push -uq origin main' } ) { $r = Invoke-OptedInHook -Command $Command $r.Output | Should -Not -Match 'permissionDecision' @@ -277,6 +279,12 @@ exit 0 @{ Command = 'git push origin main; git push origin :main' } @{ Command = 'git push origin main | tee out.txt' } @{ Command = 'git push $(echo origin) main' } + @{ Command = 'git push --dele origin main' } + @{ Command = 'git push --no-verif origin main' } + @{ Command = 'git push --forc origin main' } + @{ Command = 'git push --mirr origin' } + @{ Command = 'git push -uf origin main' } + @{ Command = 'git push --repo=other main' } ) { $r = Invoke-OptedInHook -Command $Command $r.Output | Should -Match '"permissionDecision":"deny"' diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 index b7d9b30..16b2a3b 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -28,9 +28,11 @@ Before the completeness check it refuses any push to main or master: a named target, a quoted one, HEAD while on main, a bare push while on main, and --all, --mirror or --branches. A repository that sets git.allowTrunkPush to true in aisdlc.json may update main or master directly, but only in a plain - push that is the whole command: a force push (-f, --force*, a +refspec), a delete (-d, --delete, - :main), --all, --mirror, --branches, --prune, --no-verify, a git option before push other than -C, - and a push chained with any other command stay refused. The rest of the checks still run on such a + push that is the whole command: a +refspec, a delete refspec (:main), any push option outside a short + allow list (-u, -q, -v, --set-upstream, --quiet, --verbose, --progress, --no-progress, --porcelain, + --atomic, --follow-tags, each written in full), a git option before push other than -C, and a push + chained with any other command stay refused. So --force, --delete, --mirror and --no-verify are refused, + also when shortened. The rest of the checks still run on such a push. A permission rule cannot see which branch a bare push targets, so this hook is the guard for Claude Code and Copilot CLI alike. It is registered for the Bash tool and for the PowerShell tool, because a repository @@ -238,10 +240,15 @@ function Test-RewritesBranch { $push = [regex]::Match($single, '^&?\s*' + $gitName + '(?:\s+-C\s+(?:"[^"]*"|''[^'']*''|\S+))?\s+push(?(?:\s.*)?)$') if (-not $push.Success) { return $true } $all = @($push.Groups['rest'].Value.Trim() -split '\s+' | Where-Object { $_ } | ForEach-Object { $_ -replace '[''"]', '' }) + # Options pass only from a short allow list, written in full. git accepts a shortened long option, + # such as --dele for --delete, so a deny list of names would miss one. + $safeLong = @('--set-upstream', '--quiet', '--verbose', '--progress', '--no-progress', '--porcelain', '--atomic', '--follow-tags') foreach ($word in $all) { - if ($word -in @('-f', '--all', '--mirror', '--branches', '--prune', '-d', '--delete', '--no-verify')) { return $true } - if ($word -like '--force*') { return $true } - if ($word.StartsWith('-') -and -not $word.StartsWith('--') -and $word -match 'f|d') { return $true } + if (-not $word.StartsWith('-')) { continue } + if ($word.StartsWith('--')) { + if ($word -notin $safeLong) { return $true } + } + elseif ($word -notmatch '^-[uqv]+$') { return $true } } $refspecs = @($all | Where-Object { -not $_.StartsWith('-') } | Select-Object -Skip 1) foreach ($refspec in $refspecs) { From 738cd9e7b228822fd20ea60d2563fd447911b703 Mon Sep 17 00:00:00 2001 From: Rob Hofmann Date: Mon, 9 Nov 2026 02:48:00 +0100 Subject: [PATCH 4/6] Refuse a push word with shell escapes under git.allowTrunkPush A word that is not an option must be a plain remote or refspec name. A backslash, a dollar sign or a brace could hide an option from the check, as \--force reaches git as --force. Refs #16 --- .claude/skills/ai-sdlc-gates/sync-manifest.json | 4 ++-- .../scripts/Deny-IncompletePush.Tests.ps1 | 3 +++ .../ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 | 7 ++++++- apm.lock.yaml | 12 ++++++------ core/.apm/skills/ai-sdlc-gates/sync-manifest.json | 4 ++-- .../scripts/Deny-IncompletePush.Tests.ps1 | 3 +++ .../ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 | 7 ++++++- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.claude/skills/ai-sdlc-gates/sync-manifest.json b/.claude/skills/ai-sdlc-gates/sync-manifest.json index c349b59..a98cef2 100644 --- a/.claude/skills/ai-sdlc-gates/sync-manifest.json +++ b/.claude/skills/ai-sdlc-gates/sync-manifest.json @@ -135,8 +135,8 @@ ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "ef5b30f0811181462d354a61d3e64c19f0c305e2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "16b2a3b9b0e0286c542785eda4387dc3d1db3e6c", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "d801962e9efc387cc577b5b6db372aa2ff8fa9f5", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "735fa8ceacf1dad23abf09a59defaf1bcf40e874", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "e91541c0e0b50e140bb6b98b21410c0a22e96204", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1": "ca703a9e057633e39af161d9e43a042429813acc", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1": "d15bf28d4191b5e2bca8ce59621ad03a1ef6198c", ".claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.ps1": "da6172d61799df3f37c5f70a103cddddb5517cb0", diff --git a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 index d801962..e91541c 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 @@ -285,6 +285,9 @@ exit 0 @{ Command = 'git push --mirr origin' } @{ Command = 'git push -uf origin main' } @{ Command = 'git push --repo=other main' } + @{ Command = 'git push origin main \--force' } + @{ Command = 'git push origin main ${X}' } + @{ Command = 'git push origin main {--force,}' } ) { $r = Invoke-OptedInHook -Command $Command $r.Output | Should -Match '"permissionDecision":"deny"' diff --git a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 index 16b2a3b..735fa8c 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -244,7 +244,12 @@ function Test-RewritesBranch { # such as --dele for --delete, so a deny list of names would miss one. $safeLong = @('--set-upstream', '--quiet', '--verbose', '--progress', '--no-progress', '--porcelain', '--atomic', '--follow-tags') foreach ($word in $all) { - if (-not $word.StartsWith('-')) { continue } + # A remote or refspec holds only plain name characters. A backslash, $ or brace could hide an + # option from this check (\--force reaches git as --force), so such a word is refused. + if (-not $word.StartsWith('-')) { + if ($word -notmatch '^[A-Za-z0-9._/:@^~+-]+$') { return $true } + continue + } if ($word.StartsWith('--')) { if ($word -notin $safeLong) { return $true } } diff --git a/apm.lock.yaml b/apm.lock.yaml index 813bd37..67612a2 100644 --- a/apm.lock.yaml +++ b/apm.lock.yaml @@ -331,7 +331,7 @@ dependencies: .claude/skills/ai-sdlc-gates/scripts/gitleaks-rules.json: sha256:6a8a75c5dbcf2378a1c52d046e34ce275aac7ce08a0ae61408d25c18e1e27014 .claude/skills/ai-sdlc-gates/scripts/gitleaks-version.json: sha256:c54acb854f87a1bbdf0e90c670b72b5de3cd37f7e460d82eca599c3c7af23a84 .claude/skills/ai-sdlc-gates/skill-catalog.json: sha256:5537684656bf189a740ba7e9e7050083af05668d00501ce1e9c6909cb8b91203 - .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:b0ff0d55f4b76147c4b24bd91a6df38b51f188b6347c643b0ae5f5c636891361 + .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:d76ce5649ccda8b4ab92cab77661c855a5b3dbd40968aa5192d50939ea8ec9dd .claude/skills/ai-sdlc-handbook/SKILL.md: sha256:548e6b9ad79d3d2afa2f5779835988eeb12c49cda08917c4bbaa9ac0486a47a0 .claude/skills/ai-sdlc-handbook/references/README.md: sha256:654afcaa2b81f560eff93dbdef521b09ced06137a1dbb85d70a4e14ef7502248 .claude/skills/ai-sdlc-handbook/references/artifact-graph.md: sha256:d7ddfe20e5ee6565bcf25f9cef0f578da2a4ab1590033d791b8814d4688fd1f0 @@ -363,8 +363,8 @@ dependencies: .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1: sha256:b3569de6e27c3dcaffbc082311e6882bd722d440e5e855245da2410033202c7e .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1: sha256:4c4e1f6b673671125290d78815c72277665a8a618b55fd589f75f3a36e3b80aa .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1: sha256:46d1d83e38e75db41b1f370bc6f49f4800f0234765eac63c53e37b5af7000453 - .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1: sha256:3b60e8acbba450d078f6535b2173baefd91e473c926990f162e1ee23410eef5b - .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1: sha256:d68695e5221c253610946f5da7d36df2c0928461646eea038cfa786e3917c5f2 + .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1: sha256:20e41e5c86854c2a1752c02295a6040e050a6f9126a4e21699b9d850ff6708ac + .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1: sha256:01c095018cb97ec7b880b7781f330b94cd143580030be793894ade5a0f96b3a5 .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1: sha256:1c46576b9633bd12286efa11cc9f7c6c2f982f29859f9a33272f76452888e77b .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1: sha256:fccaa2da3a0254cc8a7740974f07b1c0fc1e67106ae7191d9710cbf699da1ba7 .claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.Tests.ps1: sha256:151c3ee69c88db0d85cf4c94207b04dfc4eabe857e178051044ed4fdcee58f33 @@ -1551,7 +1551,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:b0ff0d55f4b76147c4b24bd91a6df38b51f188b6347c643b0ae5f5c636891361 + content_hash: sha256:d76ce5649ccda8b4ab92cab77661c855a5b3dbd40968aa5192d50939ea8ec9dd - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook @@ -1857,7 +1857,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:3b60e8acbba450d078f6535b2173baefd91e473c926990f162e1ee23410eef5b + content_hash: sha256:20e41e5c86854c2a1752c02295a6040e050a6f9126a4e21699b9d850ff6708ac - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -1866,7 +1866,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:d68695e5221c253610946f5da7d36df2c0928461646eea038cfa786e3917c5f2 + content_hash: sha256:01c095018cb97ec7b880b7781f330b94cd143580030be793894ade5a0f96b3a5 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1 diff --git a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json index c349b59..a98cef2 100644 --- a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json +++ b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json @@ -135,8 +135,8 @@ ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "ef5b30f0811181462d354a61d3e64c19f0c305e2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "16b2a3b9b0e0286c542785eda4387dc3d1db3e6c", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "d801962e9efc387cc577b5b6db372aa2ff8fa9f5", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "735fa8ceacf1dad23abf09a59defaf1bcf40e874", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "e91541c0e0b50e140bb6b98b21410c0a22e96204", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1": "ca703a9e057633e39af161d9e43a042429813acc", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1": "d15bf28d4191b5e2bca8ce59621ad03a1ef6198c", ".claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.ps1": "da6172d61799df3f37c5f70a103cddddb5517cb0", diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 index d801962..e91541c 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 @@ -285,6 +285,9 @@ exit 0 @{ Command = 'git push --mirr origin' } @{ Command = 'git push -uf origin main' } @{ Command = 'git push --repo=other main' } + @{ Command = 'git push origin main \--force' } + @{ Command = 'git push origin main ${X}' } + @{ Command = 'git push origin main {--force,}' } ) { $r = Invoke-OptedInHook -Command $Command $r.Output | Should -Match '"permissionDecision":"deny"' diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 index 16b2a3b..735fa8c 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -244,7 +244,12 @@ function Test-RewritesBranch { # such as --dele for --delete, so a deny list of names would miss one. $safeLong = @('--set-upstream', '--quiet', '--verbose', '--progress', '--no-progress', '--porcelain', '--atomic', '--follow-tags') foreach ($word in $all) { - if (-not $word.StartsWith('-')) { continue } + # A remote or refspec holds only plain name characters. A backslash, $ or brace could hide an + # option from this check (\--force reaches git as --force), so such a word is refused. + if (-not $word.StartsWith('-')) { + if ($word -notmatch '^[A-Za-z0-9._/:@^~+-]+$') { return $true } + continue + } if ($word.StartsWith('--')) { if ($word -notin $safeLong) { return $true } } From 53f4fd6add4c4728b1b11e0934fcac6d71b19d02 Mon Sep 17 00:00:00 2001 From: Rob Hofmann Date: Mon, 9 Nov 2026 02:52:49 +0100 Subject: [PATCH 5/6] Read git.allowTrunkPush from the remote main branch, not the working tree Both push hooks now read the setting from aisdlc.json on the remote-tracking ref of the main branch they guard. An edit in the working tree cannot switch it on; the change that turns it on reaches main first. Refs #16 --- .../scripts/AiSdlcConfig.Tests.ps1 | 17 ++++++++++ .../ai-sdlc-gates/scripts/AiSdlcConfig.psm1 | 16 +++++++++- .../skills/ai-sdlc-gates/sync-manifest.json | 14 ++++---- .../ai-sdlc-handbook/references/layout.md | 2 +- .../skills/ai-sdlc-hooks/githooks/pre-push | 19 +++++------ .../scripts/Deny-IncompletePush.Tests.ps1 | 26 +++++++++++++++ .../scripts/Deny-IncompletePush.ps1 | 31 +++++++++++++++++- .../scripts/PrePushHook.Tests.ps1 | 16 ++++++++-- CHANGELOG.md | 4 ++- apm.lock.yaml | 32 +++++++++---------- .../scripts/AiSdlcConfig.Tests.ps1 | 17 ++++++++++ .../ai-sdlc-gates/scripts/AiSdlcConfig.psm1 | 16 +++++++++- .../skills/ai-sdlc-gates/sync-manifest.json | 14 ++++---- .../ai-sdlc-handbook/references/layout.md | 2 +- .../skills/ai-sdlc-hooks/githooks/pre-push | 19 +++++------ .../scripts/Deny-IncompletePush.Tests.ps1 | 26 +++++++++++++++ .../scripts/Deny-IncompletePush.ps1 | 31 +++++++++++++++++- .../scripts/PrePushHook.Tests.ps1 | 16 ++++++++-- 18 files changed, 259 insertions(+), 59 deletions(-) diff --git a/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 b/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 index c4b9161..e5689b5 100644 --- a/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 +++ b/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 @@ -144,6 +144,23 @@ Describe 'AiSdlcConfig' { Test-AiSdlcTrunkPushAllowed -RepoRoot (New-ConfigRepo -Json $Json -Git) | Should -Be $Expected } + It 'reads git.allowTrunkPush from the commit that -Ref names, not from the working tree' { + $root = New-ConfigRepo -Json '{ "git": { "allowTrunkPush": true } }' -Git + git -C $root config user.email probe@example.invalid + git -C $root config user.name probe + git -C $root add aisdlc.json + git -C $root commit --quiet -m on --no-verify + git -C $root update-ref refs/remotes/origin/main HEAD + Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value '{}' + git -C $root commit --quiet -am off --no-verify + git -C $root update-ref refs/remotes/origin/master HEAD + Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value '{ "git": { "allowTrunkPush": true } }' + + Test-AiSdlcTrunkPushAllowed -RepoRoot $root -Ref 'refs/remotes/origin/main' | Should -BeTrue + Test-AiSdlcTrunkPushAllowed -RepoRoot $root -Ref 'refs/remotes/origin/master' | Should -BeFalse + Test-AiSdlcTrunkPushAllowed -RepoRoot $root -Ref 'refs/remotes/origin/missing' | Should -BeFalse + } + It 'reads the other repositories whose issues a pull request may name from tracker.acceptedRepositories' { $config = Get-AiSdlcConfig -RepoRoot (New-ConfigRepo -Json '{ "tracker": { "acceptedRepositories": ["contoso/ai-sdlc"] } }') diff --git a/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 b/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 index d403d2d..3d3449e 100644 --- a/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 +++ b/.claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 @@ -276,8 +276,22 @@ function Test-AiSdlcPack { function Test-AiSdlcTrunkPushAllowed { # True only when aisdlc.json sets git.allowTrunkPush to the JSON value true. A string such as "true" # does not count, so a typo never opens the trunk. The push hooks still refuse a delete or a force push. + # With -Ref, the file is read from that commit, not from the working tree. The push hooks pass the + # remote-tracking ref of the branch they guard, such as refs/remotes/origin/main, so a change in the + # working tree cannot switch the setting on: it counts only once it is on the remote main branch. + # A missing ref, a missing file or a file that is not valid JSON counts as false. [CmdletBinding()] - param([string]$RepoRoot) + param([string]$RepoRoot, [string]$Ref) + + if ($Ref) { + if (-not $RepoRoot) { $RepoRoot = Find-AiSdlcRepoRoot } + $text = git -C $RepoRoot show "$($Ref):$($script:ConfigFileName)" 2>$null + if ($LASTEXITCODE -ne 0 -or -not $text) { return $false } + try { $values = ($text -join "`n") | ConvertFrom-Json -AsHashtable } catch { return $false } + $section = if ($values -is [System.Collections.IDictionary]) { $values['git'] } else { $null } + $value = if ($section -is [System.Collections.IDictionary]) { $section['allowTrunkPush'] } else { $null } + return ($value -is [bool]) -and $value + } $config = Get-AiSdlcConfig -RepoRoot $RepoRoot $value = $config.git['allowTrunkPush'] diff --git a/.claude/skills/ai-sdlc-gates/sync-manifest.json b/.claude/skills/ai-sdlc-gates/sync-manifest.json index a98cef2..2529eeb 100644 --- a/.claude/skills/ai-sdlc-gates/sync-manifest.json +++ b/.claude/skills/ai-sdlc-gates/sync-manifest.json @@ -21,8 +21,8 @@ ".claude/skills/ai-sdlc-gates/assets/actions/ai-sdlc-pr/action.yml": "f80ed84d896859668d74cd47bf327a714d383f8a", ".claude/skills/ai-sdlc-gates/assets/agents-core.md": "f7e45643bf0f5447d480b588784b2c599cc7f320", ".claude/skills/ai-sdlc-gates/gates.json": "cf6f5a2d284f0b22f0f4a89292037caed3e53c19", - ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1": "d403d2dde2dbcbceba925ae845645cc66c7aef40", - ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1": "c4b91617b2558d1769b35b17aa0be30bc52ff4bd", + ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1": "3d3449e30e25d842f355ce74a2150775ab8b3e0d", + ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1": "e5689b5deec495e74dc991786596903d70283263", ".claude/skills/ai-sdlc-gates/scripts/apm-version.json": "fbbd8a51e60e3a7e653a35bc9b959f2bf332ab74", ".claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.ps1": "64c6d651e638b0fe15d20cde02418e8021a5cdfc", ".claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.Tests.ps1": "d9ac6b357e1fc4dbf7deacce04ec365b8515e627", @@ -114,7 +114,7 @@ ".claude/skills/ai-sdlc-handbook/references/docs-wiki.md": "038477c9b704a5b545decfe5e3f3f9970d8d1f9d", ".claude/skills/ai-sdlc-handbook/references/first-story.md": "be899eb395dafb2d704b8f0cb46bac1fb5e593c8", ".claude/skills/ai-sdlc-handbook/references/language.md": "ca703edeb9e07e28e32a39fbcc9116b64db444d8", - ".claude/skills/ai-sdlc-handbook/references/layout.md": "1c7fd6a6eaca9256c87810dcdf6bc8ee36052e08", + ".claude/skills/ai-sdlc-handbook/references/layout.md": "92bf66ab0b736782e25982ed74866c9826476363", ".claude/skills/ai-sdlc-handbook/references/node-templates.md": "580c9c92c470a6abbaa0145cc3060ff1a11d247c", ".claude/skills/ai-sdlc-handbook/references/orchestration.md": "22373827d6ecd454d93cfb652f76c5204f3215e2", ".claude/skills/ai-sdlc-handbook/references/pattern.md": "f0f2a8cf3dac267cda0fd3783d86bddba5afc7c0", @@ -130,13 +130,13 @@ ".claude/skills/ai-sdlc-hooks/githooks/post-commit": "f18058f9a38efc164e13801d61bb05329a056109", ".claude/skills/ai-sdlc-hooks/githooks/post-merge": "bb373f33abd09294cda55d7fc4499f32672eb372", ".claude/skills/ai-sdlc-hooks/githooks/post-rewrite": "e4c187dffeeaba569901f3424fae476b17c14927", - ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "9ee20d817cb7958fc37649be80486e177b826650", + ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "267f418c8e3c6b910d2bb7b680ac5f0ffceb1dc1", ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1": "52ffd325d13cd403e7bfea0de8098c530c129b65", ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "ef5b30f0811181462d354a61d3e64c19f0c305e2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "735fa8ceacf1dad23abf09a59defaf1bcf40e874", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "e91541c0e0b50e140bb6b98b21410c0a22e96204", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "0f946257b55c99127482226fdff6b14a98973071", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "73947a2a69aecf0e73a11640a0c21d081d43c4d8", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1": "ca703a9e057633e39af161d9e43a042429813acc", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1": "d15bf28d4191b5e2bca8ce59621ad03a1ef6198c", ".claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.ps1": "da6172d61799df3f37c5f70a103cddddb5517cb0", @@ -156,7 +156,7 @@ ".claude/skills/ai-sdlc-hooks/scripts/Invoke-PostEditCheck.Tests.ps1": "3429e18735428ab387ab58ae276d4195b32e7999", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.ps1": "b54f90deb751d0b0dbf8ee8fbc3f39b3300b3b3d", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.Tests.ps1": "77e4b627da13ea9887f3918f66bc5b33dfd91c56", - ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "28197207004ab21a5f74e315b797306ad41a6791", + ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "ade65e330fbe44cc947b18b428ccd4fbf139fb4e", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1": "56abaf1de1c17bea94c26e128f8c41e275a74f87", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1": "8db305e438bc7ee404eb5106eacbe5581738f148", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.ps1": "fa3d7f509b6f9a1a935178c1eaf0d1566b7afead", diff --git a/.claude/skills/ai-sdlc-handbook/references/layout.md b/.claude/skills/ai-sdlc-handbook/references/layout.md index 1c7fd6a..92bf66a 100644 --- a/.claude/skills/ai-sdlc-handbook/references/layout.md +++ b/.claude/skills/ai-sdlc-handbook/references/layout.md @@ -129,7 +129,7 @@ installs. `AiSdlcConfig.psm1` takes each dependency whose path ends in `packs//main). Without pwsh, the config module or +# that ref, the setting cannot be read, so the push is refused. # git passes one line per ref on stdin: . # `git lfs pre-push` needs the same lines at the end, so they are read once and kept. +# The setting is read from aisdlc.json on the remote-tracking ref of the branch ($1 is the remote, $2 the +# branch), not from the working tree, so an edit that is not on the remote main branch yet cannot switch it on. trunk_push_allowed() { command -v pwsh >/dev/null 2>&1 || return 1 module="$(dirname "$0")/../../ai-sdlc-gates/scripts/AiSdlcConfig.psm1" [ -f "$module" ] || return 1 - AISDLC_CONFIG_MODULE="$module" AISDLC_REPO_ROOT="$(git rev-parse --show-toplevel)" \ - pwsh -NoProfile -NonInteractive -Command 'try { Import-Module $env:AISDLC_CONFIG_MODULE -Force; if (Test-AiSdlcTrunkPushAllowed -RepoRoot $env:AISDLC_REPO_ROOT) { exit 0 } } catch { }; exit 1' >/dev/null 2>&1 + AISDLC_CONFIG_MODULE="$module" AISDLC_REPO_ROOT="$(git rev-parse --show-toplevel)" AISDLC_REF="refs/remotes/$1/$2" \ + pwsh -NoProfile -NonInteractive -Command 'try { Import-Module $env:AISDLC_CONFIG_MODULE -Force; if (Test-AiSdlcTrunkPushAllowed -RepoRoot $env:AISDLC_REPO_ROOT -Ref $env:AISDLC_REF) { exit 0 } } catch { }; exit 1' >/dev/null 2>&1 } +remote_name=$1 + is_zero_sha() { case "$1" in *[!0]*) return 1 ;; @@ -39,15 +44,11 @@ is_zero_sha() { } refs=$(cat) -trunk_allowed= while read -r local_ref local_sha remote_ref remote_sha; do case "$remote_ref" in refs/heads/main|refs/heads/master) branch=${remote_ref#refs/heads/} - if [ -z "$trunk_allowed" ]; then - if trunk_push_allowed; then trunk_allowed=yes; else trunk_allowed=no; fi - fi - if [ "$trunk_allowed" != yes ]; then + if ! trunk_push_allowed "$remote_name" "$branch"; then echo "pre-push: a push to $branch is refused. A change reaches main only through a pull request that a person reviews and merges. Push the story branch and open or update its pull request instead." >&2 exit 1 fi diff --git a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 index e91541c..73947a2 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 @@ -240,7 +240,26 @@ exit 0 $script:OptedIn = Join-Path -Path $TestDrive -ChildPath 'trunk-push-repo' New-Item -ItemType Directory -Path $script:OptedIn -Force | Out-Null git -C $script:OptedIn init --quiet + git -C $script:OptedIn config user.email probe@example.invalid + git -C $script:OptedIn config user.name probe Set-Content -LiteralPath (Join-Path $script:OptedIn 'aisdlc.json') -Value '{ "git": { "allowTrunkPush": true } }' + git -C $script:OptedIn add aisdlc.json + git -C $script:OptedIn commit --quiet -m on --no-verify + # The setting counts only on the remote main branch, so the remote-tracking refs hold it. + git -C $script:OptedIn update-ref refs/remotes/origin/main HEAD + git -C $script:OptedIn update-ref refs/remotes/origin/master HEAD + + # A repository whose working tree switches the setting on, while the remote main branch does not. + $script:LocalOnly = Join-Path -Path $TestDrive -ChildPath 'local-only-repo' + New-Item -ItemType Directory -Path $script:LocalOnly -Force | Out-Null + git -C $script:LocalOnly init --quiet + git -C $script:LocalOnly config user.email probe@example.invalid + git -C $script:LocalOnly config user.name probe + Set-Content -LiteralPath (Join-Path $script:LocalOnly 'aisdlc.json') -Value '{}' + git -C $script:LocalOnly add aisdlc.json + git -C $script:LocalOnly commit --quiet -m off --no-verify + git -C $script:LocalOnly update-ref refs/remotes/origin/main HEAD + Set-Content -LiteralPath (Join-Path $script:LocalOnly 'aisdlc.json') -Value '{ "git": { "allowTrunkPush": true } }' function Invoke-OptedInHook { param([string]$Command, [string]$Branch = 'main', [string]$CheckScript = $script:CleanCheck) @@ -294,6 +313,13 @@ exit 0 $r.Output | Should -Match 'allowTrunkPush' } + It 'refuses a trunk push when only the working tree switches the setting on' { + $payload = New-Payload -Command 'git push origin main' + $out = & $script:ScriptUnderTest -Payload $payload -CheckScript $script:CleanCheck -CurrentBranch 'main' -ReceiptRoot $script:Receipts -HeadTree $script:GreenTree -RepoRoot $script:LocalOnly *>&1 | Out-String + $out | Should -Match '"permissionDecision":"deny"' + $out | Should -Match 'refs/remotes/origin/main' + } + It 'still runs the completeness check on a trunk push' { $r = Invoke-OptedInHook -Command 'git push origin main' -CheckScript $script:GapCheck $r.Output | Should -Match '"permissionDecision":"deny"' diff --git a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 index 735fa8c..0f94625 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -32,7 +32,8 @@ allow list (-u, -q, -v, --set-upstream, --quiet, --verbose, --progress, --no-progress, --porcelain, --atomic, --follow-tags, each written in full), a git option before push other than -C, and a push chained with any other command stay refused. So --force, --delete, --mirror and --no-verify are refused, - also when shortened. The rest of the checks still run on such a + also when shortened. The setting counts only when it is in aisdlc.json on the remote-tracking ref of + that main branch (refs/remotes//main), so an edit in the working tree cannot switch it on. The rest of the checks still run on such a push. A permission rule cannot see which branch a bare push targets, so this hook is the guard for Claude Code and Copilot CLI alike. It is registered for the Bash tool and for the PowerShell tool, because a repository @@ -227,6 +228,27 @@ function Test-TargetsProtectedBranch { return $false } +function Get-TrunkTrackingRef { + # The remote-tracking ref of the main branch a plain push updates, such as refs/remotes/origin/main. + # git.allowTrunkPush is read from that commit, so only a setting that is already on the remote counts. + # Call it only after Test-RewritesBranch passed, so the command is one plain push. + param([string]$CommandLine, [string]$Branch, [string]$Root) + + $push = [regex]::Match($CommandLine, "$gitPrefix\s+push(?[^;&|]*)") + $all = @($push.Groups['rest'].Value.Trim() -split '\s+' | Where-Object { $_ } | ForEach-Object { $_ -replace '[''"]', '' }) + $words = @($all | Where-Object { $_ -ne '2>&1' -and -not $_.StartsWith('-') }) + $remote = if ($words.Count -gt 0) { $words[0] } else { '' } + if (-not $remote -and $Branch) { $remote = try { [string](git -C $Root config "branch.$Branch.remote" 2>$null) } catch { '' } } + if (-not $remote) { $remote = 'origin' } + $target = $Branch + foreach ($refspec in @($words | Select-Object -Skip 1)) { + $name = ($refspec -split ':')[-1] -replace '^refs/heads/', '' + if ($name -eq 'HEAD') { $name = $Branch } + if ($name -in $protectedBranches) { $target = $name; break } + } + return "refs/remotes/$($remote.Trim())/$target" +} + function Test-RewritesBranch { # True when the push may delete or rewrite a branch, or when the hook cannot judge it: a force option, # a +refspec, a delete, a push of every branch, --no-verify (which skips the pre-push git hook), a git @@ -355,6 +377,13 @@ if (Test-TargetsProtectedBranch -CommandLine $command -Branch ([string]$CurrentB 'commands. Run the push of main on its own, as git push [remote] [branch].') exit 0 } + $trunkRef = Get-TrunkTrackingRef -CommandLine $command -Branch ([string]$CurrentBranch).Trim() -Root $targetRoot + if (-not (Test-AiSdlcTrunkPushAllowed -RepoRoot $targetRoot -Ref $trunkRef)) { + Write-Deny ("git.allowTrunkPush counts only when it is on the remote main branch ($trunkRef), not in the " + + 'working tree alone. Get the setting onto main through a pull request first, or fetch when it is ' + + 'already there.') + exit 0 + } } if (-not $targetInstalls) { exit 0 } diff --git a/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 index 2819720..ade65e3 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 @@ -74,17 +74,23 @@ Describe 'The pre-push git hook' { # A repository with two commits on main, so a push can be a fast-forward or a rewrite. function Invoke-TrunkPush { - param([string]$Json, [ValidateSet('FastForward', 'Rewrite', 'Delete', 'UnknownRemote')][string]$Kind) + param([string]$Json, [ValidateSet('FastForward', 'Rewrite', 'Delete', 'UnknownRemote')][string]$Kind, [string]$WorkTreeJson) $root = Join-Path ([System.IO.Path]::GetTempPath()) ('pre-push-' + [guid]::NewGuid().ToString('n')) New-Item -ItemType Directory -Path $root | Out-Null git -C $root init --quiet --initial-branch main git -C $root config user.email probe@example.invalid git -C $root config user.name probe - if ($Json) { Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value $Json } + if ($Json) { + Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value $Json + git -C $root add aisdlc.json + } git -C $root commit --quiet --allow-empty -m one --no-verify $first = (git -C $root rev-parse HEAD).Trim() git -C $root commit --quiet --allow-empty -m two --no-verify $second = (git -C $root rev-parse HEAD).Trim() + # The remote main branch holds the committed setting; the hook reads it from there. + git -C $root update-ref refs/remotes/origin/main $first + if ($WorkTreeJson) { Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value $WorkTreeJson } $line = switch ($Kind) { 'FastForward' { "refs/heads/main $second refs/heads/main $first" } 'Rewrite' { "refs/heads/main $first refs/heads/main $second" } @@ -125,6 +131,12 @@ Describe 'The pre-push git hook' { $r.Code | Should -Be 1 $r.Output | Should -Match 'a push to main is refused' } + + It 'refuses a fast-forward when only the working tree switches the setting on' -Skip:($script:NoSh -or $script:NoPwshHere) { + $r = Invoke-TrunkPush -Json '{}' -WorkTreeJson $script:OptIn -Kind FastForward + $r.Code | Should -Be 1 + $r.Output | Should -Match 'a push to main is refused' + } } It 'never falls back to Windows PowerShell, which cannot run a gate that needs PowerShell 7' { diff --git a/CHANGELOG.md b/CHANGELOG.md index fbac36d..1415a0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,9 @@ Each entry names its issue, as `#42`. still refuse a delete and a force push of `main`, and the blocking gates still run. The git hook prints one line that names the setting when it lets a push through. The agent hook now checks every push in a command, and with the setting it refuses `--no-verify`, a git option before `push`, and a - push to `main` that is chained with other commands. + push to `main` that is chained with other commands. Both hooks read the setting from `aisdlc.json` on + the remote `main` branch, not from the working tree, so an edit that is not on `main` cannot switch + it on. ## v1.2.0 - 2026-11-07 diff --git a/apm.lock.yaml b/apm.lock.yaml index 67612a2..8c855bf 100644 --- a/apm.lock.yaml +++ b/apm.lock.yaml @@ -248,8 +248,8 @@ dependencies: .claude/skills/ai-sdlc-gates/assets/actions/ai-sdlc-pr/action.yml: sha256:ee6430668f2f44b6256275645e10f8ab2167b8b6d49990465c5527d1b334abac .claude/skills/ai-sdlc-gates/assets/agents-core.md: sha256:544bb5b78ceaa2ee9eb20203ecdef5d380ecd9b10265cc90d10385d96ed72509 .claude/skills/ai-sdlc-gates/gates.json: sha256:160f09f14ff6591b024f827c879802cf9218b37785d209da6a1323602d6153e5 - .claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1: sha256:d7fc0ff34d5e1995c8d1a592827147fab087361097249ca710953d03581ddb0a - .claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1: sha256:967f1efe278a6640b9e24ac249a12a27eacd9e6d11edbe460c7333179353915c + .claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1: sha256:669ce124af8ce839ddd1f463236777d682196ebda0a0175fe362185f033779a4 + .claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1: sha256:59a69f20f41fdcde013a4654e6532730acb1da42408ff2d825747b8c6891e401 .claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.Tests.ps1: sha256:0b95e6de39c913f3bdebc38c6003f12565a225b165c19e73167cf30391ec1a8b .claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.ps1: sha256:fe0a4432d2e5cb3d1830bc178a086c721eea3cbdd744def18586e1d0a9c0a4c1 .claude/skills/ai-sdlc-gates/scripts/Check-AgentHygiene.Tests.ps1: sha256:d4115307bda4dc2794d395bf41cdc4169896f1255e37b5393d71ad3fb6e6495b @@ -331,7 +331,7 @@ dependencies: .claude/skills/ai-sdlc-gates/scripts/gitleaks-rules.json: sha256:6a8a75c5dbcf2378a1c52d046e34ce275aac7ce08a0ae61408d25c18e1e27014 .claude/skills/ai-sdlc-gates/scripts/gitleaks-version.json: sha256:c54acb854f87a1bbdf0e90c670b72b5de3cd37f7e460d82eca599c3c7af23a84 .claude/skills/ai-sdlc-gates/skill-catalog.json: sha256:5537684656bf189a740ba7e9e7050083af05668d00501ce1e9c6909cb8b91203 - .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:d76ce5649ccda8b4ab92cab77661c855a5b3dbd40968aa5192d50939ea8ec9dd + .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:31ab2b37324dec52467b23dfc34ad7af70623600b0528deb31ba74b03e53acfd .claude/skills/ai-sdlc-handbook/SKILL.md: sha256:548e6b9ad79d3d2afa2f5779835988eeb12c49cda08917c4bbaa9ac0486a47a0 .claude/skills/ai-sdlc-handbook/references/README.md: sha256:654afcaa2b81f560eff93dbdef521b09ced06137a1dbb85d70a4e14ef7502248 .claude/skills/ai-sdlc-handbook/references/artifact-graph.md: sha256:d7ddfe20e5ee6565bcf25f9cef0f578da2a4ab1590033d791b8814d4688fd1f0 @@ -343,7 +343,7 @@ dependencies: .claude/skills/ai-sdlc-handbook/references/docs-wiki.md: sha256:2bd6f3a8e64f9db16163519767b822e4ebcffd740e3c5cbff17281ad71d264b7 .claude/skills/ai-sdlc-handbook/references/first-story.md: sha256:831552230cc16386ee01d7c730e288ef19aca5a66fafb00e1dfbbf4e9788caf2 .claude/skills/ai-sdlc-handbook/references/language.md: sha256:e0e32fae9c9fcdd23380d92ec910128254ce248538940541f5789ca78228a023 - .claude/skills/ai-sdlc-handbook/references/layout.md: sha256:4ac735eea3800a51727efd56ca61f3ed4137c8cca960da5b74f21d1115e78f63 + .claude/skills/ai-sdlc-handbook/references/layout.md: sha256:b03868c6780c790b2b24acc33c165e46b6e7b99258a04d2d07bfbaed9c035ae6 .claude/skills/ai-sdlc-handbook/references/node-templates.md: sha256:8664ad1f85bff48d6230ed22e3f25683f378822e566c2a1454cbb204f4bb8fad .claude/skills/ai-sdlc-handbook/references/orchestration.md: sha256:6a1d6b6cc434f2e312994bd77daaa1fef4e007e03777ac63f3ca74edaa0cc485 .claude/skills/ai-sdlc-handbook/references/pattern.md: sha256:7908f80ee28ff1f7cd9f85b22fcf3e455fe74225d33ff201f8fbce1623d672eb @@ -358,13 +358,13 @@ dependencies: .claude/skills/ai-sdlc-hooks/githooks/post-commit: sha256:4f73a74133b0272725117fa9d962353abb6ed98d9cf5e731cd212fd5ace23271 .claude/skills/ai-sdlc-hooks/githooks/post-merge: sha256:b9f1f47cd3894406451e00c177912baeed66470b0cc18d581a5461330c7c0868 .claude/skills/ai-sdlc-hooks/githooks/post-rewrite: sha256:b7ee1a97b08a9826678829b6c49457fdc4b5ebd53eaf8cdd70f33d26e61c4a79 - .claude/skills/ai-sdlc-hooks/githooks/pre-push: sha256:f71a2b92ba190e7bf7b2ccc42a3f7705524db7f5cadbf31ee7abd39c9ae3ca79 + .claude/skills/ai-sdlc-hooks/githooks/pre-push: sha256:66453196c7d3e116c1510bd6c75c5e02240d86dbd960dfbe3c29b73d290a61c4 .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1: sha256:004bc7f1a68e953c8e657b49e74755b69a14138dfb0db61162ab15420f2b24be .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1: sha256:b3569de6e27c3dcaffbc082311e6882bd722d440e5e855245da2410033202c7e .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1: sha256:4c4e1f6b673671125290d78815c72277665a8a618b55fd589f75f3a36e3b80aa .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1: sha256:46d1d83e38e75db41b1f370bc6f49f4800f0234765eac63c53e37b5af7000453 - .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1: sha256:20e41e5c86854c2a1752c02295a6040e050a6f9126a4e21699b9d850ff6708ac - .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1: sha256:01c095018cb97ec7b880b7781f330b94cd143580030be793894ade5a0f96b3a5 + .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1: sha256:ea9062bd8b20ad47d488b9838eb5a6c735d73b3148cdcfdd9ebdd60ef708f897 + .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1: sha256:b291a529130c4216e473e271a827f8fb3bf96be77480a4195ce2adbfa68217ec .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1: sha256:1c46576b9633bd12286efa11cc9f7c6c2f982f29859f9a33272f76452888e77b .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1: sha256:fccaa2da3a0254cc8a7740974f07b1c0fc1e67106ae7191d9710cbf699da1ba7 .claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.Tests.ps1: sha256:151c3ee69c88db0d85cf4c94207b04dfc4eabe857e178051044ed4fdcee58f33 @@ -384,7 +384,7 @@ dependencies: .claude/skills/ai-sdlc-hooks/scripts/Invoke-PostEditCheck.ps1: sha256:d60cdd2d341487ded3b9fafe40da49f2adfb1cf8f20cf3f8559ea2e80a5f93c6 .claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.Tests.ps1: sha256:9c9859767d2534c45e1c72b47f4b5c64aaa16c32c580df3b5d8bc3dce5cdb2c4 .claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.ps1: sha256:abf763c6cde97dbfc83b25f140e768d66fd9edd3961605b7d058b08a31882875 - .claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1: sha256:ef41c8fce0c879024fe134dbad9e208111831bd7d85b1db8f4f117c3ac037d18 + .claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1: sha256:00ecc72b23d941c31859bcb922474dcbcbea528ae02f37570b30e2dc5b9da095 .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1: sha256:4f2fe5313c8763f8128ad0e0347da1f2dd485393d20dc5e3a5d75e08aa157ad3 .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1: sha256:0381e47c6b1070c7b230f81f243e25b1a8bfa68b5e8e9ae2ad6e225b0ddb36b6 .claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.Tests.ps1: sha256:52f81e945390e61222a2668c8525cb17f17226267e24c52d7792263a07576543 @@ -804,7 +804,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:d7fc0ff34d5e1995c8d1a592827147fab087361097249ca710953d03581ddb0a + content_hash: sha256:669ce124af8ce839ddd1f463236777d682196ebda0a0175fe362185f033779a4 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 @@ -813,7 +813,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:967f1efe278a6640b9e24ac249a12a27eacd9e6d11edbe460c7333179353915c + content_hash: sha256:59a69f20f41fdcde013a4654e6532730acb1da42408ff2d825747b8c6891e401 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.Tests.ps1 @@ -1551,7 +1551,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:d76ce5649ccda8b4ab92cab77661c855a5b3dbd40968aa5192d50939ea8ec9dd + content_hash: sha256:31ab2b37324dec52467b23dfc34ad7af70623600b0528deb31ba74b03e53acfd - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook @@ -1668,7 +1668,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:4ac735eea3800a51727efd56ca61f3ed4137c8cca960da5b74f21d1115e78f63 + content_hash: sha256:b03868c6780c790b2b24acc33c165e46b6e7b99258a04d2d07bfbaed9c035ae6 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook/references/node-templates.md @@ -1812,7 +1812,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:f71a2b92ba190e7bf7b2ccc42a3f7705524db7f5cadbf31ee7abd39c9ae3ca79 + content_hash: sha256:66453196c7d3e116c1510bd6c75c5e02240d86dbd960dfbe3c29b73d290a61c4 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1 @@ -1857,7 +1857,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:20e41e5c86854c2a1752c02295a6040e050a6f9126a4e21699b9d850ff6708ac + content_hash: sha256:ea9062bd8b20ad47d488b9838eb5a6c735d73b3148cdcfdd9ebdd60ef708f897 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -1866,7 +1866,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:01c095018cb97ec7b880b7781f330b94cd143580030be793894ade5a0f96b3a5 + content_hash: sha256:b291a529130c4216e473e271a827f8fb3bf96be77480a4195ce2adbfa68217ec - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1 @@ -2046,7 +2046,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:ef41c8fce0c879024fe134dbad9e208111831bd7d85b1db8f4f117c3ac037d18 + content_hash: sha256:00ecc72b23d941c31859bcb922474dcbcbea528ae02f37570b30e2dc5b9da095 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1 diff --git a/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 b/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 index c4b9161..e5689b5 100644 --- a/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 +++ b/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1 @@ -144,6 +144,23 @@ Describe 'AiSdlcConfig' { Test-AiSdlcTrunkPushAllowed -RepoRoot (New-ConfigRepo -Json $Json -Git) | Should -Be $Expected } + It 'reads git.allowTrunkPush from the commit that -Ref names, not from the working tree' { + $root = New-ConfigRepo -Json '{ "git": { "allowTrunkPush": true } }' -Git + git -C $root config user.email probe@example.invalid + git -C $root config user.name probe + git -C $root add aisdlc.json + git -C $root commit --quiet -m on --no-verify + git -C $root update-ref refs/remotes/origin/main HEAD + Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value '{}' + git -C $root commit --quiet -am off --no-verify + git -C $root update-ref refs/remotes/origin/master HEAD + Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value '{ "git": { "allowTrunkPush": true } }' + + Test-AiSdlcTrunkPushAllowed -RepoRoot $root -Ref 'refs/remotes/origin/main' | Should -BeTrue + Test-AiSdlcTrunkPushAllowed -RepoRoot $root -Ref 'refs/remotes/origin/master' | Should -BeFalse + Test-AiSdlcTrunkPushAllowed -RepoRoot $root -Ref 'refs/remotes/origin/missing' | Should -BeFalse + } + It 'reads the other repositories whose issues a pull request may name from tracker.acceptedRepositories' { $config = Get-AiSdlcConfig -RepoRoot (New-ConfigRepo -Json '{ "tracker": { "acceptedRepositories": ["contoso/ai-sdlc"] } }') diff --git a/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 b/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 index d403d2d..3d3449e 100644 --- a/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 +++ b/core/.apm/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1 @@ -276,8 +276,22 @@ function Test-AiSdlcPack { function Test-AiSdlcTrunkPushAllowed { # True only when aisdlc.json sets git.allowTrunkPush to the JSON value true. A string such as "true" # does not count, so a typo never opens the trunk. The push hooks still refuse a delete or a force push. + # With -Ref, the file is read from that commit, not from the working tree. The push hooks pass the + # remote-tracking ref of the branch they guard, such as refs/remotes/origin/main, so a change in the + # working tree cannot switch the setting on: it counts only once it is on the remote main branch. + # A missing ref, a missing file or a file that is not valid JSON counts as false. [CmdletBinding()] - param([string]$RepoRoot) + param([string]$RepoRoot, [string]$Ref) + + if ($Ref) { + if (-not $RepoRoot) { $RepoRoot = Find-AiSdlcRepoRoot } + $text = git -C $RepoRoot show "$($Ref):$($script:ConfigFileName)" 2>$null + if ($LASTEXITCODE -ne 0 -or -not $text) { return $false } + try { $values = ($text -join "`n") | ConvertFrom-Json -AsHashtable } catch { return $false } + $section = if ($values -is [System.Collections.IDictionary]) { $values['git'] } else { $null } + $value = if ($section -is [System.Collections.IDictionary]) { $section['allowTrunkPush'] } else { $null } + return ($value -is [bool]) -and $value + } $config = Get-AiSdlcConfig -RepoRoot $RepoRoot $value = $config.git['allowTrunkPush'] diff --git a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json index a98cef2..2529eeb 100644 --- a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json +++ b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json @@ -21,8 +21,8 @@ ".claude/skills/ai-sdlc-gates/assets/actions/ai-sdlc-pr/action.yml": "f80ed84d896859668d74cd47bf327a714d383f8a", ".claude/skills/ai-sdlc-gates/assets/agents-core.md": "f7e45643bf0f5447d480b588784b2c599cc7f320", ".claude/skills/ai-sdlc-gates/gates.json": "cf6f5a2d284f0b22f0f4a89292037caed3e53c19", - ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1": "d403d2dde2dbcbceba925ae845645cc66c7aef40", - ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1": "c4b91617b2558d1769b35b17aa0be30bc52ff4bd", + ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.psm1": "3d3449e30e25d842f355ce74a2150775ab8b3e0d", + ".claude/skills/ai-sdlc-gates/scripts/AiSdlcConfig.Tests.ps1": "e5689b5deec495e74dc991786596903d70283263", ".claude/skills/ai-sdlc-gates/scripts/apm-version.json": "fbbd8a51e60e3a7e653a35bc9b959f2bf332ab74", ".claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.ps1": "64c6d651e638b0fe15d20cde02418e8021a5cdfc", ".claude/skills/ai-sdlc-gates/scripts/Build-DocsIndex.Tests.ps1": "d9ac6b357e1fc4dbf7deacce04ec365b8515e627", @@ -114,7 +114,7 @@ ".claude/skills/ai-sdlc-handbook/references/docs-wiki.md": "038477c9b704a5b545decfe5e3f3f9970d8d1f9d", ".claude/skills/ai-sdlc-handbook/references/first-story.md": "be899eb395dafb2d704b8f0cb46bac1fb5e593c8", ".claude/skills/ai-sdlc-handbook/references/language.md": "ca703edeb9e07e28e32a39fbcc9116b64db444d8", - ".claude/skills/ai-sdlc-handbook/references/layout.md": "1c7fd6a6eaca9256c87810dcdf6bc8ee36052e08", + ".claude/skills/ai-sdlc-handbook/references/layout.md": "92bf66ab0b736782e25982ed74866c9826476363", ".claude/skills/ai-sdlc-handbook/references/node-templates.md": "580c9c92c470a6abbaa0145cc3060ff1a11d247c", ".claude/skills/ai-sdlc-handbook/references/orchestration.md": "22373827d6ecd454d93cfb652f76c5204f3215e2", ".claude/skills/ai-sdlc-handbook/references/pattern.md": "f0f2a8cf3dac267cda0fd3783d86bddba5afc7c0", @@ -130,13 +130,13 @@ ".claude/skills/ai-sdlc-hooks/githooks/post-commit": "f18058f9a38efc164e13801d61bb05329a056109", ".claude/skills/ai-sdlc-hooks/githooks/post-merge": "bb373f33abd09294cda55d7fc4499f32672eb372", ".claude/skills/ai-sdlc-hooks/githooks/post-rewrite": "e4c187dffeeaba569901f3424fae476b17c14927", - ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "9ee20d817cb7958fc37649be80486e177b826650", + ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "267f418c8e3c6b910d2bb7b680ac5f0ffceb1dc1", ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1": "52ffd325d13cd403e7bfea0de8098c530c129b65", ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "ef5b30f0811181462d354a61d3e64c19f0c305e2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "735fa8ceacf1dad23abf09a59defaf1bcf40e874", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "e91541c0e0b50e140bb6b98b21410c0a22e96204", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "0f946257b55c99127482226fdff6b14a98973071", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "73947a2a69aecf0e73a11640a0c21d081d43c4d8", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1": "ca703a9e057633e39af161d9e43a042429813acc", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1": "d15bf28d4191b5e2bca8ce59621ad03a1ef6198c", ".claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.ps1": "da6172d61799df3f37c5f70a103cddddb5517cb0", @@ -156,7 +156,7 @@ ".claude/skills/ai-sdlc-hooks/scripts/Invoke-PostEditCheck.Tests.ps1": "3429e18735428ab387ab58ae276d4195b32e7999", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.ps1": "b54f90deb751d0b0dbf8ee8fbc3f39b3300b3b3d", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.Tests.ps1": "77e4b627da13ea9887f3918f66bc5b33dfd91c56", - ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "28197207004ab21a5f74e315b797306ad41a6791", + ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "ade65e330fbe44cc947b18b428ccd4fbf139fb4e", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1": "56abaf1de1c17bea94c26e128f8c41e275a74f87", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1": "8db305e438bc7ee404eb5106eacbe5581738f148", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.ps1": "fa3d7f509b6f9a1a935178c1eaf0d1566b7afead", diff --git a/core/.apm/skills/ai-sdlc-handbook/references/layout.md b/core/.apm/skills/ai-sdlc-handbook/references/layout.md index 1c7fd6a..92bf66a 100644 --- a/core/.apm/skills/ai-sdlc-handbook/references/layout.md +++ b/core/.apm/skills/ai-sdlc-handbook/references/layout.md @@ -129,7 +129,7 @@ installs. `AiSdlcConfig.psm1` takes each dependency whose path ends in `packs//main). Without pwsh, the config module or +# that ref, the setting cannot be read, so the push is refused. # git passes one line per ref on stdin: . # `git lfs pre-push` needs the same lines at the end, so they are read once and kept. +# The setting is read from aisdlc.json on the remote-tracking ref of the branch ($1 is the remote, $2 the +# branch), not from the working tree, so an edit that is not on the remote main branch yet cannot switch it on. trunk_push_allowed() { command -v pwsh >/dev/null 2>&1 || return 1 module="$(dirname "$0")/../../ai-sdlc-gates/scripts/AiSdlcConfig.psm1" [ -f "$module" ] || return 1 - AISDLC_CONFIG_MODULE="$module" AISDLC_REPO_ROOT="$(git rev-parse --show-toplevel)" \ - pwsh -NoProfile -NonInteractive -Command 'try { Import-Module $env:AISDLC_CONFIG_MODULE -Force; if (Test-AiSdlcTrunkPushAllowed -RepoRoot $env:AISDLC_REPO_ROOT) { exit 0 } } catch { }; exit 1' >/dev/null 2>&1 + AISDLC_CONFIG_MODULE="$module" AISDLC_REPO_ROOT="$(git rev-parse --show-toplevel)" AISDLC_REF="refs/remotes/$1/$2" \ + pwsh -NoProfile -NonInteractive -Command 'try { Import-Module $env:AISDLC_CONFIG_MODULE -Force; if (Test-AiSdlcTrunkPushAllowed -RepoRoot $env:AISDLC_REPO_ROOT -Ref $env:AISDLC_REF) { exit 0 } } catch { }; exit 1' >/dev/null 2>&1 } +remote_name=$1 + is_zero_sha() { case "$1" in *[!0]*) return 1 ;; @@ -39,15 +44,11 @@ is_zero_sha() { } refs=$(cat) -trunk_allowed= while read -r local_ref local_sha remote_ref remote_sha; do case "$remote_ref" in refs/heads/main|refs/heads/master) branch=${remote_ref#refs/heads/} - if [ -z "$trunk_allowed" ]; then - if trunk_push_allowed; then trunk_allowed=yes; else trunk_allowed=no; fi - fi - if [ "$trunk_allowed" != yes ]; then + if ! trunk_push_allowed "$remote_name" "$branch"; then echo "pre-push: a push to $branch is refused. A change reaches main only through a pull request that a person reviews and merges. Push the story branch and open or update its pull request instead." >&2 exit 1 fi diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 index e91541c..73947a2 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1 @@ -240,7 +240,26 @@ exit 0 $script:OptedIn = Join-Path -Path $TestDrive -ChildPath 'trunk-push-repo' New-Item -ItemType Directory -Path $script:OptedIn -Force | Out-Null git -C $script:OptedIn init --quiet + git -C $script:OptedIn config user.email probe@example.invalid + git -C $script:OptedIn config user.name probe Set-Content -LiteralPath (Join-Path $script:OptedIn 'aisdlc.json') -Value '{ "git": { "allowTrunkPush": true } }' + git -C $script:OptedIn add aisdlc.json + git -C $script:OptedIn commit --quiet -m on --no-verify + # The setting counts only on the remote main branch, so the remote-tracking refs hold it. + git -C $script:OptedIn update-ref refs/remotes/origin/main HEAD + git -C $script:OptedIn update-ref refs/remotes/origin/master HEAD + + # A repository whose working tree switches the setting on, while the remote main branch does not. + $script:LocalOnly = Join-Path -Path $TestDrive -ChildPath 'local-only-repo' + New-Item -ItemType Directory -Path $script:LocalOnly -Force | Out-Null + git -C $script:LocalOnly init --quiet + git -C $script:LocalOnly config user.email probe@example.invalid + git -C $script:LocalOnly config user.name probe + Set-Content -LiteralPath (Join-Path $script:LocalOnly 'aisdlc.json') -Value '{}' + git -C $script:LocalOnly add aisdlc.json + git -C $script:LocalOnly commit --quiet -m off --no-verify + git -C $script:LocalOnly update-ref refs/remotes/origin/main HEAD + Set-Content -LiteralPath (Join-Path $script:LocalOnly 'aisdlc.json') -Value '{ "git": { "allowTrunkPush": true } }' function Invoke-OptedInHook { param([string]$Command, [string]$Branch = 'main', [string]$CheckScript = $script:CleanCheck) @@ -294,6 +313,13 @@ exit 0 $r.Output | Should -Match 'allowTrunkPush' } + It 'refuses a trunk push when only the working tree switches the setting on' { + $payload = New-Payload -Command 'git push origin main' + $out = & $script:ScriptUnderTest -Payload $payload -CheckScript $script:CleanCheck -CurrentBranch 'main' -ReceiptRoot $script:Receipts -HeadTree $script:GreenTree -RepoRoot $script:LocalOnly *>&1 | Out-String + $out | Should -Match '"permissionDecision":"deny"' + $out | Should -Match 'refs/remotes/origin/main' + } + It 'still runs the completeness check on a trunk push' { $r = Invoke-OptedInHook -Command 'git push origin main' -CheckScript $script:GapCheck $r.Output | Should -Match '"permissionDecision":"deny"' diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 index 735fa8c..0f94625 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -32,7 +32,8 @@ allow list (-u, -q, -v, --set-upstream, --quiet, --verbose, --progress, --no-progress, --porcelain, --atomic, --follow-tags, each written in full), a git option before push other than -C, and a push chained with any other command stay refused. So --force, --delete, --mirror and --no-verify are refused, - also when shortened. The rest of the checks still run on such a + also when shortened. The setting counts only when it is in aisdlc.json on the remote-tracking ref of + that main branch (refs/remotes//main), so an edit in the working tree cannot switch it on. The rest of the checks still run on such a push. A permission rule cannot see which branch a bare push targets, so this hook is the guard for Claude Code and Copilot CLI alike. It is registered for the Bash tool and for the PowerShell tool, because a repository @@ -227,6 +228,27 @@ function Test-TargetsProtectedBranch { return $false } +function Get-TrunkTrackingRef { + # The remote-tracking ref of the main branch a plain push updates, such as refs/remotes/origin/main. + # git.allowTrunkPush is read from that commit, so only a setting that is already on the remote counts. + # Call it only after Test-RewritesBranch passed, so the command is one plain push. + param([string]$CommandLine, [string]$Branch, [string]$Root) + + $push = [regex]::Match($CommandLine, "$gitPrefix\s+push(?[^;&|]*)") + $all = @($push.Groups['rest'].Value.Trim() -split '\s+' | Where-Object { $_ } | ForEach-Object { $_ -replace '[''"]', '' }) + $words = @($all | Where-Object { $_ -ne '2>&1' -and -not $_.StartsWith('-') }) + $remote = if ($words.Count -gt 0) { $words[0] } else { '' } + if (-not $remote -and $Branch) { $remote = try { [string](git -C $Root config "branch.$Branch.remote" 2>$null) } catch { '' } } + if (-not $remote) { $remote = 'origin' } + $target = $Branch + foreach ($refspec in @($words | Select-Object -Skip 1)) { + $name = ($refspec -split ':')[-1] -replace '^refs/heads/', '' + if ($name -eq 'HEAD') { $name = $Branch } + if ($name -in $protectedBranches) { $target = $name; break } + } + return "refs/remotes/$($remote.Trim())/$target" +} + function Test-RewritesBranch { # True when the push may delete or rewrite a branch, or when the hook cannot judge it: a force option, # a +refspec, a delete, a push of every branch, --no-verify (which skips the pre-push git hook), a git @@ -355,6 +377,13 @@ if (Test-TargetsProtectedBranch -CommandLine $command -Branch ([string]$CurrentB 'commands. Run the push of main on its own, as git push [remote] [branch].') exit 0 } + $trunkRef = Get-TrunkTrackingRef -CommandLine $command -Branch ([string]$CurrentBranch).Trim() -Root $targetRoot + if (-not (Test-AiSdlcTrunkPushAllowed -RepoRoot $targetRoot -Ref $trunkRef)) { + Write-Deny ("git.allowTrunkPush counts only when it is on the remote main branch ($trunkRef), not in the " + + 'working tree alone. Get the setting onto main through a pull request first, or fetch when it is ' + + 'already there.') + exit 0 + } } if (-not $targetInstalls) { exit 0 } diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 index 2819720..ade65e3 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 @@ -74,17 +74,23 @@ Describe 'The pre-push git hook' { # A repository with two commits on main, so a push can be a fast-forward or a rewrite. function Invoke-TrunkPush { - param([string]$Json, [ValidateSet('FastForward', 'Rewrite', 'Delete', 'UnknownRemote')][string]$Kind) + param([string]$Json, [ValidateSet('FastForward', 'Rewrite', 'Delete', 'UnknownRemote')][string]$Kind, [string]$WorkTreeJson) $root = Join-Path ([System.IO.Path]::GetTempPath()) ('pre-push-' + [guid]::NewGuid().ToString('n')) New-Item -ItemType Directory -Path $root | Out-Null git -C $root init --quiet --initial-branch main git -C $root config user.email probe@example.invalid git -C $root config user.name probe - if ($Json) { Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value $Json } + if ($Json) { + Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value $Json + git -C $root add aisdlc.json + } git -C $root commit --quiet --allow-empty -m one --no-verify $first = (git -C $root rev-parse HEAD).Trim() git -C $root commit --quiet --allow-empty -m two --no-verify $second = (git -C $root rev-parse HEAD).Trim() + # The remote main branch holds the committed setting; the hook reads it from there. + git -C $root update-ref refs/remotes/origin/main $first + if ($WorkTreeJson) { Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value $WorkTreeJson } $line = switch ($Kind) { 'FastForward' { "refs/heads/main $second refs/heads/main $first" } 'Rewrite' { "refs/heads/main $first refs/heads/main $second" } @@ -125,6 +131,12 @@ Describe 'The pre-push git hook' { $r.Code | Should -Be 1 $r.Output | Should -Match 'a push to main is refused' } + + It 'refuses a fast-forward when only the working tree switches the setting on' -Skip:($script:NoSh -or $script:NoPwshHere) { + $r = Invoke-TrunkPush -Json '{}' -WorkTreeJson $script:OptIn -Kind FastForward + $r.Code | Should -Be 1 + $r.Output | Should -Match 'a push to main is refused' + } } It 'never falls back to Windows PowerShell, which cannot run a gate that needs PowerShell 7' { From a58a1f9926c12beed42fd5fb2457ddf9c9d63415 Mon Sep 17 00:00:00 2001 From: Rob Hofmann Date: Mon, 9 Nov 2026 02:59:40 +0100 Subject: [PATCH 6/6] Read git.allowTrunkPush from the remote tip that git passes to the pre-push hook git learns the remote tip of the branch while it pushes and passes it on stdin. The hook now reads the setting from that commit, so a local remote-tracking ref cannot switch it on. The agent hook keeps its check on the local ref as a first check; the git hook is the backstop. Refs #16 --- .../skills/ai-sdlc-gates/sync-manifest.json | 8 ++--- .../ai-sdlc-handbook/references/layout.md | 2 +- .../skills/ai-sdlc-hooks/githooks/pre-push | 36 +++++++++---------- .../scripts/Deny-IncompletePush.ps1 | 4 ++- .../scripts/PrePushHook.Tests.ps1 | 16 +++++++-- CHANGELOG.md | 3 +- apm.lock.yaml | 20 +++++------ .../skills/ai-sdlc-gates/sync-manifest.json | 8 ++--- .../ai-sdlc-handbook/references/layout.md | 2 +- .../skills/ai-sdlc-hooks/githooks/pre-push | 36 +++++++++---------- .../scripts/Deny-IncompletePush.ps1 | 4 ++- .../scripts/PrePushHook.Tests.ps1 | 16 +++++++-- 12 files changed, 88 insertions(+), 67 deletions(-) diff --git a/.claude/skills/ai-sdlc-gates/sync-manifest.json b/.claude/skills/ai-sdlc-gates/sync-manifest.json index 2529eeb..fb4e8ae 100644 --- a/.claude/skills/ai-sdlc-gates/sync-manifest.json +++ b/.claude/skills/ai-sdlc-gates/sync-manifest.json @@ -114,7 +114,7 @@ ".claude/skills/ai-sdlc-handbook/references/docs-wiki.md": "038477c9b704a5b545decfe5e3f3f9970d8d1f9d", ".claude/skills/ai-sdlc-handbook/references/first-story.md": "be899eb395dafb2d704b8f0cb46bac1fb5e593c8", ".claude/skills/ai-sdlc-handbook/references/language.md": "ca703edeb9e07e28e32a39fbcc9116b64db444d8", - ".claude/skills/ai-sdlc-handbook/references/layout.md": "92bf66ab0b736782e25982ed74866c9826476363", + ".claude/skills/ai-sdlc-handbook/references/layout.md": "b6683bbb25c614a5d0a3f8283d4e46bfa110bcd2", ".claude/skills/ai-sdlc-handbook/references/node-templates.md": "580c9c92c470a6abbaa0145cc3060ff1a11d247c", ".claude/skills/ai-sdlc-handbook/references/orchestration.md": "22373827d6ecd454d93cfb652f76c5204f3215e2", ".claude/skills/ai-sdlc-handbook/references/pattern.md": "f0f2a8cf3dac267cda0fd3783d86bddba5afc7c0", @@ -130,12 +130,12 @@ ".claude/skills/ai-sdlc-hooks/githooks/post-commit": "f18058f9a38efc164e13801d61bb05329a056109", ".claude/skills/ai-sdlc-hooks/githooks/post-merge": "bb373f33abd09294cda55d7fc4499f32672eb372", ".claude/skills/ai-sdlc-hooks/githooks/post-rewrite": "e4c187dffeeaba569901f3424fae476b17c14927", - ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "267f418c8e3c6b910d2bb7b680ac5f0ffceb1dc1", + ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "490c81fd333d26cf9f09877fecb369d531710d66", ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1": "52ffd325d13cd403e7bfea0de8098c530c129b65", ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "ef5b30f0811181462d354a61d3e64c19f0c305e2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "0f946257b55c99127482226fdff6b14a98973071", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "117d527a075a78017b0a199703d84a6807797573", ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "73947a2a69aecf0e73a11640a0c21d081d43c4d8", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1": "ca703a9e057633e39af161d9e43a042429813acc", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1": "d15bf28d4191b5e2bca8ce59621ad03a1ef6198c", @@ -156,7 +156,7 @@ ".claude/skills/ai-sdlc-hooks/scripts/Invoke-PostEditCheck.Tests.ps1": "3429e18735428ab387ab58ae276d4195b32e7999", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.ps1": "b54f90deb751d0b0dbf8ee8fbc3f39b3300b3b3d", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.Tests.ps1": "77e4b627da13ea9887f3918f66bc5b33dfd91c56", - ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "ade65e330fbe44cc947b18b428ccd4fbf139fb4e", + ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "718248ded3ba695b29d4d7eb59e8f09130cf918c", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1": "56abaf1de1c17bea94c26e128f8c41e275a74f87", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1": "8db305e438bc7ee404eb5106eacbe5581738f148", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.ps1": "fa3d7f509b6f9a1a935178c1eaf0d1566b7afead", diff --git a/.claude/skills/ai-sdlc-handbook/references/layout.md b/.claude/skills/ai-sdlc-handbook/references/layout.md index 92bf66a..b6683bb 100644 --- a/.claude/skills/ai-sdlc-handbook/references/layout.md +++ b/.claude/skills/ai-sdlc-handbook/references/layout.md @@ -129,7 +129,7 @@ installs. `AiSdlcConfig.psm1` takes each dependency whose path ends in `packs//main). Without pwsh, the config module or -# that ref, the setting cannot be read, so the push is refused. +# stay refused. The blocking gates still run on such a push. The setting counts only in aisdlc.json of +# the commit that is the remote tip of that branch, which git passes on stdin. Without pwsh, the config +# module or that commit in the clone, the setting cannot be read, so the push is refused. # git passes one line per ref on stdin: . # `git lfs pre-push` needs the same lines at the end, so they are read once and kept. -# The setting is read from aisdlc.json on the remote-tracking ref of the branch ($1 is the remote, $2 the -# branch), not from the working tree, so an edit that is not on the remote main branch yet cannot switch it on. +# The setting is read from aisdlc.json in the commit that is the tip of the remote branch now. git +# learns that commit from the remote while it pushes and passes it on stdin as , so neither +# an edit in the working tree nor a local ref can switch the setting on. A new branch (zero sha) or a tip +# that is not in this clone counts as off. $1 is that remote sha. trunk_push_allowed() { + is_zero_sha "$1" && return 1 + git cat-file -e "$1^{commit}" 2>/dev/null || return 1 command -v pwsh >/dev/null 2>&1 || return 1 module="$(dirname "$0")/../../ai-sdlc-gates/scripts/AiSdlcConfig.psm1" [ -f "$module" ] || return 1 - AISDLC_CONFIG_MODULE="$module" AISDLC_REPO_ROOT="$(git rev-parse --show-toplevel)" AISDLC_REF="refs/remotes/$1/$2" \ - pwsh -NoProfile -NonInteractive -Command 'try { Import-Module $env:AISDLC_CONFIG_MODULE -Force; if (Test-AiSdlcTrunkPushAllowed -RepoRoot $env:AISDLC_REPO_ROOT -Ref $env:AISDLC_REF) { exit 0 } } catch { }; exit 1' >/dev/null 2>&1 + AISDLC_CONFIG_MODULE="$module" AISDLC_REPO_ROOT="$(git rev-parse --show-toplevel)" AISDLC_REF="$1" pwsh -NoProfile -NonInteractive -Command 'try { Import-Module $env:AISDLC_CONFIG_MODULE -Force; if (Test-AiSdlcTrunkPushAllowed -RepoRoot $env:AISDLC_REPO_ROOT -Ref $env:AISDLC_REF) { exit 0 } } catch { }; exit 1' >/dev/null 2>&1 } -remote_name=$1 - is_zero_sha() { case "$1" in *[!0]*) return 1 ;; @@ -48,23 +49,20 @@ while read -r local_ref local_sha remote_ref remote_sha; do case "$remote_ref" in refs/heads/main|refs/heads/master) branch=${remote_ref#refs/heads/} - if ! trunk_push_allowed "$remote_name" "$branch"; then + if ! trunk_push_allowed "$remote_sha"; then echo "pre-push: a push to $branch is refused. A change reaches main only through a pull request that a person reviews and merges. Push the story branch and open or update its pull request instead." >&2 + if ! is_zero_sha "$remote_sha" && ! git cat-file -e "$remote_sha^{commit}" 2>/dev/null; then + echo "pre-push: the remote tip of $branch is not in this clone, so git.allowTrunkPush cannot be read from it. If the setting is on $branch, fetch first, then push again." >&2 + fi exit 1 fi if is_zero_sha "$local_sha"; then echo "pre-push: git.allowTrunkPush in aisdlc.json allows an update of $branch, not a delete. The delete is refused." >&2 exit 1 fi - if ! is_zero_sha "$remote_sha"; then - if ! git cat-file -e "$remote_sha^{commit}" 2>/dev/null; then - echo "pre-push: the remote tip of $branch is not in this clone, so this push cannot be checked as a fast-forward. Fetch first, then push again." >&2 - exit 1 - fi - if ! git merge-base --is-ancestor "$remote_sha" "$local_sha"; then - echo "pre-push: git.allowTrunkPush in aisdlc.json allows a fast-forward of $branch, not a force push. The push is refused." >&2 - exit 1 - fi + if ! git merge-base --is-ancestor "$remote_sha" "$local_sha"; then + echo "pre-push: git.allowTrunkPush in aisdlc.json allows a fast-forward of $branch, not a force push. The push is refused." >&2 + exit 1 fi echo "pre-push: git.allowTrunkPush in aisdlc.json allows this fast-forward of $branch. The blocking gates still run." ;; diff --git a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 index 0f94625..117d527 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -33,7 +33,9 @@ --atomic, --follow-tags, each written in full), a git option before push other than -C, and a push chained with any other command stay refused. So --force, --delete, --mirror and --no-verify are refused, also when shortened. The setting counts only when it is in aisdlc.json on the remote-tracking ref of - that main branch (refs/remotes//main), so an edit in the working tree cannot switch it on. The rest of the checks still run on such a + that main branch (refs/remotes//main), so an edit in the working tree cannot switch it on. + That ref lives in the clone, so it is a first check only. The pre-push git hook is the backstop: it + reads the setting from the remote tip that git passes during the push, which no local ref can change. The rest of the checks still run on such a push. A permission rule cannot see which branch a bare push targets, so this hook is the guard for Claude Code and Copilot CLI alike. It is registered for the Bash tool and for the PowerShell tool, because a repository diff --git a/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 index ade65e3..718248d 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 @@ -74,7 +74,7 @@ Describe 'The pre-push git hook' { # A repository with two commits on main, so a push can be a fast-forward or a rewrite. function Invoke-TrunkPush { - param([string]$Json, [ValidateSet('FastForward', 'Rewrite', 'Delete', 'UnknownRemote')][string]$Kind, [string]$WorkTreeJson) + param([string]$Json, [ValidateSet('FastForward', 'Rewrite', 'Delete', 'UnknownRemote')][string]$Kind, [string]$WorkTreeJson, [string]$SecondJson) $root = Join-Path ([System.IO.Path]::GetTempPath()) ('pre-push-' + [guid]::NewGuid().ToString('n')) New-Item -ItemType Directory -Path $root | Out-Null git -C $root init --quiet --initial-branch main @@ -86,10 +86,14 @@ Describe 'The pre-push git hook' { } git -C $root commit --quiet --allow-empty -m one --no-verify $first = (git -C $root rev-parse HEAD).Trim() + if ($SecondJson) { + Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value $SecondJson + git -C $root add aisdlc.json + } git -C $root commit --quiet --allow-empty -m two --no-verify $second = (git -C $root rev-parse HEAD).Trim() - # The remote main branch holds the committed setting; the hook reads it from there. - git -C $root update-ref refs/remotes/origin/main $first + # The remote-tracking ref may point anywhere; the hook must read the remote sha from stdin. + git -C $root update-ref refs/remotes/origin/main $(if ($SecondJson) { $second } else { $first }) if ($WorkTreeJson) { Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value $WorkTreeJson } $line = switch ($Kind) { 'FastForward' { "refs/heads/main $second refs/heads/main $first" } @@ -132,6 +136,12 @@ Describe 'The pre-push git hook' { $r.Output | Should -Match 'a push to main is refused' } + It 'reads the setting from the remote sha git passes, not from a local remote-tracking ref' -Skip:($script:NoSh -or $script:NoPwshHere) { + $r = Invoke-TrunkPush -Json '{}' -SecondJson $script:OptIn -Kind FastForward + $r.Code | Should -Be 1 + $r.Output | Should -Match 'a push to main is refused' + } + It 'refuses a fast-forward when only the working tree switches the setting on' -Skip:($script:NoSh -or $script:NoPwshHere) { $r = Invoke-TrunkPush -Json '{}' -WorkTreeJson $script:OptIn -Kind FastForward $r.Code | Should -Be 1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1415a0e..1fae576 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,8 @@ Each entry names its issue, as `#42`. push in a command, and with the setting it refuses `--no-verify`, a git option before `push`, and a push to `main` that is chained with other commands. Both hooks read the setting from `aisdlc.json` on the remote `main` branch, not from the working tree, so an edit that is not on `main` cannot switch - it on. + it on. The git hook reads it from the remote tip that git passes during the push, so a local ref + cannot switch it on either. ## v1.2.0 - 2026-11-07 diff --git a/apm.lock.yaml b/apm.lock.yaml index 8c855bf..3543dfa 100644 --- a/apm.lock.yaml +++ b/apm.lock.yaml @@ -331,7 +331,7 @@ dependencies: .claude/skills/ai-sdlc-gates/scripts/gitleaks-rules.json: sha256:6a8a75c5dbcf2378a1c52d046e34ce275aac7ce08a0ae61408d25c18e1e27014 .claude/skills/ai-sdlc-gates/scripts/gitleaks-version.json: sha256:c54acb854f87a1bbdf0e90c670b72b5de3cd37f7e460d82eca599c3c7af23a84 .claude/skills/ai-sdlc-gates/skill-catalog.json: sha256:5537684656bf189a740ba7e9e7050083af05668d00501ce1e9c6909cb8b91203 - .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:31ab2b37324dec52467b23dfc34ad7af70623600b0528deb31ba74b03e53acfd + .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:02e70e5febf8f5c377da8f209aebae347f1dd5c54abdb3c47c65e097b5551cda .claude/skills/ai-sdlc-handbook/SKILL.md: sha256:548e6b9ad79d3d2afa2f5779835988eeb12c49cda08917c4bbaa9ac0486a47a0 .claude/skills/ai-sdlc-handbook/references/README.md: sha256:654afcaa2b81f560eff93dbdef521b09ced06137a1dbb85d70a4e14ef7502248 .claude/skills/ai-sdlc-handbook/references/artifact-graph.md: sha256:d7ddfe20e5ee6565bcf25f9cef0f578da2a4ab1590033d791b8814d4688fd1f0 @@ -343,7 +343,7 @@ dependencies: .claude/skills/ai-sdlc-handbook/references/docs-wiki.md: sha256:2bd6f3a8e64f9db16163519767b822e4ebcffd740e3c5cbff17281ad71d264b7 .claude/skills/ai-sdlc-handbook/references/first-story.md: sha256:831552230cc16386ee01d7c730e288ef19aca5a66fafb00e1dfbbf4e9788caf2 .claude/skills/ai-sdlc-handbook/references/language.md: sha256:e0e32fae9c9fcdd23380d92ec910128254ce248538940541f5789ca78228a023 - .claude/skills/ai-sdlc-handbook/references/layout.md: sha256:b03868c6780c790b2b24acc33c165e46b6e7b99258a04d2d07bfbaed9c035ae6 + .claude/skills/ai-sdlc-handbook/references/layout.md: sha256:b37f18f29cdbef58bdf34ed17367b49d5a4a7ccd2e220fc3a1615effd4a8be31 .claude/skills/ai-sdlc-handbook/references/node-templates.md: sha256:8664ad1f85bff48d6230ed22e3f25683f378822e566c2a1454cbb204f4bb8fad .claude/skills/ai-sdlc-handbook/references/orchestration.md: sha256:6a1d6b6cc434f2e312994bd77daaa1fef4e007e03777ac63f3ca74edaa0cc485 .claude/skills/ai-sdlc-handbook/references/pattern.md: sha256:7908f80ee28ff1f7cd9f85b22fcf3e455fe74225d33ff201f8fbce1623d672eb @@ -358,13 +358,13 @@ dependencies: .claude/skills/ai-sdlc-hooks/githooks/post-commit: sha256:4f73a74133b0272725117fa9d962353abb6ed98d9cf5e731cd212fd5ace23271 .claude/skills/ai-sdlc-hooks/githooks/post-merge: sha256:b9f1f47cd3894406451e00c177912baeed66470b0cc18d581a5461330c7c0868 .claude/skills/ai-sdlc-hooks/githooks/post-rewrite: sha256:b7ee1a97b08a9826678829b6c49457fdc4b5ebd53eaf8cdd70f33d26e61c4a79 - .claude/skills/ai-sdlc-hooks/githooks/pre-push: sha256:66453196c7d3e116c1510bd6c75c5e02240d86dbd960dfbe3c29b73d290a61c4 + .claude/skills/ai-sdlc-hooks/githooks/pre-push: sha256:8083ee4f6a7d6c688a73d66ed31428cc602f87d7742b29c1c2210804ac9d04c5 .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1: sha256:004bc7f1a68e953c8e657b49e74755b69a14138dfb0db61162ab15420f2b24be .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1: sha256:b3569de6e27c3dcaffbc082311e6882bd722d440e5e855245da2410033202c7e .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1: sha256:4c4e1f6b673671125290d78815c72277665a8a618b55fd589f75f3a36e3b80aa .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1: sha256:46d1d83e38e75db41b1f370bc6f49f4800f0234765eac63c53e37b5af7000453 .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1: sha256:ea9062bd8b20ad47d488b9838eb5a6c735d73b3148cdcfdd9ebdd60ef708f897 - .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1: sha256:b291a529130c4216e473e271a827f8fb3bf96be77480a4195ce2adbfa68217ec + .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1: sha256:72d8b73859a105ebbf86838a016b0b61a630e4f28eec5d6d1d86e03fb085c6e4 .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1: sha256:1c46576b9633bd12286efa11cc9f7c6c2f982f29859f9a33272f76452888e77b .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1: sha256:fccaa2da3a0254cc8a7740974f07b1c0fc1e67106ae7191d9710cbf699da1ba7 .claude/skills/ai-sdlc-hooks/scripts/Find-RetiredSkillNames.Tests.ps1: sha256:151c3ee69c88db0d85cf4c94207b04dfc4eabe857e178051044ed4fdcee58f33 @@ -384,7 +384,7 @@ dependencies: .claude/skills/ai-sdlc-hooks/scripts/Invoke-PostEditCheck.ps1: sha256:d60cdd2d341487ded3b9fafe40da49f2adfb1cf8f20cf3f8559ea2e80a5f93c6 .claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.Tests.ps1: sha256:9c9859767d2534c45e1c72b47f4b5c64aaa16c32c580df3b5d8bc3dce5cdb2c4 .claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.ps1: sha256:abf763c6cde97dbfc83b25f140e768d66fd9edd3961605b7d058b08a31882875 - .claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1: sha256:00ecc72b23d941c31859bcb922474dcbcbea528ae02f37570b30e2dc5b9da095 + .claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1: sha256:de023a2c91558728f72e02091986607941ef6b7ef0e6df7602d944e20219ae4b .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1: sha256:4f2fe5313c8763f8128ad0e0347da1f2dd485393d20dc5e3a5d75e08aa157ad3 .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1: sha256:0381e47c6b1070c7b230f81f243e25b1a8bfa68b5e8e9ae2ad6e225b0ddb36b6 .claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.Tests.ps1: sha256:52f81e945390e61222a2668c8525cb17f17226267e24c52d7792263a07576543 @@ -1551,7 +1551,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:31ab2b37324dec52467b23dfc34ad7af70623600b0528deb31ba74b03e53acfd + content_hash: sha256:02e70e5febf8f5c377da8f209aebae347f1dd5c54abdb3c47c65e097b5551cda - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook @@ -1668,7 +1668,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:b03868c6780c790b2b24acc33c165e46b6e7b99258a04d2d07bfbaed9c035ae6 + content_hash: sha256:b37f18f29cdbef58bdf34ed17367b49d5a4a7ccd2e220fc3a1615effd4a8be31 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook/references/node-templates.md @@ -1812,7 +1812,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:66453196c7d3e116c1510bd6c75c5e02240d86dbd960dfbe3c29b73d290a61c4 + content_hash: sha256:8083ee4f6a7d6c688a73d66ed31428cc602f87d7742b29c1c2210804ac9d04c5 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1 @@ -1866,7 +1866,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:b291a529130c4216e473e271a827f8fb3bf96be77480a4195ce2adbfa68217ec + content_hash: sha256:72d8b73859a105ebbf86838a016b0b61a630e4f28eec5d6d1d86e03fb085c6e4 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1 @@ -2046,7 +2046,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:00ecc72b23d941c31859bcb922474dcbcbea528ae02f37570b30e2dc5b9da095 + content_hash: sha256:de023a2c91558728f72e02091986607941ef6b7ef0e6df7602d944e20219ae4b - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1 diff --git a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json index 2529eeb..fb4e8ae 100644 --- a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json +++ b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json @@ -114,7 +114,7 @@ ".claude/skills/ai-sdlc-handbook/references/docs-wiki.md": "038477c9b704a5b545decfe5e3f3f9970d8d1f9d", ".claude/skills/ai-sdlc-handbook/references/first-story.md": "be899eb395dafb2d704b8f0cb46bac1fb5e593c8", ".claude/skills/ai-sdlc-handbook/references/language.md": "ca703edeb9e07e28e32a39fbcc9116b64db444d8", - ".claude/skills/ai-sdlc-handbook/references/layout.md": "92bf66ab0b736782e25982ed74866c9826476363", + ".claude/skills/ai-sdlc-handbook/references/layout.md": "b6683bbb25c614a5d0a3f8283d4e46bfa110bcd2", ".claude/skills/ai-sdlc-handbook/references/node-templates.md": "580c9c92c470a6abbaa0145cc3060ff1a11d247c", ".claude/skills/ai-sdlc-handbook/references/orchestration.md": "22373827d6ecd454d93cfb652f76c5204f3215e2", ".claude/skills/ai-sdlc-handbook/references/pattern.md": "f0f2a8cf3dac267cda0fd3783d86bddba5afc7c0", @@ -130,12 +130,12 @@ ".claude/skills/ai-sdlc-hooks/githooks/post-commit": "f18058f9a38efc164e13801d61bb05329a056109", ".claude/skills/ai-sdlc-hooks/githooks/post-merge": "bb373f33abd09294cda55d7fc4499f32672eb372", ".claude/skills/ai-sdlc-hooks/githooks/post-rewrite": "e4c187dffeeaba569901f3424fae476b17c14927", - ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "267f418c8e3c6b910d2bb7b680ac5f0ffceb1dc1", + ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "490c81fd333d26cf9f09877fecb369d531710d66", ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1": "52ffd325d13cd403e7bfea0de8098c530c129b65", ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "ef5b30f0811181462d354a61d3e64c19f0c305e2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", - ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "0f946257b55c99127482226fdff6b14a98973071", + ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "117d527a075a78017b0a199703d84a6807797573", ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1": "73947a2a69aecf0e73a11640a0c21d081d43c4d8", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.ps1": "ca703a9e057633e39af161d9e43a042429813acc", ".claude/skills/ai-sdlc-hooks/scripts/Deny-SharedFileEdit.Tests.ps1": "d15bf28d4191b5e2bca8ce59621ad03a1ef6198c", @@ -156,7 +156,7 @@ ".claude/skills/ai-sdlc-hooks/scripts/Invoke-PostEditCheck.Tests.ps1": "3429e18735428ab387ab58ae276d4195b32e7999", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.ps1": "b54f90deb751d0b0dbf8ee8fbc3f39b3300b3b3d", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.Tests.ps1": "77e4b627da13ea9887f3918f66bc5b33dfd91c56", - ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "ade65e330fbe44cc947b18b428ccd4fbf139fb4e", + ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "718248ded3ba695b29d4d7eb59e8f09130cf918c", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1": "56abaf1de1c17bea94c26e128f8c41e275a74f87", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1": "8db305e438bc7ee404eb5106eacbe5581738f148", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.ps1": "fa3d7f509b6f9a1a935178c1eaf0d1566b7afead", diff --git a/core/.apm/skills/ai-sdlc-handbook/references/layout.md b/core/.apm/skills/ai-sdlc-handbook/references/layout.md index 92bf66a..b6683bb 100644 --- a/core/.apm/skills/ai-sdlc-handbook/references/layout.md +++ b/core/.apm/skills/ai-sdlc-handbook/references/layout.md @@ -129,7 +129,7 @@ installs. `AiSdlcConfig.psm1` takes each dependency whose path ends in `packs//main). Without pwsh, the config module or -# that ref, the setting cannot be read, so the push is refused. +# stay refused. The blocking gates still run on such a push. The setting counts only in aisdlc.json of +# the commit that is the remote tip of that branch, which git passes on stdin. Without pwsh, the config +# module or that commit in the clone, the setting cannot be read, so the push is refused. # git passes one line per ref on stdin: . # `git lfs pre-push` needs the same lines at the end, so they are read once and kept. -# The setting is read from aisdlc.json on the remote-tracking ref of the branch ($1 is the remote, $2 the -# branch), not from the working tree, so an edit that is not on the remote main branch yet cannot switch it on. +# The setting is read from aisdlc.json in the commit that is the tip of the remote branch now. git +# learns that commit from the remote while it pushes and passes it on stdin as , so neither +# an edit in the working tree nor a local ref can switch the setting on. A new branch (zero sha) or a tip +# that is not in this clone counts as off. $1 is that remote sha. trunk_push_allowed() { + is_zero_sha "$1" && return 1 + git cat-file -e "$1^{commit}" 2>/dev/null || return 1 command -v pwsh >/dev/null 2>&1 || return 1 module="$(dirname "$0")/../../ai-sdlc-gates/scripts/AiSdlcConfig.psm1" [ -f "$module" ] || return 1 - AISDLC_CONFIG_MODULE="$module" AISDLC_REPO_ROOT="$(git rev-parse --show-toplevel)" AISDLC_REF="refs/remotes/$1/$2" \ - pwsh -NoProfile -NonInteractive -Command 'try { Import-Module $env:AISDLC_CONFIG_MODULE -Force; if (Test-AiSdlcTrunkPushAllowed -RepoRoot $env:AISDLC_REPO_ROOT -Ref $env:AISDLC_REF) { exit 0 } } catch { }; exit 1' >/dev/null 2>&1 + AISDLC_CONFIG_MODULE="$module" AISDLC_REPO_ROOT="$(git rev-parse --show-toplevel)" AISDLC_REF="$1" pwsh -NoProfile -NonInteractive -Command 'try { Import-Module $env:AISDLC_CONFIG_MODULE -Force; if (Test-AiSdlcTrunkPushAllowed -RepoRoot $env:AISDLC_REPO_ROOT -Ref $env:AISDLC_REF) { exit 0 } } catch { }; exit 1' >/dev/null 2>&1 } -remote_name=$1 - is_zero_sha() { case "$1" in *[!0]*) return 1 ;; @@ -48,23 +49,20 @@ while read -r local_ref local_sha remote_ref remote_sha; do case "$remote_ref" in refs/heads/main|refs/heads/master) branch=${remote_ref#refs/heads/} - if ! trunk_push_allowed "$remote_name" "$branch"; then + if ! trunk_push_allowed "$remote_sha"; then echo "pre-push: a push to $branch is refused. A change reaches main only through a pull request that a person reviews and merges. Push the story branch and open or update its pull request instead." >&2 + if ! is_zero_sha "$remote_sha" && ! git cat-file -e "$remote_sha^{commit}" 2>/dev/null; then + echo "pre-push: the remote tip of $branch is not in this clone, so git.allowTrunkPush cannot be read from it. If the setting is on $branch, fetch first, then push again." >&2 + fi exit 1 fi if is_zero_sha "$local_sha"; then echo "pre-push: git.allowTrunkPush in aisdlc.json allows an update of $branch, not a delete. The delete is refused." >&2 exit 1 fi - if ! is_zero_sha "$remote_sha"; then - if ! git cat-file -e "$remote_sha^{commit}" 2>/dev/null; then - echo "pre-push: the remote tip of $branch is not in this clone, so this push cannot be checked as a fast-forward. Fetch first, then push again." >&2 - exit 1 - fi - if ! git merge-base --is-ancestor "$remote_sha" "$local_sha"; then - echo "pre-push: git.allowTrunkPush in aisdlc.json allows a fast-forward of $branch, not a force push. The push is refused." >&2 - exit 1 - fi + if ! git merge-base --is-ancestor "$remote_sha" "$local_sha"; then + echo "pre-push: git.allowTrunkPush in aisdlc.json allows a fast-forward of $branch, not a force push. The push is refused." >&2 + exit 1 fi echo "pre-push: git.allowTrunkPush in aisdlc.json allows this fast-forward of $branch. The blocking gates still run." ;; diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 index 0f94625..117d527 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1 @@ -33,7 +33,9 @@ --atomic, --follow-tags, each written in full), a git option before push other than -C, and a push chained with any other command stay refused. So --force, --delete, --mirror and --no-verify are refused, also when shortened. The setting counts only when it is in aisdlc.json on the remote-tracking ref of - that main branch (refs/remotes//main), so an edit in the working tree cannot switch it on. The rest of the checks still run on such a + that main branch (refs/remotes//main), so an edit in the working tree cannot switch it on. + That ref lives in the clone, so it is a first check only. The pre-push git hook is the backstop: it + reads the setting from the remote tip that git passes during the push, which no local ref can change. The rest of the checks still run on such a push. A permission rule cannot see which branch a bare push targets, so this hook is the guard for Claude Code and Copilot CLI alike. It is registered for the Bash tool and for the PowerShell tool, because a repository diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 index ade65e3..718248d 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 @@ -74,7 +74,7 @@ Describe 'The pre-push git hook' { # A repository with two commits on main, so a push can be a fast-forward or a rewrite. function Invoke-TrunkPush { - param([string]$Json, [ValidateSet('FastForward', 'Rewrite', 'Delete', 'UnknownRemote')][string]$Kind, [string]$WorkTreeJson) + param([string]$Json, [ValidateSet('FastForward', 'Rewrite', 'Delete', 'UnknownRemote')][string]$Kind, [string]$WorkTreeJson, [string]$SecondJson) $root = Join-Path ([System.IO.Path]::GetTempPath()) ('pre-push-' + [guid]::NewGuid().ToString('n')) New-Item -ItemType Directory -Path $root | Out-Null git -C $root init --quiet --initial-branch main @@ -86,10 +86,14 @@ Describe 'The pre-push git hook' { } git -C $root commit --quiet --allow-empty -m one --no-verify $first = (git -C $root rev-parse HEAD).Trim() + if ($SecondJson) { + Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value $SecondJson + git -C $root add aisdlc.json + } git -C $root commit --quiet --allow-empty -m two --no-verify $second = (git -C $root rev-parse HEAD).Trim() - # The remote main branch holds the committed setting; the hook reads it from there. - git -C $root update-ref refs/remotes/origin/main $first + # The remote-tracking ref may point anywhere; the hook must read the remote sha from stdin. + git -C $root update-ref refs/remotes/origin/main $(if ($SecondJson) { $second } else { $first }) if ($WorkTreeJson) { Set-Content -LiteralPath (Join-Path $root 'aisdlc.json') -Value $WorkTreeJson } $line = switch ($Kind) { 'FastForward' { "refs/heads/main $second refs/heads/main $first" } @@ -132,6 +136,12 @@ Describe 'The pre-push git hook' { $r.Output | Should -Match 'a push to main is refused' } + It 'reads the setting from the remote sha git passes, not from a local remote-tracking ref' -Skip:($script:NoSh -or $script:NoPwshHere) { + $r = Invoke-TrunkPush -Json '{}' -SecondJson $script:OptIn -Kind FastForward + $r.Code | Should -Be 1 + $r.Output | Should -Match 'a push to main is refused' + } + It 'refuses a fast-forward when only the working tree switches the setting on' -Skip:($script:NoSh -or $script:NoPwshHere) { $r = Invoke-TrunkPush -Json '{}' -WorkTreeJson $script:OptIn -Kind FastForward $r.Code | Should -Be 1