-
-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathopenwisp-commit
More file actions
executable file
·66 lines (60 loc) · 1.42 KB
/
openwisp-commit
File metadata and controls
executable file
·66 lines (60 loc) · 1.42 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
58
59
60
61
62
63
64
65
66
#!/bin/bash
show_help() {
printf "Usage:\n"
printf " openwisp-commit [--amend]\n"
printf " openwisp-commit --check [--rev-range <range>]\n"
printf "\n"
printf "Creates or validates commits following OpenWISP commit conventions.\n"
printf "\n"
printf "Options:\n"
printf " --amend Amend the last commit (soft reset + recommit)\n"
printf " --check Validate commit messages instead of creating one\n"
printf " --rev-range <range> Git revision range to check (default: HEAD^!)\n"
}
REV_RANGE="HEAD^!"
CHECK_MODE=false
AMEND_MODE=false
while [ "$1" != "" ]; do
case "$1" in
--check)
CHECK_MODE=true
;;
--amend)
AMEND_MODE=true
;;
--rev-range)
shift
if [ -z "$1" ] || [ "${1#-}" != "$1" ]; then
printf "Error: --rev-range requires a value\n\n"
show_help
exit 1
fi
REV_RANGE="$1"
;;
--help | -h)
show_help
exit 0
;;
*)
printf "Unknown argument: %s\n" "$1"
printf "\n"
show_help
exit 1
;;
esac
shift
done
# Define reusable commands (after argument parsing)
CZ_CMD="cz -n cz_openwisp"
CZ_COMMIT="$CZ_CMD commit"
CZ_CHECK="$CZ_CMD check --rev-range $REV_RANGE"
run_commit_and_check() {
$CZ_COMMIT && $CZ_CHECK
}
if $CHECK_MODE; then
$CZ_CHECK
elif $AMEND_MODE; then
git reset --soft HEAD~1 && run_commit_and_check
else
run_commit_and_check
fi