-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·44 lines (41 loc) · 1.07 KB
/
pre-commit
File metadata and controls
executable file
·44 lines (41 loc) · 1.07 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
#!/bin/bash
# hooks/pre-commit — tracked copy of the pre-commit guard.
# Install: ln -sf ../../hooks/pre-commit .git/hooks/pre-commit
# (or run scripts/init.sh which does this automatically)
#
# Blocks Added/Copied/Renamed files matching forbidden patterns.
# Deletions and modifications are always allowed.
FORBIDDEN_PATTERNS=(
"\.txt$"
"\.log$"
"(^|/)test_.*\.json$"
"(^|/)debug_.*"
"^Meta/"
"^Daily/"
"^Weekly/"
"^Monthly/"
"^Ideas/"
"^References/"
"^Projects/"
"^Clippings/"
"^Bases/"
"^Canvases/"
"^Sandbox/"
)
errors=()
while IFS= read -r file; do
for pat in "${FORBIDDEN_PATTERNS[@]}"; do
if echo "$file" | grep -qE "$pat"; then
errors+=(" $file (matches: $pat)")
break
fi
done
done < <(git diff --cached --name-only --diff-filter=ACR)
if [[ ${#errors[@]} -gt 0 ]]; then
echo "second-brain pre-commit: forbidden files staged:" >&2
for e in "${errors[@]}"; do echo "$e" >&2; done
echo "" >&2
echo "These files must not be committed to this repository." >&2
echo "Remove them with: git rm --cached <file>" >&2
exit 1
fi