only write .gitignore if needed (#3618)

This commit is contained in:
benedikt-bartscher 2024-07-09 04:19:19 +02:00 committed by GitHub
parent e71acececc
commit 09ff952d01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -404,9 +404,15 @@ def initialize_gitignore(
files_to_ignore: The files to add to the .gitignore file.
"""
# Combine with the current ignored files.
current_ignore: set[str] = set()
if os.path.exists(gitignore_file):
with open(gitignore_file, "r") as f:
files_to_ignore |= set([line.strip() for line in f.readlines()])
current_ignore |= set([line.strip() for line in f.readlines()])
if files_to_ignore == current_ignore:
console.debug(f"{gitignore_file} already up to date.")
return
files_to_ignore |= current_ignore
# Write files to the .gitignore file.
with open(gitignore_file, "w", newline="\n") as f: