Просмотр исходного кода

chore: 初始化 Git 仓库与工程化基线

- .gitignore:运行产物/权重/构建目录/临时输出不入库,补 --no-plc、*.pgm、*.out/*.err 与敏感文件规则

- .gitattributes:库内统一 LF(目标机 RK3576/Jetson 为 Linux),bat/cmd/ps1 检出为 CRLF,图片视频模型声明为 binary

- .gitmessage:提交模板(为什么改 / 改了什么 / 验证 / 关联)

- .githooks/pre-commit:提交前跑 L1 单测(229 项),可用 --no-verify 跳过
Administrator 2 недель назад
Сommit
38a96e2f0d
4 измененных файлов с 176 добавлено и 0 удалено
  1. 55 0
      .gitattributes
  2. 40 0
      .githooks/pre-commit
  3. 63 0
      .gitignore
  4. 18 0
      .gitmessage

+ 55 - 0
.gitattributes

@@ -0,0 +1,55 @@
+# ---------------------------------------------------------------- 统一换行与二进制
+# 目标平台是 Linux(RK3576 / Jetson),开发机是 Windows:库里一律存 LF,
+# 避免全仓 diff 被行尾污染;确有需要的格式(bat/cmd/ps1)在 Windows 上检出为 CRLF。
+* text=auto eol=lf
+
+*.py     text eol=lf
+*.pyi    text eol=lf
+*.c      text eol=lf
+*.cc     text eol=lf
+*.cpp    text eol=lf
+*.h      text eol=lf
+*.hpp    text eol=lf
+*.cu     text eol=lf
+*.sh     text eol=lf
+*.cmake  text eol=lf
+CMakeLists.txt text eol=lf
+*.json   text eol=lf
+*.jsonl  text eol=lf
+*.yaml   text eol=lf
+*.yml    text eol=lf
+*.md     text eol=lf
+*.txt    text eol=lf
+*.txt.in text eol=lf
+*.gitignore    text eol=lf
+.gitattributes text eol=lf
+*.service       text eol=lf
+*.conf          text eol=lf
+
+*.bat    text eol=crlf
+*.cmd    text eol=crlf
+*.ps1    text eol=crlf
+
+# 二进制:禁止行尾转换与文本 diff
+*.png    binary
+*.jpg    binary
+*.jpeg   binary
+*.bmp    binary
+*.pgm    binary
+*.mp4    binary
+*.avi    binary
+*.h264   binary
+*.onnx   binary
+*.rknn   binary
+*.engine binary
+*.plan   binary
+*.pt     binary
+*.calib  binary
+*.docx   binary
+*.xlsx   binary
+*.pdf    binary
+*.zip    binary
+*.7z     binary
+
+# 依赖锁文件/生成物不参与 diff 合并
+package-lock.json merge=binary

+ 40 - 0
.githooks/pre-commit

@@ -0,0 +1,40 @@
+#!/bin/sh
+# 提交前钩子:跑 L1 单元测试(229 项,约 4 秒),失败则拒绝提交。
+#
+# 启用(每人一次,克隆后执行):git config core.hooksPath .githooks
+# 临时跳过:git commit --no-verify
+# 关闭:    git config --unset core.hooksPath
+#
+# 约定:钩子只做「快速、离线、无硬件依赖」的检查;
+#       ctest / video_eval / 浸泡属于发布前检查(见 docs/git_workflow.md §5)。
+
+PY=""
+for c in python python3 py; do
+    if command -v "$c" >/dev/null 2>&1; then
+        PY="$c"
+        break
+    fi
+done
+
+if [ -z "$PY" ]; then
+    echo "[pre-commit] 未找到 python,跳过单元测试"
+    exit 0
+fi
+
+if [ ! -d tests ] || [ ! -f pyproject.toml ]; then
+    echo "[pre-commit] 不在仓库根目录,跳过单元测试"
+    exit 0
+fi
+
+LOG="$(mktemp 2>/dev/null || echo /tmp/portcv_precommit.log)"
+
+echo "[pre-commit] 运行 tests/ 单元测试 ..."
+if ! "$PY" -m unittest discover -s tests -q >"$LOG" 2>&1; then
+    echo "[pre-commit] 单元测试失败,提交被拒绝:"
+    tail -n 40 "$LOG"
+    echo "[pre-commit] 修复后重试;确认要绕过:git commit --no-verify"
+    exit 1
+fi
+
+echo "[pre-commit] 单元测试通过"
+exit 0

+ 63 - 0
.gitignore

@@ -0,0 +1,63 @@
+# Python
+__pycache__/
+*.py[cod]
+*.egg-info/
+build/
+dist/
+.venv/
+venv/
+
+# 构建目录(CMake/Ninja 生成物)
+build-cmake/
+build_cmake_zig/
+build_zig/
+
+# 敏感信息:现场账号/密码/证书放这里,不入库
+*.local.json
+local.private.json
+secrets/
+*.pem
+*.key
+
+# 运行产物:存图、报表、日志、抓帧
+runs/
+*.log
+*.jsonl
+
+# 模型权重与引擎(体积大、与设备绑定,不进版本库)
+weights/
+*.onnx
+*.rknn
+*.plan
+*.pt
+*.ckpt
+*.engine
+*.calib
+calib.txt
+
+# 临时/调试
+*.tmp
+*.out
+*.err
+*_scan.txt
+*_part.txt
+t_*.txt
+sm_*.txt
+chk.txt
+compile.out
+tool_out.txt
+files.txt
+_listing.txt
+probe_cli.txt
+_gen/
+
+# 命令行参数误写产生的转储目录(如 --no-plc 被当成输出路径)与逐帧图像
+--no-plc/
+*.pgm
+*.ppm
+
+# 编辑器
+.vscode/
+.idea/
+*.swp
+.DS_Store

+ 18 - 0
.gitmessage

@@ -0,0 +1,18 @@
+# <类型>(<范围>): <一句话祈使句,≤ 50 字>
+#
+# 为什么改(现场现象 / 需求 / 缺陷编号):
+#
+# 改了什么(关键文件 / 关键决策):
+#
+# 验证(跑过什么,结果如何;没跑的写"未验证"及原因):
+#
+# 关联:#issue / TP-xxx / 文档章节
+#
+# 类型:feat 新功能 | fix 修缺陷 | perf 性能 | refactor 重构 | test 测试
+#       docs 文档 | build 构建/依赖 | chore 杂务 | revert 回滚
+# 范围:portcv | cpp | plc | deploy | configs | tests | scripts | docs
+#
+# 提交前自检:
+#   python -m unittest discover -s tests -q          # L1,229 项
+#   ctest --test-dir build-cmake --output-on-failure # L2,8 组 1128 项
+#   模型/阈值变更另跑 scripts\video_eval.py           # L3 回放