From 3721ed45f00edb6106d417d2b0f4171c7e2a8158 Mon Sep 17 00:00:00 2001 From: Kirill Markin Date: Sat, 25 Oct 2025 15:02:18 +0200 Subject: [PATCH] Fix tree command for Windows (fixes #26) - Add platform detection to run_tree_command - Use 'cmd /c tree /a /f' syntax on Windows - Keep 'tree -a -f --noreport' syntax on Unix/Linux/Mac - Modernize subprocess call with text=True and encoding='utf-8' - Add stderr=subprocess.PIPE for better error handling All 43 tests pass successfully. --- repo_to_text/core/core.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/repo_to_text/core/core.py b/repo_to_text/core/core.py index 6dfcda9..b786d8e 100644 --- a/repo_to_text/core/core.py +++ b/repo_to_text/core/core.py @@ -4,6 +4,7 @@ Core functionality for repo-to-text import os import subprocess +import platform from typing import Tuple, Optional, List, Dict, Any, Set from datetime import datetime, timezone from importlib.machinery import ModuleSpec @@ -36,12 +37,20 @@ def get_tree_structure( def run_tree_command(path: str) -> str: """Run the tree command and return its output.""" + if platform.system() == "Windows": + cmd = ["cmd", "/c", "tree", "/a", "/f", path] + else: + cmd = ["tree", "-a", "-f", "--noreport", path] + result = subprocess.run( - ['tree', '-a', '-f', '--noreport', path], + cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + encoding='utf-8', check=True ) - return result.stdout.decode('utf-8') + return result.stdout def filter_tree_output( tree_output: str,