Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Scripts a POSIX shell reads keep LF line endings in every checkout. Git for
# Windows converts text to CRLF by default, and sh (Git Bash included) reads a
# CR as part of each command. A plugin marketplace install is a clone.
*.sh text eol=lf
integrations/*/bin/loom-node text eol=lf
integrations/grep-shim/bin/* text eol=lf
integrations/cline/hooks/* text eol=lf
# Skills are read by each agent's frontmatter parser: one line ending for all.
integrations/*/skills/** text eol=lf
skills/** text eol=lf
# Preserve committed LF bytes for shell launchers and skill frontmatter.
# Disabling conversion also keeps these bytes unchanged with autocrlf enabled.
# The checkout-byte tests reject CRLF in the committed files.
*.sh -text
integrations/*/bin/loom-node -text
integrations/grep-shim/bin/* -text
integrations/cline/hooks/* -text
integrations/*/skills/** -text
skills/** -text
80 changes: 80 additions & 0 deletions tests/unit/test_plugin_checkout_bytes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""Shell launchers and skill files keep their committed LF bytes in a checkout."""

from __future__ import annotations

import fnmatch
import os
import subprocess
from pathlib import Path

import pytest

ROOT = Path(__file__).resolve().parents[2]
PROTECTED = (
"*.sh",
"integrations/*/bin/loom-node",
"integrations/grep-shim/bin/*",
"integrations/cline/hooks/*",
"integrations/*/skills/**",
"skills/**",
)
EXAMPLES = (
"run.sh",
"integrations/claude-code-plugin/bin/loom-node",
"integrations/grep-shim/bin/grep",
"integrations/cline/hooks/PreToolUse",
"integrations/codex-plugin/skills/memory/SKILL.md",
"skills/memory/SKILL.md",
)


def _git(root: Path, *args: str) -> bytes:
env = {
key: value
for key, value in os.environ.items()
if key not in {"GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_COMMON_DIR"}
}
env.update(GIT_CONFIG_NOSYSTEM="1", GIT_CONFIG_GLOBAL=os.devnull)
return subprocess.run(["git", *args], cwd=root, env=env, check=True, capture_output=True).stdout


def test_protected_committed_files_are_lf_and_disable_conversion() -> None:
names = _git(ROOT, "ls-tree", "-rz", "--name-only", "HEAD").decode().split("\0")
protected = [name for name in names if any(fnmatch.fnmatchcase(name, pat) for pat in PROTECTED)]
assert protected, "No protected scripts or skills found"
for name in protected:
data = _git(ROOT, "show", f"HEAD:{name}")
assert b"\r" not in data, f"Commit LF bytes in {name}; Git preserves them unchanged"
attrs = _git(ROOT, "check-attr", "-z", "text", "eol", "--", name).decode().split("\0")
assert attrs[1:3] == ["text", "unset"], name
assert attrs[4:6] == ["eol", "unspecified"], name


@pytest.mark.parametrize("autocrlf", ["true", "input", "false"])
def test_checkout_preserves_protected_bytes_with_autocrlf(tmp_path: Path, autocrlf: str) -> None:
repo = tmp_path / "repo"
repo.mkdir()
_git(repo, "init", "-q")
(repo / ".gitattributes").write_bytes((ROOT / ".gitattributes").read_bytes())
content = b"# Fixture\none\ntwo\n"
for name in (*EXAMPLES, "ordinary.txt"):
target = repo / name
target.parent.mkdir(parents=True, exist_ok=True)
target.write_bytes(content)
_git(repo, "-c", "core.autocrlf=false", "add", ".")
dest = tmp_path / "checkout"
dest.mkdir()
_git(
repo,
"-c",
f"core.autocrlf={autocrlf}",
"-c",
"core.eol=crlf",
"checkout-index",
"--all",
f"--prefix={dest}/",
)
for name in EXAMPLES:
assert (dest / name).read_bytes() == content, (autocrlf, name)
expected = content.replace(b"\n", b"\r\n") if autocrlf == "true" else content
assert (dest / "ordinary.txt").read_bytes() == expected
Loading