Repository navigation
chore: sync from monorepo @b0ace50 #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,55 +1,62 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright 2026 ResQ Software | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Canonical ResQ commit-msg shim — source: resq-software/dev. | ||
| # Enforces Conventional Commits; blocks fixup/squash/WIP on main/master. | ||
|
|
||
| set -euo pipefail | ||
| # | ||
| # Copyright 2026 ResQ | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # commit-msg | ||
| # | ||
| # Validates the commit message format. | ||
| # Ensures the subject line follows the Conventional Commits specification. | ||
| # | ||
| # Usage: | ||
| # .git-hooks/commit-msg COMMIT_MSG_FILE | ||
| # | ||
| # Arguments: | ||
| # $1 - Path to the file containing the commit message. | ||
| # | ||
| # Exit codes: | ||
| # 0 Commit message is valid. | ||
| # 1 Commit message is invalid. | ||
|
|
||
| [ -n "${GIT_HOOKS_SKIP:-}" ] && exit 0 | ||
|
|
||
| INPUT_FILE="${1:-}" | ||
| # git always passes the message file, but the `${1:-}` default means a hook run | ||
| # by hand, or by a tool that forgets the argument, reaches `head -1 ""` instead — | ||
| # and `set -e` turns that into a bare tool error naming neither the hook nor the | ||
| # cause. Fail here, where the message can say what was expected. | ||
| if [ -z "$INPUT_FILE" ] || [ ! -f "$INPUT_FILE" ]; then | ||
| echo "❌ commit-msg: expected a commit-message file as \$1, got '$INPUT_FILE'." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # INPUT_FILE stores the path to the commit message file. | ||
| INPUT_FILE=${1:-} | ||
| # PATTERN is the regular expression for a valid Conventional Commit message. | ||
| PATTERN="^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?(!)?: .+$" | ||
|
|
||
| # Validate only the first line (subject). Strip an optional [TICKET-123] prefix | ||
| # inserted by prepare-commit-msg so the two hooks don't conflict. | ||
| FIRST_LINE=$(head -1 "$INPUT_FILE") | ||
| # Ticket-prefix regex matches what prepare-commit-msg prepends ({2,} chars). | ||
| SUBJECT=$(sed -E 's/^\[[A-Z]{2,}-[0-9]+\][[:space:]]*//' <<<"$FIRST_LINE") | ||
|
|
||
| # WIP / fixup! / squash! guard runs *before* the format check so users get | ||
| # a branch-specific error message on main/master instead of the generic | ||
| # "Invalid commit message format". | ||
| BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || echo "") | ||
| case "$BRANCH" in | ||
| main|master) | ||
| if grep -qiE "^(\[[A-Z]{2,}-[0-9]+\] )?(fixup!|squash!|wip[: ])" <<<"$FIRST_LINE"; then | ||
| echo "Error: fixup!/squash!/WIP commits are not allowed on $BRANCH." | ||
| echo "Create a feature branch instead." | ||
| exit 1 | ||
| fi | ||
| ;; | ||
| esac | ||
| SUBJECT=$(echo "$FIRST_LINE" | sed 's/^\[[A-Z][A-Z]*-[0-9]*\] //') | ||
|
|
||
| if ! grep -qE "$PATTERN" <<<"$SUBJECT"; then | ||
| if ! echo "$SUBJECT" | grep -qE "$PATTERN"; then | ||
| echo "Error: Invalid commit message format." | ||
| echo "Expected: type(scope)(!): subject" | ||
| echo "Expected format: type(scope): subject" | ||
| echo "Examples:" | ||
| echo " feat(core): add new feature" | ||
| echo " feat!: remove deprecated API (breaking change marker)" | ||
| echo " fix(ui): fix button color" | ||
| exit 1 | ||
| fi | ||
|
|
||
| LOCAL_HOOK="$(git rev-parse --show-toplevel)/.git-hooks/local-commit-msg" | ||
| if [ -x "$LOCAL_HOOK" ]; then | ||
| exec "$LOCAL_HOOK" "$@" | ||
| # Block fixup!/WIP commits on main | ||
| BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || echo "") | ||
| if [ "$BRANCH" = "main" ]; then | ||
| if echo "$FIRST_LINE" | grep -qiE "^(\[[A-Z]+-[0-9]+\] )?(fixup!|squash!|wip[: ])"; then | ||
| echo "Error: fixup!/squash!/WIP commits are not allowed on main." | ||
| echo "Create a feature branch instead." | ||
| exit 1 | ||
| fi | ||
| fi | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,71 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright 2026 ResQ Software | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Canonical ResQ post-checkout shim — source: resq-software/dev. | ||
| # Notifies when lock files change so devs know to resync dependencies. | ||
|
|
||
| set -euo pipefail | ||
| # | ||
| # Copyright 2026 ResQ | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # post-checkout | ||
| # | ||
| # Automatically installs dependencies when lock files change during branch checkout. | ||
| # | ||
| # Usage: | ||
| # .git-hooks/post-checkout PREV_HEAD NEW_HEAD IS_BRANCH_CHECKOUT | ||
| # | ||
| # Arguments: | ||
| # $1 - Previous HEAD commit hash. | ||
| # $2 - New HEAD commit hash. | ||
| # $3 - Flag indicating if it's a branch checkout (1) or file checkout (0). | ||
| # | ||
| # Exit codes: | ||
| # 0 Always. | ||
|
|
||
| [ -n "${GIT_HOOKS_SKIP:-}" ] && exit 0 | ||
|
|
||
| # PREV_HEAD stores the commit hash before checkout. | ||
| PREV_HEAD="${1:-}" | ||
| # NEW_HEAD stores the commit hash after checkout. | ||
| NEW_HEAD="${2:-}" | ||
| # IS_BRANCH_CHECKOUT is "1" if a branch was checked out, "0" otherwise. | ||
| IS_BRANCH_CHECKOUT="${3:-}" | ||
|
|
||
| if [ "$IS_BRANCH_CHECKOUT" = "1" ] && [ "$PREV_HEAD" != "$NEW_HEAD" ]; then | ||
| CHANGED=$(git diff --name-only "$PREV_HEAD" "$NEW_HEAD" 2>/dev/null || true) | ||
| # Only run on branch checkouts, not file checkouts | ||
| if [ "$IS_BRANCH_CHECKOUT" != "1" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Matched by basename rather than anchored to the repository root: a monorepo | ||
| # keeps lockfiles in nested workspaces (`libs/dotnet/flake.lock`, | ||
| # `programs/Cargo.lock`), and a root-anchored pattern ignores them all. | ||
| grep -qE "(^|/)Cargo\.lock$" <<<"$CHANGED" && echo "📦 Cargo.lock changed — run: cargo build" | ||
| # `\?` is a GNU BRE extension; BSD grep on macOS reads it as a literal `?`, | ||
| # so the optional-`b` form needs ERE to match on every developer's box. | ||
| grep -qE "(^|/)bun\.lockb?$" <<<"$CHANGED" && echo "📦 bun.lock changed — run: bun install" | ||
| grep -qE "(^|/)uv\.lock$" <<<"$CHANGED" && echo "📦 uv.lock changed — run: uv sync" | ||
| grep -qE "(^|/)flake\.lock$" <<<"$CHANGED" && echo "📦 flake.lock changed — exit and re-enter: nix develop" | ||
| # Skip if both heads are the same (no actual branch change) | ||
| if [ "$PREV_HEAD" = "$NEW_HEAD" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| LOCAL_HOOK="$(git rev-parse --show-toplevel)/.git-hooks/local-post-checkout" | ||
| if [ -x "$LOCAL_HOOK" ]; then | ||
| exec "$LOCAL_HOOK" "$@" | ||
| # CHANGED stores the list of files that differ between the two heads. | ||
| CHANGED=$(git diff --name-only "$PREV_HEAD" "$NEW_HEAD" 2>/dev/null) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle the null previous HEAD before diffing. When Git creates a worktree, it passes a null previous HEAD and flag Skip the null previous HEAD or compare against the empty tree. Keep normal commit-to-commit comparisons.
|
||
|
|
||
| # Check if Cargo.lock changed | ||
| if echo "$CHANGED" | grep -q "^Cargo\.lock$"; then | ||
| echo "📦 Cargo.lock changed — dependencies will update on next build" | ||
| fi | ||
|
|
||
| exit 0 | ||
| # Check if bun.lockb changed | ||
| if echo "$CHANGED" | grep -q "^bun\.lockb$"; then | ||
| if [ -n "${SKIP_BUN_INSTALL:-}" ]; then | ||
| echo "📦 bun.lockb changed — skipping install (SKIP_BUN_INSTALL set)" | ||
| elif command -v bun >/dev/null 2>&1; then | ||
| echo "📦 bun.lockb changed — running bun install..." | ||
| bun install --frozen-lockfile 2>/dev/null || bun install | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep optional installation failures from failing checkout. If both Bun attempts fail, the final command triggers Handle the final failure explicitly. Print a warning with the manual recovery command and return success. Print the success message only when installation succeeds.
|
||
| echo "✅ JS dependencies updated" | ||
| else | ||
| echo "⚠️ bun not found — run 'bun install' manually" | ||
| fi | ||
| fi | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve whitespace handling after a ticket prefix.
With
git commit -m "[PROJ-123] feat: add validation", this substitution leaves one leading space. The format check then rejects the commit. The previous implementation removed all whitespace after the prefix and accepted this subject. Restore whitespace-flexible stripping after]; the generated single-space prefix will still work. (raw.githubusercontent.com)