Skip to content

Commit 5250b13

Browse files
committed
Enhance init_commit: add check for files already tracked by git to prevent overwriting
1 parent 094536c commit 5250b13

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

exporters/git/init_commit.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ def init_commit(
7575
if verbose:
7676
print(f"Varning: Filen {relative_path} finns redan i git repository, skippar")
7777
return final_content
78+
79+
# Also check if file is already tracked by git (in case it was deleted locally)
80+
try:
81+
result = subprocess.run(['git', 'ls-files', str(relative_path)],
82+
capture_output=True, text=True, timeout=GIT_TIMEOUT)
83+
if result.returncode == 0 and result.stdout.strip():
84+
if verbose:
85+
print(f"Varning: Filen {relative_path} är redan spårad av git, skippar")
86+
return final_content
87+
except subprocess.CalledProcessError:
88+
pass # File is not tracked, continue
7889

7990
# Write the file (use clean content without selex tags for git)
8091
clean_content = clean_selex_tags(markdown_content)

0 commit comments

Comments
 (0)