Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .claude/skills/repo-ci-baseline/references/git-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
Expand Down
15 changes: 9 additions & 6 deletions scripts/check-branch-name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
Loading