-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-push
More file actions
44 lines (40 loc) · 1.06 KB
/
pre-push
File metadata and controls
44 lines (40 loc) · 1.06 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
#!/usr/bin/env bash
# labgit pre-push hook
# Blocks pushes unless the user has identified via 'git identify'.
# Same logic as pre-commit.
SESSION_FILE="${HOME}/.labgit-session"
LABGIT_TIMEOUT="${LABGIT_TIMEOUT:-28800}"
# --- Helper: check session file age ---
_labgit_session_valid() {
if [[ ! -f "$SESSION_FILE" ]]; then
return 1
fi
local now file_mod age
now=$(date +%s)
if stat --version &>/dev/null 2>&1; then
file_mod=$(stat -c %Y "$SESSION_FILE" 2>/dev/null) || return 1
else
file_mod=$(stat -f %m "$SESSION_FILE" 2>/dev/null) || return 1
fi
age=$(( now - file_mod ))
(( age <= LABGIT_TIMEOUT ))
}
if _labgit_session_valid; then
if [[ -n "${LABGIT_USER:-}" ]]; then
exit 0
fi
if [[ -O "$SESSION_FILE" ]]; then
source "$SESSION_FILE"
if [[ -n "${LABGIT_USER:-}" ]]; then
exit 0
fi
fi
else
rm -f "$SESSION_FILE" 2>/dev/null
fi
echo ""
echo "BLOCKED: You must identify yourself before pushing."
echo ""
echo " Run: git identify <username>"
echo ""
exit 1