From 895ce41bcd8c7f4da976626832a99798f9ece022 Mon Sep 17 00:00:00 2001 From: jeanluc Date: Wed, 25 Sep 2024 13:12:14 +0200 Subject: [PATCH] Don't crash in pre-commit automation when no new files were added --- project/tools/helpers/pre_commit.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/project/tools/helpers/pre_commit.py b/project/tools/helpers/pre_commit.py index bcab18a..db4687a 100644 --- a/project/tools/helpers/pre_commit.py +++ b/project/tools/helpers/pre_commit.py @@ -102,6 +102,7 @@ def _run_pre_commit_loop(retries_left): for i, failing_hook in enumerate(failing): prompt.warn(f"✗ Failing hook ({i + 1}): {failing_hook}", failing[failing_hook]) finally: - # Undo git add --intent-to-add to allow RenovateBot to detect new files correctly - git("restore", "--staged", *new_files) + if new_files: + # Undo git add --intent-to-add to allow RenovateBot to detect new files correctly + git("restore", "--staged", *new_files) return False