Add check for existing file in Git history before committing

This commit is contained in:
2025-05-09 03:29:29 +02:00
parent af0de88d8e
commit 0c7dff95c0

View File

@ -109,6 +109,17 @@ def commit_file_with_timestamp(filepath: Path) -> bool:
bool: True if the commit was successful, False otherwise. bool: True if the commit was successful, False otherwise.
""" """
# Check in Git history if we already have this file
git_log_cmd: list[str] = ["git", "log", "--pretty=format:%H", "--follow", str(filepath)]
try:
git_log_output: str = subprocess.check_output(git_log_cmd, text=True).strip() # noqa: S603
if git_log_output:
logger.info("File %s already exists in Git history.", filepath)
return True
except subprocess.CalledProcessError:
logger.exception("Error checking Git history for %s", filepath)
return False
try: try:
# Get the full path to the Git executable # Get the full path to the Git executable
git_executable = shutil.which("git") git_executable = shutil.which("git")
@ -151,7 +162,7 @@ def commit_file_with_timestamp(filepath: Path) -> bool:
return True return True
async def main() -> Literal[1, 0]: # noqa: C901, PLR0912, PLR0915 async def main() -> Literal[1, 0]: # noqa: C901, PLR0912, PLR0914, PLR0915
"""Fetch and save articles from the Wuthering Waves website. """Fetch and save articles from the Wuthering Waves website.
Returns: Returns: