-
Notifications
You must be signed in to change notification settings - Fork 12
/
commit
executable file
·38 lines (32 loc) · 1018 Bytes
/
commit
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
#!/usr/bin/env bash
set -euo pipefail
if [ -z "${1:-}" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo -e "Create a commit prefixed with the current branch name.\n"
echo "Usage:"
echo -e " commit MESSAGE\n"
echo "Example:"
echo " commit \"Hello world!\""
exit 1
fi
CURRENT_BRANCH="$(git symbolic-ref --short HEAD)"
GIT_ROOT_DIRECTORY=$(git rev-parse --show-toplevel)
IGNORED_BRANCHES=("dev" "master" "main" "qa" "uat" "staging")
CUSTOM_IGNORED_PATH="$GIT_ROOT_DIRECTORY/.smart-commit-ignore"
if [ -f "$CUSTOM_IGNORED_PATH" ]; then
CUSTOM_BRANCHES=$(cat "$CUSTOM_IGNORED_PATH")
BRANCHES=($CUSTOM_BRANCHES)
IGNORED_BRANCHES=(${IGNORED_BRANCHES[@]} ${BRANCHES[@]})
fi
IS_IGNORED=false
for branch in "${IGNORED_BRANCHES[@]}"; do
if [ "$CURRENT_BRANCH" == $branch ]; then
IS_IGNORED=true
break
fi
done
if [ "$IS_IGNORED" == false ]; then
# Edit your config here
git commit -m "$CURRENT_BRANCH: $1" ${@:2}
else
git commit -m "$1" ${@:2}
fi