Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added pre-commit hook to handle submodules #8302

Merged
merged 2 commits into from
Apr 13, 2017

Conversation

ErisDS
Copy link
Member

@ErisDS ErisDS commented Apr 10, 2017

This PR adds a pre-commit hook that developers can install to remind them NOT to commit submodules. It is borrowed very heavily from https://github.com/chaitanyagupta/gitutils/blob/master/submodule-hooks/pre-commit, but I modified the output to closely resemble git status.

At the moment, this would have to be installed manually:

cp .github/hooks/pre-commit ./git/hooks/pre-commit
chmod ugo+x .git/hooks/pre-commit

We could use the npm postinstall hook to automatically install this using a symlink. There is a node module that would do this for us, but it makes certain assumptions.

Not sure how everyone feels - should we be building up a library of hooks & auto-linking them to make everyone's life easier, or does this feel too intrusive?


refs #8235

Usage:

In the root of your repo run

cp .github/hooks/pre-commit ./git/hooks/pre-commit
chmod ugo+x .git/hooks/pre-commit

  • Checks to see if there are any submodules about to be committed
  • Output matches closely to git st to make it easy to read
  • Requires interaction from the committer to accept that this really should be committed

refs TryGhost#8235

Usage:

In the root of your repo run

`cp .github/hooks/pre-commit ./git/hooks/pre-commit`
`chmod ugo+x .git/hooks/pre-commit`

- Checks to see if there are any submodules about to be committed
- Output matches closely to `git st` to make it easy to read
- Requires interaction from the committer to accept that this really should be committed
@ErisDS
Copy link
Member Author

ErisDS commented Apr 10, 2017

Update: maybe https://github.com/typicode/husky is the right thing to use.

We'd add something like the following to our package.json

"scripts": {
   "precommit": "sh .github/hooks/pre-commit ${GIT_PARAMS}"
}

Update again: never mind, I didn't like the way this works - the output looked like

> husky - npm run -s precommit

-e Checking submodules (pre-commit hook) 
Submodules to be committed:
  (use "git reset HEAD <file>..." to unstage)

-e 	modified:	core/client

-n -e Continue with commit? (N|y) 

Messy!

Will look at using a symlinking mechanism instead.

refs TryGhost#8235

- Grunt symlink will make a link to the pre-commit hook
- It ONLY does this if there isn't already a pre-commit hook, so won't overwrite anything
- It does this as part of npm run init, not grunt init, because a release repo would NEVER want this
- This is a dev tool, that configures the repo for development
@ErisDS
Copy link
Member Author

ErisDS commented Apr 10, 2017

I've added an extra commit to this PR that now symlinks the git hooks automagically.

This is done with grunt symlink which is also added to npm run init. It does this as part of npm run init, not grunt init, because a release repo would NEVER want this. It's a dev-only tool, that only needs to run once, or if we add new githooks.

It ONLY does this if there isn't already a pre-commit hook, so won't overwrite anything.

It should work on windows as well as mac/linux.

Have a play - see if you like it :)

@kevinansfield
Copy link
Contributor

👍 LGTM, tested and works 😄

I was looking at a pre-commit hook earlier that runs ESLint on only the changed files - undecided if it would be genuinely useful or a little annoying 🤔

@kevinansfield kevinansfield merged commit e9a5370 into TryGhost:master Apr 13, 2017
@kevinansfield kevinansfield deleted the pre-commit-hook branch April 13, 2017 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants