This commit is contained in:
AI Christianson 2025-03-04 00:57:15 -05:00
parent 9cae0ef1fc
commit 4859a4cdc5
1 changed files with 33 additions and 17 deletions

View File

@ -154,24 +154,40 @@ def get_all_project_files(
# Not a git repository, use manual file listing # Not a git repository, use manual file listing
base_path = Path(directory) base_path = Path(directory)
for root, dirs, files in os.walk(directory): # First check if we can access the directory (check exists and isdir already done above)
# Filter out excluded directories try:
dirs[:] = [d for d in dirs if d not in excluded_dirs and (include_hidden or not d.startswith('.'))] # We already verified existence, just check for permission errors
# Handle potential FileNotFoundError for mock tests
# Calculate relative path try:
rel_root = os.path.relpath(root, directory) os.listdir(directory)
if rel_root == '.': except FileNotFoundError:
rel_root = '' # This should normally not happen as we checked existence above
# But it can happen in mock tests
# Process files pass
for file in files: except PermissionError as e:
# Skip hidden files unless explicitly included raise DirectoryAccessError(f"Cannot access directory {directory}: {e}")
if not include_hidden and file.startswith('.'):
continue try:
for root, dirs, files in os.walk(directory):
# Filter out excluded directories
dirs[:] = [d for d in dirs if d not in excluded_dirs and (include_hidden or not d.startswith('.'))]
# Create relative path # Calculate relative path
rel_path = os.path.join(rel_root, file) if rel_root else file rel_root = os.path.relpath(root, directory)
all_files.append(rel_path) if rel_root == '.':
rel_root = ''
# Process files
for file in files:
# Skip hidden files unless explicitly included
if not include_hidden and file.startswith('.'):
continue
# Create relative path
rel_path = os.path.join(rel_root, file) if rel_root else file
all_files.append(rel_path)
except PermissionError as e:
raise DirectoryAccessError(f"Permission denied while walking directory {directory}: {e}")
# Apply additional exclude patterns if specified # Apply additional exclude patterns if specified
if exclude_patterns: if exclude_patterns: