overcommit --run skips Git-quoted filenames with include filters

未关闭
#908 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
半天
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
git, ruby
领域
devtools

调研方向

Start with GitRepo.all_files in lib/overcommit/git_repo.rb around lines 138-143, which splits both git ls-files and git ls-files --deleted output on newlines. Reproduce with the scratch-repo steps in the issue, using a filename such as café.rb under core.quotePath=true, then check whether the TrailingWhitespace hook reports a failure. Done means NUL-delimited parsing for both lists, with regression specs covering Unicode, quoted, control-character, nested, deleted, untracked, empty-index and broken-symlink paths.

由索引模型根据 Issue 内容生成。

描述

Reproduced on current main 50f3e866bef75e3c3be7f92b47b1c45b6e7436ba (0.74.0), macOS 15.6.1, Ruby 4.0.7, Apple Git 2.50.1.

With Git's default core.quotePath=true, GitRepo.all_files returns the quoted/escaped output of git ls-files rather than actual paths. When a hook has an include pattern such as **/*.rb, those paths no longer match, and overcommit --run can report success without checking a tracked file.

Reproduction

Use a scratch repository, not an existing project:

mkdir overcommit-path-repro
cd overcommit-path-repro
git init
git config --local user.name 'Local Fixture'
git config --local user.email '[email protected]'
git config --local commit.gpgsign false
git config --local core.hooksPath /dev/null
git config --local core.quotePath true
git commit --allow-empty -m 'Initial fixture'

cat > .overcommit.yml <<'YAML'
PreCommit:
  ALL:
    enabled: false
  TrailingWhitespace:
    enabled: true
    on_warn: fail
    include:
      - '**/*.rb'
YAML

overcommit --sign
printf 'puts "fixture" \n' > normal.rb
git add -- normal.rb
overcommit --run
# TrailingWhitespace FAILED; exit 65.

git mv -- normal.rb 'café.rb'
overcommit --run
# All pre-commit hooks passed; exit 0. The content is unchanged.

git config --local core.quotePath false
overcommit --run
# TrailingWhitespace FAILED again; exit 65.

The same false-success result occurs for filenames containing double quotes, tabs, or newlines. core.quotePath=false is a control for the Unicode case, not a general workaround for those other characters.

Scope

GitRepo.all_files in lib/overcommit/git_repo.rb:138-143 splits both git ls-files and git ls-files --deleted on newlines. Using NUL-delimited output for both lists would avoid interpreting Git's C-style filename quoting while retaining the deleted-file filtering added in #905.

This behavior predates #905; I am not reporting it as a regression from that PR. The older #220/#222 discussion concerned a repository root containing spaces and list_files. I reproduced this with the repository root itself containing a space, and ordinary space-containing basenames still work.

The regression cases should include live Unicode/quoted/control-character paths, a nested Unicode path, unstaged deletions, an empty index, untracked files, and a tracked broken symlink. The broken symlink must remain visible to the BrokenSymlinks hook.

Would a small all_files parsing fix with these tests be welcome? I would leave other Git helpers, command execution, and index-error handling out of this change.

主要语言
Ruby
星标
4k
派生
288
平均合并
2 天 4 小时
30 天内合并 PR
18

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

sds/overcommit 的其他 Issue

查看 sds/overcommit 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。