Add --staged for pre-commit hooks: --changed also scans unstaged edits and untracked files

未關閉
#124 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
62/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
git, go
領域
cli, devtools

研究方向

Start at internal/gitx/gitx.go around ChangedUncommitted (lines 292-310) to see how git diff HEAD and ls-files --others feed the file list, then follow that list into internal/engine/diffscan.go (lines 38-39) where texts enter walk.Texts. Wire the new --staged flag in internal/cli/scan.go:32, mutually exclusive with --since and --changed, listing with git diff --cached --name-only -z --diff-filter=ACMR. Done when go test ./internal/gitx ./internal/engine ./internal/cli passes, a staged-only scan ignores untracked and unstaged files, docs/ci.md:141-146 shows --staged, and a .pre-commit-hooks.yaml with id: spackle exists.

由索引模型根據 Issue 內容生成。

描述

enhancement help wanted severity: medium

Summary

docs/ci.md documents spackle scan . --changed as the pre-commit hook, but --changed scans staged edits, unstaged edits and every untracked, non-ignored file, all read from the working tree. A pre-commit hook should judge what is being committed. Add a --staged mode, and ship a hook manifest for the pre-commit framework.

Where

  • internal/gitx/gitx.go:292-310 (ChangedUncommitted: git diff HEAD plus ls-files --others)
  • internal/engine/diffscan.go:38-39
  • docs/ci.md:141-146 (the documented hook)
  • internal/cli/scan.go:32

Impact

  • An untracked scratch file that will not be committed can block the commit.
  • With a partial commit (git add -p), an unstaged edit that is not in the commit can block it.
  • A risky line that is staged and then fixed only in the working tree passes the hook, although the staged version is what lands.

Teams using the pre-commit framework or lefthook cannot add Spackle with a repo:/rev: entry: there is no .pre-commit-hooks.yaml, so every clone needs a hand-written hook.

Steps to reproduce

  1. Create an untracked scratch.py containing cursor.execute(f"... {x}").
  2. Stage an unrelated, clean change.
  3. The documented hook exits 1 and blocks a commit that does not contain the flaw.

Suggested fix

  • Add --staged, mutually exclusive with --since and --changed. List git diff --cached --name-only -z --diff-filter=ACMR and read each listed file's staged blob (git show :<path> through gitx with the same no-textconv guards) into the shared walk.Texts in place of the working-tree text.
  • A cheaper first step is staged names with working-tree content, plus a run note saying so.
  • Trade-off: external scanners read the tree themselves, so a faithful index read needs a temporary checkout of the index (git checkout-index --prefix=), or this mode is limited to the built-in seeders.
  • Change the docs/ci.md hook to --staged.
  • Add .pre-commit-hooks.yaml with an id: spackle hook (entry: spackle scan . --staged --offline --fail-on high, pass_filenames: false, always_run: true) and document it.

Acceptance criteria

  • --staged reports leads only in staged files, using their staged content (or says in a note that it reads the working tree).
  • Untracked files and unstaged edits do not affect a --staged scan.
  • A .pre-commit-hooks.yaml lets pre-commit users add Spackle with repo: and rev:.

Getting started

  • Relevant files: internal/gitx/gitx.go, internal/engine/diffscan.go, internal/cli/scan.go, docs/ci.md
  • How to run tests: go test ./internal/gitx ./internal/engine ./internal/cli

Filed by repo-audit/full-audit at fffef43. Severity: medium. Effort: M. audit-key: enhancement|internal/gitx/gitx.go|ChangedUncommitted

主要語言
Go
星號
0
分支
1
PR 合併指標
30 天內沒有已合併 PR

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TMHSDigital/Spackle 的其他 Issue

查看 TMHSDigital/Spackle 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。