File tree Expand file tree Collapse file tree 3 files changed +6
-4
lines changed
Expand file tree Collapse file tree 3 files changed +6
-4
lines changed Original file line number Diff line number Diff line change 66import re
77from pathlib import Path
88
9- from gitingest .schemas .filesystem import SEPARATOR
9+ from gitingest .schemas .filesystem import EMPTY_FILE , SEPARATOR
1010from gitingest .utils .logging_config import get_logger
1111
1212logger = get_logger (__name__ )
@@ -103,6 +103,8 @@ def extract(digest_path: str | Path, output_dir: str | Path = ".") -> None:
103103 target_file_path .parent .mkdir (parents = True , exist_ok = True )
104104
105105 try :
106+ if file_content == EMPTY_FILE :
107+ file_content = ""
106108 with target_file_path .open ("w" , encoding = "utf-8" ) as f :
107109 f .write (file_content )
108110 logger .debug (f"Extracted: { target_file_path } " )
Original file line number Diff line number Diff line change 1515 from pathlib import Path
1616
1717SEPARATOR = "=" * 48 # Tiktoken, the tokenizer openai uses, counts 2 tokens if we have more than 48
18-
18+ EMPTY_FILE = "[Empty file]"
1919
2020class FileSystemNodeType (Enum ):
2121 """Enum representing the type of a file system node (directory or file)."""
@@ -140,7 +140,7 @@ def content(self) -> str: # pylint: disable=too-many-return-statements
140140 return "Error reading file"
141141
142142 if chunk == b"" :
143- return "[Empty file]"
143+ return EMPTY_FILE
144144
145145 if not _decodes (chunk , "utf-8" ):
146146 return "[Binary file]"
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ def test_extract_empty_file(tmp_path: Path) -> None:
7070
7171 extracted_file = output_dir / "empty.txt"
7272 assert extracted_file .exists ()
73- assert extracted_file .read_text (encoding = "utf-8" ) == "[Empty file] "
73+ assert extracted_file .read_text (encoding = "utf-8" ) == ""
7474
7575
7676def test_extract_binary_file_placeholder (tmp_path : Path ) -> None :
You can’t perform that action at this time.
0 commit comments