Skip to content

Commit a90342f

Browse files
committed
Make commit work with ignored branches inside any sub-folder
1 parent 59f0602 commit a90342f

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

.smart-commit-ignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
hotfix
2+
sprint-11
3+
new-feature
4+
user-story-5

commit

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
echo 'Running commit script'
44

5-
IGNORED_BRANCHES=("dev" "master" "qa" "uat" "staging")
6-
IGNORED_PATH="./.ignore"
5+
IGNORED_BRANCHES=("dev" "master" "qa" "uat" "staging")
6+
7+
ROOT_DIRECTORY_CMD="git rev-parse --show-toplevel"
8+
GIT_ROOT_DIRECTORY=$(eval $ROOT_DIRECTORY_CMD)
9+
10+
CUSTOM_IGNORED_PATH="$GIT_ROOT_DIRECTORY/.smart-commit-ignore"
711

812
if [ -f "$IGNORED_PATH" ]
913
then
1014
CUSTOM_BRANCHES=$(cat "$IGNORED_PATH")
11-
BRANCHES=( $CUSTOM_BRANCHES )
12-
IGNORED_BRANCHES=( ${IGNORED_BRANCHES[@]} ${BRANCHES[@]} )
13-
fi
15+
BRANCHES=($CUSTOM_BRANCHES)
16+
IGNORED_BRANCHES=(${IGNORED_BRANCHES[@]} ${BRANCHES[@]})
17+
fi
1418

1519
CURRENT_BRANCH_CMD="git rev-parse --abbrev-ref HEAD"
1620
CURRENT_BRANCH=$(eval $CURRENT_BRANCH_CMD)
@@ -19,7 +23,7 @@ COMMIT_WITH_BRANCH="git commit -m \"$CURRENT_BRANCH: $1\""
1923
DEFAULT_COMMIT="git commit -m \"$1\""
2024

2125
IS_IGNORED=false
22-
26+
2327
for branch in "${IGNORED_BRANCHES[@]}";
2428
do
2529
if [ "$CURRENT_BRANCH" == $branch ]
@@ -34,6 +38,5 @@ then
3438
echo "Commiting with branch name -> $CURRENT_BRANCH"
3539
eval $COMMIT_WITH_BRANCH
3640
else
37-
echo "Commiting with default branch"
3841
eval $DEFAULT_COMMIT
3942
fi

0 commit comments

Comments
 (0)