Skip to content

Commit e926047

Browse files
authored
chore: Adds git pre-push hook that validates commit message formatting (#516)
* chore: Adds git pre-push hook that validates commit message formatting * chore: Adds a pre-push hook * refactor: Fixed script name * refactor: Make the script fancy * chore: Add pre-commit hook too * chore: Add helper * refactor: execute a common script * fix: whitespace * fix: fix up hints * fix: no whitespace * chore: add a commit-msg hook * chore: bad message * chore: use stdin * chore: a better stdin approach * docs: fix up docs for windows users * docs: bold, not italics * chore: add --silent option
1 parent c32da79 commit e926047

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# Because commits are hard to remove (unless you are a pro at interactive
3+
# rebasing), this commit hook script should make it easier for new
4+
# contributors.
5+
6+
commit_msg=$1
7+
cat "$commit_msg" | npm run changelog-lint-from-stdin --silent
8+
exit_status=$?
9+
10+
if [ $exit_status -ne 0 ]; then
11+
echo
12+
echo "Your unsaved commit message:"
13+
echo
14+
cat "$commit_msg"
15+
echo
16+
echo "--------------------------------------------------------------------"
17+
echo "Your commit was not saved because the message was formatted incorrectly."
18+
echo "See the error log above."
19+
echo "--------------------------------------------------------------------"
20+
echo
21+
echo "For formatting instructions, see:"
22+
echo "https://github.com/mozilla/web-ext/blob/master/CONTRIBUTING.md#writing-commit-messages"
23+
echo
24+
echo "To bypass this check and commit anyway, use:"
25+
echo "git commit --no-verify ..."
26+
echo
27+
fi
28+
29+
exit $exit_status

CONTRIBUTING.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,16 @@ Examples:
141141
If you want to use scopes then it would look more like:
142142
`feat(dysfunctioner): Added --quiet option`.
143143

144-
### Check for commit message lint
144+
### Checking commit message formatting
145145

146-
You can test that your commit message is formatted in a way that will support
147-
our changelog generator like this:
146+
Because editing git history is difficult for many developers,
147+
the commit message formatting described above is automatically enforced
148+
each time you commit to your work branch.
148149

149-
npm run changelog-lint
150+
**If you're on Windows**, the commit message verification currently doesn't
151+
work (sorry!). You will need to commit to your branch using this command:
152+
153+
git commit --no-verify
150154

151155
## Squashing commits
152156

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Mozilla Public License Version 2.0
3535
means any form of the work other than Source Code Form.
3636

3737
1.7. "Larger Work"
38-
means a work that combines Covered Software with other material, in
38+
means a work that combines Covered Software with other material, in
3939
a separate file or files, that is not Covered Software.
4040

4141
1.8. "License"

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"publish-coverage": "grunt coveralls",
2121
"nsp-check": "nsp check -o summary",
2222
"changelog": "conventional-changelog -p angular -u",
23-
"changelog-lint": "conventional-changelog-lint --from master"
23+
"changelog-lint": "conventional-changelog-lint --from master",
24+
"changelog-lint-from-stdin": "conventional-changelog-lint"
2425
},
2526
"homepage": "https://github.com/mozilla/web-ext",
2627
"repository": {
@@ -85,6 +86,7 @@
8586
"eslint-plugin-flowtype": "2.19.0",
8687
"firefox-client": "0.3.0",
8788
"flow-bin": "0.33.0",
89+
"git-hooks": "1.1.1",
8890
"grunt": "1.0.1",
8991
"grunt-contrib-clean": "1.0.0",
9092
"grunt-contrib-copy": "1.0.0",

0 commit comments

Comments
 (0)