From cb3e122b2aacc5902a8498bfb5e7bf6cb7771d49 Mon Sep 17 00:00:00 2001 From: T <60372079+mpaulosky@users.noreply.github.com> Date: Tue, 10 Nov 2026 12:01:02 -0800 Subject: [PATCH] fix(baseline): Keep the --pr branch check lenient for Dependabot and widen the hook's shell-safe class #37 made the CI Branch name job refuse a dependabot/* name with a character outside A-Za-z0-9._-. The --pr form takes any dependabot/* again; the hook form also takes '@' and '+'. Refs #40 Co-Authored-By: Claude Sonnet 5.5 --- .../repo-ci-baseline/references/git-hooks.md | 7 ++++--- .../template/owned/scripts/check-branch-name.sh | 15 +++++++++------ .../scripts/tests/check-branch-name.test.sh | 17 +++++++++++++++++ scripts/check-branch-name.sh | 15 +++++++++------ 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/.claude/skills/repo-ci-baseline/references/git-hooks.md b/.claude/skills/repo-ci-baseline/references/git-hooks.md index 178a57c..9795f3c 100644 --- a/.claude/skills/repo-ci-baseline/references/git-hooks.md +++ b/.claude/skills/repo-ci-baseline/references/git-hooks.md @@ -38,8 +38,9 @@ standard in the first place. The check guards the process, not against a hostile PR. Under `pull_request` the job runs the PR's own copy of the script and of `ci.yml`, so a PR can change either, as it can for `Build Solution`; such an edit shows in its review. -The CI job also accepts the branches that only Actions create, which no hook sees: -`docs/release-notes` (`release.yml`) and `docs/backfill-blog-posts` (`backfill-blog-posts.yml`). `dependabot/*` is allowed by the hook too, so a person can push a fix to a Dependabot PR. +The CI job also accepts the branches that only Actions and Dependabot create, which no hook sees: +`docs/release-notes` (`release.yml`), `docs/backfill-blog-posts` (`backfill-blog-posts.yml`) and any `dependabot/*`, whatever its characters, since CI quotes the name. +The hook accepts a `dependabot/*` branch too, in shell-safe characters only (`A-Za-z0-9._@+-` per segment), so a person can push a fix to a Dependabot PR. Fork PRs skip the job, which a required check counts as passing. ## Worktree standard @@ -132,7 +133,7 @@ checkout and from a subfolder of it (refused, before the lint), the opt-out, a l and `git commit` end to end, which runs the hook with `GIT_DIR` set. `scripts/tests/check-branch-name.test.sh` covers the script's `--pr` form, which the CI job uses: the Actions -branches allowed only there, Dependabot's allowed everywhere, a `claude/...` branch refused, and other `docs/` names refused. +branches and any `dependabot/*` allowed only there, a shell-safe `dependabot/*` allowed for a push too, a `claude/...` branch refused, and other `docs/` names refused. CI's hook-tests job runs this suite, `pre-commit.test.sh`, `check-branch-name.test.sh`, `check-pr-title.test.sh` and `sync-copilot-review.test.sh`. diff --git a/.claude/skills/repo-ci-baseline/template/owned/scripts/check-branch-name.sh b/.claude/skills/repo-ci-baseline/template/owned/scripts/check-branch-name.sh index 7d0f096..83142fd 100755 --- a/.claude/skills/repo-ci-baseline/template/owned/scripts/check-branch-name.sh +++ b/.claude/skills/repo-ci-baseline/template/owned/scripts/check-branch-name.sh @@ -6,8 +6,8 @@ # # The pre-push hook runs the first form on each pushed branch. ci.yml's # "Branch name" job runs the second on a PR's head branch, which also accepts -# the branches Actions create, since no hook ever sees them. Dependabot's -# dependabot/* is allowed in both forms. +# the branches Actions and Dependabot create, since no hook ever sees them. +# The pre-push hook also lets a person push to a Dependabot branch (see below). # CI is what catches a push that skipped the hook: a Claude cloud session's # claude/... branch, GitHub's web editor, or a clone without core.hooksPath. # Exits 0 when the name is allowed, 1 (with the reason) when it isn't. @@ -29,13 +29,16 @@ if [[ "$branch" =~ ^(feature|fix|hotfix)/[0-9]+-[a-z0-9]+(-[a-z0-9]+)*$ ]] \ fi # Dependabot's branches can't be renamed, and a person pushes to one to fix its PR (mirroring a bump into the Template's file, say), -# so the hook allows them too, in shell-safe characters only. Sandcastle hands off no such branch (lib/branches.mts#isHandOffBranch). -if [[ "$branch" =~ ^dependabot/[A-Za-z0-9._-]+(/[A-Za-z0-9._-]+)*$ ]]; then +# so the hook allows them too, in shell-safe characters only ('@' and '+' included, which a scoped package or a version can carry). +# Sandcastle hands off no such branch (lib/branches.mts#isHandOffBranch). The --pr form below takes any dependabot/* name, as it did +# before the hook did: CI quotes the name, and refusing a Dependabot branch for a character would block its PR. +if [[ "$branch" =~ ^dependabot/[A-Za-z0-9._@+-]+(/[A-Za-z0-9._@+-]+)*$ ]]; then exit 0 fi -# Made by release.yml and backfill-blog-posts.yml. -if [[ "$pr" == true ]] && [[ "$branch" == docs/release-notes || "$branch" == docs/backfill-blog-posts ]]; then +# Made by release.yml, backfill-blog-posts.yml and Dependabot. +if [[ "$pr" == true ]] \ + && [[ "$branch" == docs/release-notes || "$branch" == docs/backfill-blog-posts || "$branch" == dependabot/* ]]; then exit 0 fi diff --git a/.claude/skills/repo-ci-baseline/template/owned/scripts/tests/check-branch-name.test.sh b/.claude/skills/repo-ci-baseline/template/owned/scripts/tests/check-branch-name.test.sh index 27d8d70..f051fa9 100644 --- a/.claude/skills/repo-ci-baseline/template/owned/scripts/tests/check-branch-name.test.sh +++ b/.claude/skills/repo-ci-baseline/template/owned/scripts/tests/check-branch-name.test.sh @@ -39,6 +39,23 @@ expect refused "" expect allowed dependabot/github_actions/main/minor-and-patch-actions-401d4b32a3 expect allowed --pr dependabot/nuget/all-nuget-1a2b3c expect refused dependabot +# Scoped npm packages and build-metadata versions: '@' and '+' are shell-safe, so the hook takes them. +expect allowed dependabot/npm_and_yarn/@types/node-20.1.0 +expect allowed dependabot/nuget/Foo.Bar_1.2.3+build.5 +expect allowed dependabot/@scope/x +expect allowed dependabot/a+b +# The pattern is anchored at the start: dependabot/ inside another name is not a Dependabot branch. +expect refused claude/dependabot/x +expect refused xdependabot/a +# The --pr form takes any dependabot/* name, as before the hook did: CI quotes it, and a PR must not fail on a character. +expect allowed --pr dependabot/npm_and_yarn/types/node-20~1 +expect allowed --pr dependabot/ +# Shell-unsafe or malformed names stay refused for a push. +expect refused dependabot/ +expect refused dependabot/a/ +expect refused dependabot//a +expect refused Dependabot/x +expect refused $'dependabot/a\nb' expect refused "dependabot/x;rm" # shellcheck disable=SC2016 # the \$( is the point: a literal name, not an expansion expect refused 'dependabot/$(x)' diff --git a/scripts/check-branch-name.sh b/scripts/check-branch-name.sh index 7d0f096..83142fd 100755 --- a/scripts/check-branch-name.sh +++ b/scripts/check-branch-name.sh @@ -6,8 +6,8 @@ # # The pre-push hook runs the first form on each pushed branch. ci.yml's # "Branch name" job runs the second on a PR's head branch, which also accepts -# the branches Actions create, since no hook ever sees them. Dependabot's -# dependabot/* is allowed in both forms. +# the branches Actions and Dependabot create, since no hook ever sees them. +# The pre-push hook also lets a person push to a Dependabot branch (see below). # CI is what catches a push that skipped the hook: a Claude cloud session's # claude/... branch, GitHub's web editor, or a clone without core.hooksPath. # Exits 0 when the name is allowed, 1 (with the reason) when it isn't. @@ -29,13 +29,16 @@ if [[ "$branch" =~ ^(feature|fix|hotfix)/[0-9]+-[a-z0-9]+(-[a-z0-9]+)*$ ]] \ fi # Dependabot's branches can't be renamed, and a person pushes to one to fix its PR (mirroring a bump into the Template's file, say), -# so the hook allows them too, in shell-safe characters only. Sandcastle hands off no such branch (lib/branches.mts#isHandOffBranch). -if [[ "$branch" =~ ^dependabot/[A-Za-z0-9._-]+(/[A-Za-z0-9._-]+)*$ ]]; then +# so the hook allows them too, in shell-safe characters only ('@' and '+' included, which a scoped package or a version can carry). +# Sandcastle hands off no such branch (lib/branches.mts#isHandOffBranch). The --pr form below takes any dependabot/* name, as it did +# before the hook did: CI quotes the name, and refusing a Dependabot branch for a character would block its PR. +if [[ "$branch" =~ ^dependabot/[A-Za-z0-9._@+-]+(/[A-Za-z0-9._@+-]+)*$ ]]; then exit 0 fi -# Made by release.yml and backfill-blog-posts.yml. -if [[ "$pr" == true ]] && [[ "$branch" == docs/release-notes || "$branch" == docs/backfill-blog-posts ]]; then +# Made by release.yml, backfill-blog-posts.yml and Dependabot. +if [[ "$pr" == true ]] \ + && [[ "$branch" == docs/release-notes || "$branch" == docs/backfill-blog-posts || "$branch" == dependabot/* ]]; then exit 0 fi