fix: allow commits if decrypted secrets are not staged

Signed-off-by: Menno van Leeuwen <menno@vleeuwen.me>
This commit is contained in:
Menno van Leeuwen 2024-08-22 23:40:52 +02:00
parent f3c7eda729
commit 38116cb278
Signed by: vleeuwenmenno
SSH Key Fingerprint: SHA256:OJFmjANpakwD3F2Rsws4GLtbdz1TJ5tkQF0RZmF0TRE

View File

@ -11,8 +11,26 @@ if [ -n "$unencrypted_files" ]; then
printfe "%s\n" "yellow" " - $file" printfe "%s\n" "yellow" " - $file"
done 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 "" echo ""
printfe "%s\n" "blue" "Use 'dotf secrets encrypt' to encrypt them." printfe "%s\n" "blue" "Use 'dotf secrets encrypt' to encrypt them."
exit 1
fi fi