Skip to content

Commit 79038c4

Browse files
committed
Fix issue where empty files were literally "[Empty file]"
1 parent f151c49 commit 79038c4

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/gitingest/extract.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
from pathlib import Path
88

9-
from gitingest.schemas.filesystem import SEPARATOR
9+
from gitingest.schemas.filesystem import EMPTY_FILE, SEPARATOR
1010
from gitingest.utils.logging_config import get_logger
1111

1212
logger = 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}")

src/gitingest/schemas/filesystem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pathlib import Path
1616

1717
SEPARATOR = "=" * 48 # Tiktoken, the tokenizer openai uses, counts 2 tokens if we have more than 48
18-
18+
EMPTY_FILE = "[Empty file]"
1919

2020
class 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]"

tests/test_extract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

7676
def test_extract_binary_file_placeholder(tmp_path: Path) -> None:

0 commit comments

Comments
 (0)