Skip to content

Commit 44205dc

Browse files
authored
Merge pull request #17 from mesaugat/help
Show help if commit message is not provided
2 parents 15f09ee + c7b7deb commit 44205dc

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

commit

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
if [ -z "${1:-}" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
5+
echo "Create a commit prefixed with the current branch name."
6+
echo
7+
echo "Usage:"
8+
echo " commit MESSAGE"
9+
echo
10+
echo "Example:"
11+
echo " commit \"Hello world!\""
12+
exit 1
13+
fi
14+
415
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
516
GIT_ROOT_DIRECTORY=$(git rev-parse --show-toplevel)
617
IGNORED_BRANCHES=("dev" "master" "qa" "uat" "staging")
718
CUSTOM_IGNORED_PATH="$GIT_ROOT_DIRECTORY/.smart-commit-ignore"
819

9-
if [ -f "$CUSTOM_IGNORED_PATH" ]
10-
then
20+
if [ -f "$CUSTOM_IGNORED_PATH" ]; then
1121
CUSTOM_BRANCHES=$(cat "$CUSTOM_IGNORED_PATH")
1222
BRANCHES=($CUSTOM_BRANCHES)
1323
IGNORED_BRANCHES=(${IGNORED_BRANCHES[@]} ${BRANCHES[@]})
1424
fi
1525

1626
IS_IGNORED=false
1727

18-
for branch in "${IGNORED_BRANCHES[@]}";
19-
do
20-
if [ "$CURRENT_BRANCH" == $branch ]
21-
then
22-
IS_IGNORED=true
23-
break
28+
for branch in "${IGNORED_BRANCHES[@]}"; do
29+
if [ "$CURRENT_BRANCH" == $branch ]; then
30+
IS_IGNORED=true
31+
break
2432
fi
2533
done
2634

27-
28-
if [ "$IS_IGNORED" == false ]
29-
then
35+
if [ "$IS_IGNORED" == false ]; then
3036
# Edit your config here
3137
git commit -m "$CURRENT_BRANCH: $1"
3238
else

0 commit comments

Comments
 (0)