Skip to content

chore: .gitattributes を追加し CRLF 破損を構造的に防ぐ - #212

Merged
squne121 merged 1 commit into
mainfrom
worktree-issue-97-gitattributes-crlf-prevention
May 22, 2026
Merged

squne121 merged 1 commit into
mainfrom
worktree-issue-97-gitattributes-crlf-prevention

Conversation

@squne121

Copy link
Copy Markdown
Owner

Summary

  • リポジトリ root に .gitattributes を新規追加し、スクリプト・ソース・設定系ファイルの改行コードを eol=lf に正規化する
  • Windows/WSL 環境でのエディタや core.autocrlf 設定による CRLF 混入を構造的に防ぐ
  • .sh, .py 等 14 種類の拡張子を text eol=lf、Windows 専用 4 種類を text eol=crlf、バイナリアセット 17 種類を binary 指定する

既存 working tree の CRLF 破損修復・実行 bit 修復は本 PR の対象外。別途 git checkout -- <path> での手動復旧(#206 参照)が必要。

受け入れ条件の達成状況

AC 内容 結果
AC1 .gitattributes が repo root に存在する PASS
AC2 *.sh と *.py に text eol=lf 行が含まれる PASS
AC3 代表スクリプト 3 本に eol: lf 属性が適用される PASS
AC4 git ls-files --eol で attr/text eol=lf が確認できる PASS
AC5 tracked .sh/.py に CRLF が含まれていない PASS
AC6 バイナリ拡張子の binary 指定が含まれる PASS
AC7 PR 本文に免責事項が明記されている PASS (本文参照)

検証コマンド結果

# AC1
PASS: present

# AC2
5:*.sh      text eol=lf
PASS: *.sh
8:*.py      text eol=lf
PASS: *.py

# AC3 (git check-attr)
.claude/skills/ssot-discovery/scripts/match-ssot.sh: text: set
.claude/skills/ssot-discovery/scripts/match-ssot.sh: eol: lf
.claude/skills/open-pr/scripts/open_pr.py: text: set
.claude/skills/open-pr/scripts/open_pr.py: eol: lf
.claude/skills/create-issue/scripts/verify-anchors.sh: text: set
.claude/skills/create-issue/scripts/verify-anchors.sh: eol: lf

# AC4 (git ls-files --eol, 抜粋)
i/lf    w/lf    attr/text eol=lf      	.claude/skills/create-issue/scripts/create_issue_txn.py
i/lf    w/lf    attr/text eol=lf      	.claude/skills/create-issue/scripts/verify-anchors.sh
i/lf    w/lf    attr/text eol=lf      	.claude/skills/open-pr/scripts/open_pr.py
i/lf    w/lf    attr/text eol=lf      	.claude/skills/ssot-discovery/scripts/match-ssot.sh
...(全 35 ファイル確認済み)

# AC5
PASS: no CRLF in tracked .sh/.py files under .claude/skills

# AC6
27:*.png     binary
28:*.jpg     binary
29:*.jpeg    binary
30:*.gif     binary
31:*.webp    binary
(全 17 バイナリ拡張子確認済み)

# Standard gates
pnpm typecheck: PASS
pnpm lint:      PASS
pnpm test:      PASS (4 files, 5 tests)
pnpm build:     PASS

Allowed Paths 遵守

  • 変更ファイル: .gitattributes(1 ファイル)
  • Allowed Paths: .gitattributes
  • 遵守: true

Schema Change Applicability

  • decision: not_schema_change
  • reason: .gitattributes は git の line-ending 正規化設定ファイルであり、producer-consumer 境界をまたぐ machine-readable contract ではない

Schema Consumer Inventory

N/A(not_schema_change のため)

Compatibility Decision

  • change_type: N/A
  • compatibility: N/A
  • migration_required: N/A
  • migration_or_followup: N/A
  • reason: schema 変更なし

Safety Claim Matrix

N/A。変更対象は .gitattributes(1 ファイル)であり、transport/permission/sandbox/auth/MCP/.claude/skills/**/.github/workflows/** のいずれにも該当しない。

Notes

Closes #97

リポジトリ root に .gitattributes を新規追加。
* text=auto のデフォルト行、スクリプト・ソース系を text eol=lf で正規化、
Windows 専用ファイルを text eol=crlf、バイナリアセットを binary 指定することで、
Windows/WSL 環境での checkout/commit 時 CRLF 混入を構造的に防ぐ。

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@squne121

Copy link
Copy Markdown
Owner Author

検証結果レポート

Issue #97: .gitattributes による CRLF 正規化と binary ファイル保護

AC 確認コマンド 実行結果 判定
AC1 test -f .gitattributes ファイル存在確認済み PASS
AC2 grep -nE '^\*\.sh|*.py' .gitattributes .sh・.py 両パターン確認 PASS
AC3 git check-attr text eol -- <3スクリプト> 全て eol: lf を返却 PASS
AC4 git ls-files --eol .claude/skills/**/*.{sh,py} 全て attr/text eol=lf PASS
AC5 CRLF 検査(Python) tracked な .sh/.py に CRLF なし PASS
AC6 grep -nE 'binary' .gitattributes png/jpg/gif/webp/ico 等確認 PASS
AC7 PR #212 body の disclaimer 確認 「対象外」テキスト検出 PASS

Standard Gates

ゲート 実行結果 判定
pnpm typecheck 成功 PASS
pnpm lint 成功 PASS
pnpm test 5/5 PASS PASS
pnpm build ビルド成功 PASS

総合判定

  • 全 AC PASS: YES
  • 全 Standard Gates PASS: YES
  • FAIL 件数: 0

```yaml
TEST_VERDICT:
result: PASS
mergeable: MERGEABLE
merge_state_status: CLEAN
baseline_only: false
verification_commands_pass: 11
verification_commands_fail: 0
```

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

Mergeability

  • mergeable=MERGEABLE, mergeStateStatus=CLEAN

Evidence Check

  • AC coverage: 全 7 件 (AC1〜AC7) PASS。PR 本文の ## 受け入れ条件の達成状況 テーブルに各 AC の結果と根拠が記載されており、TEST_VERDICT_MACHINE コメント(verification_commands_fail: 0)でも全 PASS が確認されている。
  • Allowed Paths: 変更ファイルは .gitattributes 1 ファイルのみ。Issue #97 の allowed_paths: [.gitattributes] に完全一致。遵守: true。
  • CI Verification: build / lint / python-test / test / typecheck の全 5 チェックが pass。
  • 検証コマンド結果: PR 本文の ## 検証コマンド結果 セクションに AC1〜AC7 各コマンドの出力が記載されており、雰囲気ではなく実行結果が確認できる。
  • Schema Change Applicability: not_schema_change と明示されており根拠も妥当(.gitattributes は producer-consumer contract ではない)。Schema Consumer Inventory 提出不要。
  • Safety Claim Matrix: 変更対象は repo root の .gitattributes 1 ファイルのみ。changed path / diff / issue text に safety-sensitive 判定条件(transport/permission/sandbox/auth/MCP/.claude/skills/**/.github/workflows/**)が含まれないため、N/A 判定は妥当。
  • Runtime Verification: Issue に decision: not_applicable と明記されており、test -f / grep / git check-attr の静的検証で完結している。

Blockers

なし

Non-blockers(任意改善)

なし

LOOP_VERDICT

LOOP_VERDICT:
  verdict: APPROVE
  blockers: []
  mergeable: MERGEABLE
  mergeStateStatus: CLEAN
  reviewed_head_sha: 4031e236086afc92a2ace886fde595333219c1af
  follow_up_issue_requests: []

@squne121

Copy link
Copy Markdown
Owner Author

敵対的レビュー結論

Verdict: APPROVE寄り。ただし “証跡品質” に軽微な修正推奨。Blockerはなし。

PR #212 は Issue #97 の要求どおり、repo root に .gitattributes だけを追加し、.sh / .py を含む主要テキストを text eol=lf、Windows系を text eol=crlf、主要バイナリを binary にしている。変更ファイルも .gitattributes 1件のみで、Issue #97 の Allowed Paths と一致する。

Git公式仕様上、text は check-in 時に LF 正規化を有効化し、eol=lf は checkout 時にも index と同じ LF を使わせる指定なので、このPRの中核方針は妥当。GitHub Docs も、repo root の .gitattributes を commit すると contributors の core.autocrlf より一貫した挙動を得られると説明している。

良い点

Issue #97 は、#79作業中に .claude/skills/ssot-discovery/scripts/match-ssot.sh が $'\r': command not found / set: pipefail: invalid option name で壊れた実害に基づく再発防止Issueであり、PR #103 でも CRLF破損と .gitattributes 不在が観測されていた。PR #212はその実害に対して最小かつ適切な構造的対策になっている。

.gitattributes の内容も、Git公式例の * text=auto、*.sh text eol=lf、画像系を非テキスト扱いにする設計と整合している。GitHub Docs でも text eol=lf は Windowsでも LFを維持すべきファイルに使い、binary は -text -diff の alias と説明されている。

指摘

  1. 検証コメントの grep 正規表現が弱い

PRコメント側のAC2検証に grep -nE '^\\.sh\|.py' と見える箇所があり、これは「.sh と .py の両方が正しく text eol=lf である」ことの証跡としては弱い。Issue #97 の Verification Commands には、.sh と .py を個別に確認する強い正規表現が定義されているため、PRコメントもIssue本文のコマンドに合わせるべき。

これは実装Blockerではない。PR本文側の検証出力と差分自体では *.sh text eol=lf / *.py text eol=lf が確認できるため、問題は「実装」ではなく「レビュー証跡の精度」。

  1. “完全解決” と誤読されない表現を維持する必要がある

.gitattributes は将来の check-in / checkout の正規化には効くが、既存 working tree の破損や既存 index の全面正規化を自動で完了するものではない。GitHub Docs も、line ending 設定変更後に全体を揃えるには git add --renormalize . を使う手順を案内している。

PR本文に「既存 working tree の CRLF 破損修復・実行 bit 修復は対象外」と明記されているため、この点は現状クリア。さらに follow-up として #206 が git add --renormalize の適用範囲設計、#205 が executable bit CI guard を扱っているため、スコープ分離も妥当。

  1. 将来拡張子の網羅性は十分ではないが、今回のBlockerではない

現状の .gitattributes は .mjs, .cjs, .jsx, .mts, .cts, .css, .html, .svg, Dockerfile, .env* などは明示していない。ただし Issue #97 のIn Scopeに列挙された拡張子は満たしており、変更許可も .gitattributes のみ。後続でSSOT YAML/frontmatter生成や npm script を扱う #198 があるため、そこで新規ファイル種別が増えた時に .gitattributes の追補Issueを切るのがよい。

高品質化パッチ案

PR #212自体に入れるなら、実装差分ではなく検証コメントまたはPR本文の証跡修正だけでよい。

AC2: .sh / .py を個別に確認

grep -nE '^*.sh[[:space:]]+text[[:space:]]+eol=lf$' .gitattributes
grep -nE '^*.py[[:space:]]+text[[:space:]]+eol=lf$' .gitattributes

binary 指定も全件数を確認するなら head で切らない

grep -nE '^*.(png|jpg|jpeg|gif|webp|ico|mp3|wav|ogg|mp4|zip|gz|pdf|ttf|otf|woff|woff2)[[:space:]]+binary$' .gitattributes

任意で .gitattributes に将来追加してもよい候補:

*.jsx text eol=lf
*.mjs text eol=lf
*.cjs text eol=lf
*.mts text eol=lf
*.cts text eol=lf
*.css text eol=lf
*.html text eol=lf
*.svg text eol=lf
*.env text eol=lf
Dockerfile text eol=lf

ただし、今回PRのIssue契約上は追加必須ではない。

最終判断

マージ可。
ただし、レビューコメントの grep 証跡だけは弱いので、PRコメントまたはPR本文の検証ログをIssue #97の厳密なコマンドに揃えると品質が上がる。実装差分そのものは、Issue #97の目的・Allowed Paths・Git/GitHub公式仕様と整合している。

@squne121

Copy link
Copy Markdown
Owner Author

検証証跡 更新 (外部レビュー指摘対応)

外部レビューで AC2 / AC6 の grep 証跡が弱いと指摘されたため、Issue #97 の VC と同等の厳密な正規表現で再確認した結果を記録します。

AC2: *.sh / *.py を個別に確認

# *.sh
$ grep -nE '^\*\.sh[[:space:]]+text[[:space:]]+eol=lf$' .gitattributes
5:*.sh      text eol=lf
PASS: *.sh

# *.py
$ grep -nE '^\*\.py[[:space:]]+text[[:space:]]+eol=lf$' .gitattributes
8:*.py      text eol=lf
PASS: *.py

AC6: binary 指定 全件確認(head -5 なし)

$ grep -nE '^\*\.(png|jpg|jpeg|gif|webp|ico|mp3|wav|ogg|mp4|zip|gz|pdf|ttf|otf|woff|woff2)[[:space:]]+binary$' .gitattributes
27:*.png     binary
28:*.jpg     binary
29:*.jpeg    binary
30:*.gif     binary
31:*.webp    binary
32:*.ico     binary
33:*.mp3     binary
34:*.wav     binary
35:*.ogg     binary
36:*.mp4     binary
37:*.zip     binary
38:*.gz      binary
39:*.pdf     binary
40:*.ttf     binary
41:*.otf     binary
42:*.woff    binary
43:*.woff2   binary

Issue #97 の Verification Commands(厳密正規表現)でも全件 PASS 確認済み。

@squne121
squne121 marked this pull request as ready for review May 22, 2026 05:16
@squne121
squne121 merged commit f7a0b6b into main May 22, 2026
5 checks passed
@squne121
squne121 deleted the worktree-issue-97-gitattributes-crlf-prevention branch May 22, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

実装: .gitattributes を追加し .claude/skills 配下スクリプトの CRLF 破損を防ぐ

1 participant