-
-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathopenwisp-commit
More file actions
executable file
·87 lines (80 loc) · 1.77 KB
/
Copy pathopenwisp-commit
File metadata and controls
executable file
·87 lines (80 loc) · 1.77 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
show_help() {
printf "Usage:\n"
printf " openwisp-commit [--amend]\n"
printf " openwisp-commit --check [--rev-range <range>]\n"
printf " openwisp-commit --info\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 " --info Show the OpenWISP commit conventions\n"
printf " --rev-range <range> Git revision range to check (default: HEAD^!)\n"
}
REV_RANGE="HEAD^!"
MODE=""
set_mode() {
if [ -n "$MODE" ]; then
printf "Error: --check, --amend, and --info are mutually exclusive\n\n"
show_help
exit 1
fi
MODE="$1"
}
while [ "$1" != "" ]; do
case "$1" in
--check)
set_mode "check"
;;
--amend)
set_mode "amend"
;;
--info)
set_mode "info"
;;
--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"
CZ_INFO="$CZ_CMD info"
run_commit_and_check() {
$CZ_COMMIT && $CZ_CHECK
}
case "$MODE" in
check)
$CZ_CHECK
;;
amend)
git reset --soft HEAD~1 && run_commit_and_check
;;
info)
$CZ_INFO
;;
*)
run_commit_and_check
;;
esac