-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.template
96 lines (81 loc) · 2.49 KB
/
init.template
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env sh
BASE=$(dirname "$0")
# exit on errors
set -e
###################
# Pre-Commit Hook #
###################
# NOTE(dgl): This creates a new pre-commit.d directory which will contain all pre-commit scripts.
# The pre-commit hook calls every script inside the pre-commi.d directory
mkdir ${BASE}/.git/hooks/pre-commit.d/
cat <<-'EOF' > ${BASE}/.git/hooks/pre-commit
#!/usr/bin/env sh
DIR=$(dirname "$0")
HOOK_NAME=$(basename "$0")
HOOK_DIR="${DIR}/${HOOK_NAME}.d"
if [ -d $HOOK_DIR ]; then
STDIN=$(cat /dev/stdin)
echo "###### Running Hooks ######"
echo "You can skip hooks by running the commit command with '--no-verify'"
for HOOK in ${HOOK_DIR}/*; do
echo "$HOOK_NAME - $HOOK"
echo
echo "$STDIN" | . $HOOK "$@"
EXIT_CODE=$?
if [ $EXIT_CODE != 0 ]; then
exit $EXIT_CODE
fi
done
else
echo "$HOOK_DIR not found"
exit 1
fi
exit 0
EOF
chmod +x ${BASE}/.git/hooks/pre-commit
####################
# No-Commit Script #
####################
# NOTE(dgl): This script ignores lines that are marked with 'nocommit' or 'no-commit'
cat <<-'EOF' > ${BASE}/.git/hooks/pre-commit.d/99-no-commit.sh
#!/use/bin/env sh
# This hook will look for code comments marked 'no-commit'
# - case-insensitive
# - dash is optional
# - can be prefixed with @
#
COUNT=$(git diff --no-ext-diff --cached --name-only -i -G"@?no-?commit" | wc -l)
if [ "$COUNT" -ne "0" ]; then
echo "WARNING: You are attempting to commit changes which include a 'no-commit'."
echo
echo "Please check the following changes:"
git diff --no-ext-diff --cached -U0 --exit-code -i -G"@?no-?commit"
fi
EOF
chmod +x ${BASE}/.git/hooks/pre-commit.d/99-no-commit.sh
################
# Config setup #
################
git_user=`git config user.name`
read -p "Git user: [${git_user}] " input
git_user=${input:-$git_user}
git config user.name "${git_user}"
git_email=`git config user.email`
read -p "Git email: [${git_email}] " input
git_email=${input:-$git_email}
git config user.email "${git_email}"
git_signing=`git config commit.gpgsign`
read -p "Git signing: [${git_signing}] " input
git_signing=${input:-$git_signing}
git config commit.gpgsign "${git_signing}"
###########
# Cleanup #
###########
read -p "Confirm if you want to cleanup the initial commit and init script and start with an empty repository? [yN] " answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
git update-ref -d HEAD
rm -f $0
git rm --cached $0
git commit --allow-empty -m "Initial commit" --no-verify
git push origin +main
fi