Skip to content

Commit cc70384

Browse files
committed
Add files for pre-commit hooks
1 parent ffbeebd commit cc70384

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

.pre-commit-hooks.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- id: git-crypt
2+
name: Avoid to commit unencrypted files
3+
description: Pre-commit hook to avoid accidentally adding unencrypted files with git-crypt
4+
entry: check-git-crypt.sh
5+
language: script

check-git-crypt.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# See <https://gist.github.com/Falkor/848c82daa63710b6c132bb42029b30ef>
4+
# Pre-commit hook to avoid accidentally adding unencrypted files with [git-crypt](https://www.agwa.name/projects/git-crypt/)
5+
6+
if [ -d .git-crypt ]; then
7+
STAGED_FILES=$(git diff --cached --name-status | awk '$1 != "D" { print $2 }' | xargs echo)
8+
if [ -n "${STAGED_FILES}" ]; then
9+
git-crypt status ${STAGED_FILES} &>/dev/null
10+
if [[ $? -ne 0 ]]; then
11+
git-crypt status -e ${STAGED_FILES}
12+
echo '/!\ You should have first unlocked your repository BEFORE staging the above file(s)'
13+
echo '/!\ Proceed now as follows:'
14+
echo -e "\t git unstage ${STAGED_FILES}"
15+
echo -e "\t git crypt unlock"
16+
echo -e "\t git add ${STAGED_FILES}"
17+
exit 1
18+
fi
19+
fi
20+
fi

0 commit comments

Comments
 (0)