Skip to content

Commit

Permalink
add post-merge hook
Browse files Browse the repository at this point in the history
  • Loading branch information
lbenie committed Apr 26, 2018
1 parent d904ca4 commit d9bcd8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions husky.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
hooks: {
'pre-commit': 'lint-staged',
'post-merge': 'yarn postmerge',
},
};

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"scripts": {
"test": "jest --config jest.config.js --colors",
"test:dev": "cross-env BABEL_ENV=test jest --config jest.config.js --watch",
"changelog": "conventional-changelog -i CHANGELOG.md -s"
"changelog": "conventional-changelog -i CHANGELOG.md -s",
"postmerge": "sh post-merge.sh"
},
"dependencies": {
"is-dom": "^1.0.9"
Expand Down
15 changes: 15 additions & 0 deletions post-merge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com

# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.

changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"

check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}

# Example usage
# In this example it's used to run `npm install` if yarn.lock changed
check_run yarn.lock "yarn"

0 comments on commit d9bcd8b

Please sign in to comment.