Skip to content

Commit

Permalink
Merge pull request #13 from mesaugat/smart-commit-ignore
Browse files Browse the repository at this point in the history
Make ignoring branches work from child directories
  • Loading branch information
sbimochan authored Jan 13, 2019
2 parents 647d418 + b75f4b5 commit 1f57ad0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .smart-commit-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hotfix
sprint-11
new-feature
user-story-5
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,27 @@ curl https://raw.githubusercontent.com/sbimochan/smart-commit/master/commit -o /

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

```shell
$ commit "New feature"
```shell
$ commit "New feature"

# translates to
git commit -m "EF-803: New feature"
```
# translates to
git commit -m "EF-803: New feature"
```

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

```shell
$ commit "New feature"
```shell
$ commit "New feature"

# translates to
git commit -m "New feature"
```
# translates to
git commit -m "New feature"
```

## Skip Branches

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).

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).
Additionally, you might want to add `.smart-commit-ignore` to your `.gitignore` file.

## Contributors

Expand Down
18 changes: 9 additions & 9 deletions commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

echo 'Running commit script'

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

if [ -f "$IGNORED_PATH" ]
if [ -f "$CUSTOM_IGNORED_PATH" ]
then
CUSTOM_BRANCHES=$(cat "$IGNORED_PATH")
BRANCHES=( $CUSTOM_BRANCHES )
IGNORED_BRANCHES=( ${IGNORED_BRANCHES[@]} ${BRANCHES[@]} )
fi
CUSTOM_BRANCHES=$(cat "$CUSTOM_IGNORED_PATH")
BRANCHES=($CUSTOM_BRANCHES)
IGNORED_BRANCHES=(${IGNORED_BRANCHES[@]} ${BRANCHES[@]})
fi

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

IS_IGNORED=false

for branch in "${IGNORED_BRANCHES[@]}";
do
if [ "$CURRENT_BRANCH" == $branch ]
Expand All @@ -34,6 +35,5 @@ then
echo "Commiting with branch name -> $CURRENT_BRANCH"
eval $COMMIT_WITH_BRANCH
else
echo "Commiting with default branch"
eval $DEFAULT_COMMIT
fi

0 comments on commit 1f57ad0

Please sign in to comment.