From 38116cb278c5f308ed9747628ca41cd62e3ba645 Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Thu, 22 Aug 2024 23:40:52 +0200 Subject: [PATCH] fix: allow commits if decrypted secrets are not staged Signed-off-by: Menno van Leeuwen --- bin/actions/git/pre-commit | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/bin/actions/git/pre-commit b/bin/actions/git/pre-commit index 7f9ff1f..30b4742 100755 --- a/bin/actions/git/pre-commit +++ b/bin/actions/git/pre-commit @@ -11,8 +11,26 @@ if [ -n "$unencrypted_files" ]; then printfe "%s\n" "yellow" " - $file" done + # Check if these files are staged + staged_files=$(git diff --cached --name-only) + unencrypted_staged_files="" + for file in $unencrypted_files; do + if [[ $staged_files == *$file* ]]; then + unencrypted_staged_files="$unencrypted_staged_files $file" + fi + done + + # If there are unencrypted files staged, print a warning and exit + if [ -n "$unencrypted_staged_files" ]; then + printfe "%s\n" "red" "Unencrypted files found in .ssh/config.d/ that are staged:" + for file in $unencrypted_staged_files; do + printfe "%s\n" "yellow" " - $file" + done + printfe "%s\n" "red" "Please unstage them before committing." + exit 1 + fi + echo "" printfe "%s\n" "blue" "Use 'dotf secrets encrypt' to encrypt them." - exit 1 fi