|
1 | 1 | #!/usr/bin/env bash |
| 2 | +set -euo pipefail |
2 | 3 |
|
3 | | -echo 'Running commit script' |
4 | | - |
5 | | -IGNORED_BRANCHES=("dev" "master" "qa" "uat" "staging") |
6 | | -IGNORED_PATH="./.ignore" |
7 | | - |
8 | | -if [ -f "$IGNORED_PATH" ] |
9 | | -then |
10 | | - CUSTOM_BRANCHES=$(cat "$IGNORED_PATH") |
11 | | - BRANCHES=( $CUSTOM_BRANCHES ) |
12 | | - IGNORED_BRANCHES=( ${IGNORED_BRANCHES[@]} ${BRANCHES[@]} ) |
13 | | -fi |
| 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 | 14 |
|
15 | | -CURRENT_BRANCH_CMD="git symbolic-ref --short HEAD" |
16 | | -CURRENT_BRANCH=$(eval $CURRENT_BRANCH_CMD) |
| 15 | +CURRENT_BRANCH="$(git symbolic-ref --short HEAD)" |
| 16 | +GIT_ROOT_DIRECTORY=$(git rev-parse --show-toplevel) |
| 17 | +IGNORED_BRANCHES=("dev" "master" "qa" "uat" "staging") |
| 18 | +CUSTOM_IGNORED_PATH="$GIT_ROOT_DIRECTORY/.smart-commit-ignore" |
17 | 19 |
|
18 | | -COMMIT_WITH_BRANCH="git commit -m \"$CURRENT_BRANCH: $1\"" |
19 | | -DEFAULT_COMMIT="git commit -m \"$1\"" |
| 20 | +if [ -f "$CUSTOM_IGNORED_PATH" ]; then |
| 21 | + CUSTOM_BRANCHES=$(cat "$CUSTOM_IGNORED_PATH") |
| 22 | + BRANCHES=($CUSTOM_BRANCHES) |
| 23 | + IGNORED_BRANCHES=(${IGNORED_BRANCHES[@]} ${BRANCHES[@]}) |
| 24 | +fi |
20 | 25 |
|
21 | 26 | IS_IGNORED=false |
22 | | - |
23 | | -for branch in "${IGNORED_BRANCHES[@]}"; |
24 | | - do |
25 | | - if [ "$CURRENT_BRANCH" == $branch ] |
26 | | - then |
27 | | - IS_IGNORED=true |
28 | | - break |
| 27 | + |
| 28 | +for branch in "${IGNORED_BRANCHES[@]}"; do |
| 29 | + if [ "$CURRENT_BRANCH" == $branch ]; then |
| 30 | + IS_IGNORED=true |
| 31 | + break |
29 | 32 | fi |
30 | 33 | done |
31 | 34 |
|
32 | | -if [ "$IS_IGNORED" == false ] |
33 | | -then |
34 | | - echo "Commiting with branch name -> $CURRENT_BRANCH" |
35 | | - eval $COMMIT_WITH_BRANCH |
| 35 | +if [ "$IS_IGNORED" == false ]; then |
| 36 | + # Edit your config here |
| 37 | + git commit -m "$CURRENT_BRANCH: $1" |
36 | 38 | else |
37 | | - echo "Commiting with default branch" |
38 | | - eval $DEFAULT_COMMIT |
| 39 | + git commit -m "$1" |
39 | 40 | fi |
0 commit comments