Skip to content

repo inspect ends in a PermissionError traceback when a tracked file's directory in a git working tree is chmod 000 #906

Closed

Description

@vchamarthi

Input: a git working tree with AGENTS.md and a committed sub/f.py, then chmod 000 sub.

python cli.py repo inspect <dir> exits 5 with PermissionError: [Errno 13] Permission denied: '.../repo/sub/f.py'. The traceback ends at dokimi/repos/source.py:141 in WorkTree.files, called from Scan.__post_init__ (dokimi/repos/l0/core.py:135). git ls-files lists sub/f.py from the index and Path.is_file() raises EACCES on it.

Expected: exit 0 and the report of the readable rest, 1 instruction files (1 root). A plain directory with the same chmod 000 sub exits 0.

d=$(mktemp -d)/repo; mkdir -p "$d/sub"
printf '# Guide\n' > "$d/AGENTS.md"; printf 'x = 1\n' > "$d/sub/f.py"
git -C "$d" init -q . && git -C "$d" add -A
git -C "$d" -c user.email=t@t -c user.name=t commit -q -m init
chmod 000 "$d/sub"
python cli.py repo inspect "$d"; echo "exit=$?"
chmod 755 "$d/sub"

A test is attached as tests/test_repo_inspect_unreadable_dir.py; it fails on aa7e8053. Wrapping the is_file() or is_symlink() test of source.py:141 in a helper that returns False on OSError makes it pass, and tests/test_repo_inspect_cli.py stays green.

tests/test_repo_inspect_unreadable_dir.py
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

"""``repo inspect`` on a git working tree with a tracked file in a directory that cannot be searched."""

from __future__ import annotations

import os
import subprocess
import sys
from pathlib import Path

import pytest

PROJECT = Path(__file__).resolve().parents[1]


@pytest.mark.skipif(os.name == "nt" or (hasattr(os, "geteuid") and os.geteuid() == 0),
                    reason="needs a directory mode the user cannot bypass")
def test_inspect_survives_a_tracked_file_in_an_unreadable_directory(tmp_path):
    root = tmp_path / "repo"
    (root / "sub").mkdir(parents=True)
    (root / "AGENTS.md").write_text("# Guide\n", encoding="utf-8")
    (root / "sub" / "f.py").write_text("x = 1\n", encoding="utf-8")
    for argv in (["init", "-q", "."], ["add", "-A"],
                 ["-c", "user.email=t@t", "-c", "user.name=t", "commit", "-q", "-m", "init"]):
        subprocess.run(["git", "-C", str(root), *argv], check=True)
    (root / "sub").chmod(0o000)
    try:
        done = subprocess.run([sys.executable, "cli.py", "repo", "inspect", str(root)], cwd=PROJECT,
                              capture_output=True, text=True, timeout=120)
    finally:
        (root / "sub").chmod(0o755)
    assert "Traceback" not in done.stderr, done.stderr[-600:]
    assert done.returncode == 0, done.stderr[-600:]
    assert "1 instruction files (1 root)" in done.stdout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions