- 吸收来自 hose-sealai-bridge 仓库的近期协作与开发规范演进 - 增强 Git Hooks 防护体系: - .githooks/pre-commit:拦截主干分支 (main/master) 直接提交,校验分支全小写与设备前缀,拦截 >15MB 单文件与 Windows 非法字符/保留设备名 - .githooks/pre-push:拦截向远端推送含大写字母的分支名 - .githooks/branch-guard.sh:增加大写字符强校验 - .githooks/setup.sh & setup.ps1:跨平台一键配置 hooksPath、autocrlf 与 symlinks - 跨平台与敏感文件防护: - 新增 .gitattributes 固化 LF 换行符(防止 Windows 下 CRLF 篡改 Shell 脚本) - 更新 .gitignore 增加 .env、*.pem、*.key 及 .drafts/* 忽略 - 确立 Markdown 实体先行标准 (Markdown-First): - 设立 .drafts/ 目录作为草稿落盘规范 - 新增项目级 Skill .agents/skills/repo-gh/SKILL.md - 新增 .agents/rules/windows-development.md - 更新 .agents/rules/issue-pr-workflow.md、.agents/rules/branch-naming.md、.agents/README.md 与 AGENTS.md
52 lines
2.0 KiB
Bash
Executable File
52 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Shared branch-naming guard: .agents/rules/branch-naming.md
|
|
# Devices opt in per clone: git config seal.branchPrefix <device-key> (e.g. mac15)
|
|
# Sourced by pre-commit and pre-push.
|
|
|
|
# guard_branch_name <branch> — returns 1 with guidance when the name breaks the rule.
|
|
guard_branch_name() {
|
|
local branch="$1"
|
|
[ -n "$branch" ] || return 0
|
|
|
|
# Check for uppercase letters in branch name (Windows/macOS case-insensitivity vs Linux collision)
|
|
if echo "$branch" | grep -q '[A-Z]'; then
|
|
local lowercase_branch
|
|
lowercase_branch=$(echo "$branch" | tr '[:upper:]' '[:lower:]')
|
|
echo "" >&2
|
|
echo "🛑 [branch-guard] Branch '$branch' contains uppercase letters." >&2
|
|
echo " Branches must be strictly lowercase (.agents/rules/windows-development.md)." >&2
|
|
echo " 👉 Rename and retry: git branch -m '$lowercase_branch'" >&2
|
|
echo " (One-off bypass: git commit --no-verify / git push --no-verify)" >&2
|
|
echo "" >&2
|
|
return 1
|
|
fi
|
|
|
|
# Reserved names: mainline branches and the release automation.
|
|
case "$branch" in
|
|
main|master|develop) return 0 ;;
|
|
codex/release-*) return 0 ;;
|
|
esac
|
|
|
|
# Enforcement is opt-in per device; without a configured prefix this guard is dormant.
|
|
local prefix
|
|
prefix="$(git config seal.branchPrefix 2>/dev/null || true)"
|
|
[ -n "$prefix" ] || return 0
|
|
|
|
case "$branch" in
|
|
"$prefix"/*) return 0 ;;
|
|
esac
|
|
|
|
# Branches that already exist on origin (created elsewhere, e.g. cloud agents) stay usable.
|
|
if git rev-parse -q --verify "refs/remotes/origin/$branch" >/dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
|
|
echo "" >&2
|
|
echo "🛑 [branch-guard] Branch '$branch' violates the device branch-prefix rule (.agents/rules/branch-naming.md)." >&2
|
|
echo " Branches created on this device must start with '${prefix}/'." >&2
|
|
echo " 👉 Rename and retry: git branch -m '${prefix}/${branch##*/}'" >&2
|
|
echo " (One-off bypass: git commit --no-verify / git push --no-verify)" >&2
|
|
echo "" >&2
|
|
return 1
|
|
}
|