Skip to content

Commit 1f57ad0

Browse files
authored
Merge pull request #13 from mesaugat/smart-commit-ignore
Make ignoring branches work from child directories
2 parents 647d418 + b75f4b5 commit 1f57ad0

3 files changed

Lines changed: 28 additions & 20 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

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,27 @@ curl https://raw.githubusercontent.com/sbimochan/smart-commit/master/commit -o /
1414

1515
* If your current branch name is `EF-803`
1616

17-
```shell
18-
$ commit "New feature"
17+
```shell
18+
$ commit "New feature"
1919

20-
# translates to
21-
git commit -m "EF-803: New feature"
22-
```
20+
# translates to
21+
git commit -m "EF-803: New feature"
22+
```
2323

2424
* If your current branch is either of `dev`, `uat`, `qa`, `staging` or `master`
2525

26-
```shell
27-
$ commit "New feature"
26+
```shell
27+
$ commit "New feature"
2828

29-
# translates to
30-
git commit -m "New feature"
31-
```
29+
# translates to
30+
git commit -m "New feature"
31+
```
32+
33+
## Skip Branches
34+
35+
To add a custom branch that you would like to skip, create a `.smart-commit-ignore` file in your top level directory. A `.smart-commit-ignore` file looks like [this](https://github.com/sbimochan/smart-commit/blob/master/.smart-commit-ignore).
3236

33-
You can create a `.ignore` file in your directory to add custom branches you want to ignore. A `.ignore` file looks like [this](https://github.com/sbimochan/smart-commit/blob/master/.ignore).
37+
Additionally, you might want to add `.smart-commit-ignore` to your `.gitignore` file.
3438

3539
## Contributors
3640

commit

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
echo 'Running commit script'
44

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

8-
if [ -f "$IGNORED_PATH" ]
9+
if [ -f "$CUSTOM_IGNORED_PATH" ]
910
then
10-
CUSTOM_BRANCHES=$(cat "$IGNORED_PATH")
11-
BRANCHES=( $CUSTOM_BRANCHES )
12-
IGNORED_BRANCHES=( ${IGNORED_BRANCHES[@]} ${BRANCHES[@]} )
13-
fi
11+
CUSTOM_BRANCHES=$(cat "$CUSTOM_IGNORED_PATH")
12+
BRANCHES=($CUSTOM_BRANCHES)
13+
IGNORED_BRANCHES=(${IGNORED_BRANCHES[@]} ${BRANCHES[@]})
14+
fi
1415

1516
CURRENT_BRANCH_CMD="git rev-parse --abbrev-ref HEAD"
1617
CURRENT_BRANCH=$(eval $CURRENT_BRANCH_CMD)
@@ -19,7 +20,7 @@ COMMIT_WITH_BRANCH="git commit -m \"$CURRENT_BRANCH: $1\""
1920
DEFAULT_COMMIT="git commit -m \"$1\""
2021

2122
IS_IGNORED=false
22-
23+
2324
for branch in "${IGNORED_BRANCHES[@]}";
2425
do
2526
if [ "$CURRENT_BRANCH" == $branch ]
@@ -34,6 +35,5 @@ then
3435
echo "Commiting with branch name -> $CURRENT_BRANCH"
3536
eval $COMMIT_WITH_BRANCH
3637
else
37-
echo "Commiting with default branch"
3838
eval $DEFAULT_COMMIT
3939
fi

0 commit comments

Comments
 (0)