Skip to content

Commit 4d2c124

Browse files
authoredMar 1, 2019
Add disallow-commits hook (#2)
1 parent 27b7450 commit 4d2c124

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed
 

‎CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ Security - in case of vulnerabilities.
1515
-->
1616

1717
## [Unreleased]
18-
19-
_TBD_
18+
### Added
19+
- Added hooks `disallow-commits`
2020

2121
## [1.1.0] 2019-03-01
22-
2322
### Added
2423
- Added hooks `motivation`
2524
- Added hooks `files-watcher`
2625

2726
## [1.0.0] 2019-03-01
28-
2927
Initial release.

‎disallow-commits/disallow-commits

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
# The `pre-commit` hook to disallow commits to some branches.
3+
# Useful for example to disallow commits directly to master branch.
4+
# Example of config:
5+
# ~~~
6+
# [disallow-commits]
7+
# branch = master
8+
# branch = development
9+
# ~~~
10+
11+
FCR='\033[1;31m' # Red
12+
NC='\033[0m'
13+
14+
branch_name="$(git rev-parse --abbrev-ref HEAD)"
15+
closed_branches=$(git config --get-all disallow-commits.branch)
16+
17+
if [[ -z ${closed_branches} ]]; then
18+
closed_branches="master"
19+
fi
20+
21+
for closed_branch in ${closed_branches} ; do
22+
if [[ "${branch_name}" =~ "${closed_branch}" ]]; then
23+
echo "${FCR}You can't commit directly to ${closed_branch} branch${NC}"
24+
exit 1
25+
fi
26+
done

0 commit comments

Comments
 (0)