Repository navigation
Expand file tree
/
Copy pathgit-crypt-check
More file actions
executable file
·57 lines (56 loc) · 2.4 KB
/
Copy pathgit-crypt-check
File metadata and controls
executable file
·57 lines (56 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
################################################################################
# Pre-commit hook to avoid accidentally adding unencrypted files with
# [git-crypt](https://www.agwa.name/projects/git-crypt/)
# Fix to [Issue #45](https://github.com/AGWA/git-crypt/issues/45)
#
# Usage:
#
# Add to your `.pre-commit-config.yaml`:
#
# - repo: https://github.com/sysfivecom/pre-commit-hooks
# rev: 0.1.0
# hooks:
# - id: git-crypt-check
#
#
################################################################################
# MIT License
#
# Copyright (c) 2016-2021 S. Varrette <Sebastien.Varrette@gmail.com>
# Portions Copyright © 2021 sysfive.com GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################
#
set -eu -o pipefail
if [[ -d .git-crypt ]]; then
STAGED_FILES=$(git diff --cached --name-status | awk '$1 != "D" { print $2 }' | xargs echo)
if [[ -n "${STAGED_FILES}" ]]; then
git-crypt status "${STAGED_FILES}" &>/dev/null || {
git-crypt status -e "${STAGED_FILES}"
echo '/!\ You should have first unlocked your repository BEFORE staging the above file(s)'
echo '/!\ Proceed now as follows:'
echo -e "\t git unstage ${STAGED_FILES}"
echo -e "\t git crypt unlock"
echo -e "\t git add ${STAGED_FILES}"
exit 1
}
fi
fi