|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
4 | | -IS_IGNORED=false |
5 | | -IGNORED_PATH="./.ignore" |
6 | 4 | CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" |
| 5 | +GIT_ROOT_DIRECTORY=$(git rev-parse --show-toplevel) |
7 | 6 | IGNORED_BRANCHES=("dev" "master" "qa" "uat" "staging") |
| 7 | +CUSTOM_IGNORED_PATH="$GIT_ROOT_DIRECTORY/.smart-commit-ignore" |
8 | 8 |
|
9 | | -colorEcho(){ |
10 | | - RED="\033[0;31m" |
11 | | - GREEN='\033[0;32m' |
12 | | - YELLOW='\033[1;33m' |
13 | | - NO_COLOR='\033[0m' |
14 | | - printf "${!1}${2} ${NO_COLOR}\n" |
15 | | -} |
16 | | - |
17 | | -commitWithBranch() { |
18 | | - colorEcho "GREEN" "Commit translation: \"$CURRENT_BRANCH: $1\"" |
19 | | - # Edit your config here |
20 | | - git commit -m "$CURRENT_BRANCH: $1" |
21 | | -} |
22 | | - |
23 | | -if [[ -f "$IGNORED_PATH" ]] |
| 9 | +if [ -f "$CUSTOM_IGNORED_PATH" ] |
24 | 10 | then |
25 | | - CUSTOM_BRANCHES=$(cat "$IGNORED_PATH") |
26 | | - BRANCHES=( $CUSTOM_BRANCHES ) |
27 | | - IGNORED_BRANCHES=( ${IGNORED_BRANCHES[@]} ${BRANCHES[@]} ) |
28 | | - colorEcho "YELLOW" "Excluding branches from .ignore file." |
29 | | -else |
30 | | - colorEcho "YELLOW" ".ignore file not found, excluding default branches." |
| 11 | + CUSTOM_BRANCHES=$(cat "$CUSTOM_IGNORED_PATH") |
| 12 | + BRANCHES=($CUSTOM_BRANCHES) |
| 13 | + IGNORED_BRANCHES=(${IGNORED_BRANCHES[@]} ${BRANCHES[@]}) |
31 | 14 | fi |
32 | 15 |
|
33 | | -for branch in "${IGNORED_BRANCHES[@]}" |
| 16 | +IS_IGNORED=false |
| 17 | + |
| 18 | +for branch in "${IGNORED_BRANCHES[@]}"; |
34 | 19 | do |
35 | 20 | if [ "$CURRENT_BRANCH" == $branch ] |
36 | 21 | then |
|
42 | 27 |
|
43 | 28 | if [ "$IS_IGNORED" == false ] |
44 | 29 | then |
45 | | - commitWithBranch $1 |
| 30 | + # Edit your config here |
| 31 | + git commit -m "$CURRENT_BRANCH: $1" |
46 | 32 | else |
47 | | - colorEcho "GREEN" "Commit translation: \"$1\"" |
48 | 33 | git commit -m "$1" |
49 | 34 | fi |
0 commit comments