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
17 changes: 17 additions & 0 deletions tests/copyright_check_untracked_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,22 @@ def git(repo, *args):
check(rc.returncode == 0, "a second occurrence past the window (emitted notice) stays green",
rc.stdout + rc.stderr)

# engine#1564: an untracked file whose comment style the tool does not know is debris, not repo content —
# run output a probe dropped (`.hrx123/logs/*.jsonl`), a scratch file. Skipping it is what stops the gate
# from reding a developer clone while `main` is clean; a TRACKED file of the same name is still an error.
with open(os.path.join(repo, "probe-dump.jsonl"), "w") as f:
f.write('{"x": 1}\n')
rc = run(repo, "--check")
check(rc.returncode == 0,
"an UNTRACKED file with no known comment style is skipped, not failed (engine#1564)",
rc.stdout + rc.stderr)
git(repo, "add", "probe-dump.jsonl")
git(repo, "commit", "-q", "-m", "track a jsonl")
rc = run(repo, "--check")
check(rc.returncode != 0, "the same file TRACKED is still an error: it would ship without a notice",
rc.stdout + rc.stderr)
check("no comment style known" in (rc.stdout + rc.stderr), "and it is named as an unknown style",
rc.stdout + rc.stderr)

print(f"copyright_check_untracked_test: {len(FAIL)} failure(s)")
sys.exit(1 if FAIL else 0)
13 changes: 11 additions & 2 deletions tools/copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,23 @@ def main():
def listing(*args):
return subprocess.run(["git", "ls-files", *args], capture_output=True, text=True,
check=True).stdout.split("\n")
files = sorted(set(filter(None, listing())) | set(filter(None, listing("--others", "--exclude-standard"))))
tracked = set(filter(None, listing()))
untracked = set(filter(None, listing("--others", "--exclude-standard")))
files = sorted(tracked | untracked)
missing, unknown, duplicated = [], [], []
for path in filter(None, files):
if exempt(path):
continue
block = notice_block(path)
if block is None:
unknown.append(path)
# A file this tool cannot attach a notice to. If it is IN the repository that is a real gap -- a source
# file whose style nobody taught the tool, which would ship without a licence header. If it is merely
# untracked, it is not repo content yet: run output, a probe's dump, a scratch file. Failing on that is
# the shape that teaches people to skip the gate (engine#1564: `.hrx123/logs/*.jsonl` reddened a
# developer clone while `main` was clean), so an untracked unknown-style file is skipped and a tracked
# one is still an error.
if path not in untracked:
unknown.append(path)
continue
with open(path, encoding="utf-8") as f:
text = f.read()
Expand Down
Loading