PyCharm pre-commit hook for CVS

Hi - We have a requirement to have a pre-commit hook for CVS that would do the following:

1. Run tests before checkin and fail if any test fails
2. Run jsHint on .js files and fail if there is a jsHint error

I couldn't find any plugins for something like this nor could I find any documentation to make this happen.

Any ideas?


  • Sid
Comment actions Permalink
This is going beyond the scope of an IDE and is usually done through a continuous integration server (e.g. TeamCity). You could set that server up to automatically track and build your feature branches (See feature branches here). The build would fail if any of your requirements (unit tests, code metrics, project specific checks, ...) fail and the developers would be notified about that failure. However, something roughly similar can be achieved through PyCharm as well.

Solution 1
You could write a small python program that executes all your tests with the command line runner. After that, the tool would call jsHint on the .js files. How this needs to be done depends on how you have structured your project and tests and which frameworks you use.  Then, you specify this python program as external tool (Preferences > External Tools). After that, you can execute that tool right from the commit dialog.

The only thing you can't do is to enforce this. There is no way to specify that this external tool must be run before committing and that committing changes is not possible if the tool returns an error. Also, your team members will need to setup the tool configuration (just the config, not the tool itself) on their machines as well because this is an IDE configuration option, not an option that is shared through the project file.

Solution 2:
Another, less involved solution would be to create a shared run configuration (make sure that "Share" is checked right next to the name) that runs all tests. You can then write a "test" that calls jsHint to run on all your .js files and that fails if something isn't right. Yes, this really isn't a test but it gets the job done. Also, you would need to run it manually (this time not possible from the commit dialog) and also there's no way to enforce running it.

The advantage of the first solution is that it can be run right from the commit dialog, the advantage of the second solution is that it is probably less complicated to create and that it can be shared with your team with one click.

I hope this provides you with some ideas how the desired behavior can be achieved.
Comment actions Permalink
Thanks for the comprehensive reply - We do have something similar to Solution 1 currently working but we wanted to enforce such on checkin. I am currently looking at TeamCity and cvs pre-commit hooks.

  • Sid
Comment actions Permalink
If you need to stay with CVS, the feature is Pre-Tested Commits. I have only used it with SVN. You'll have to check if that is possible with CVS, though.

Even with pre-tested commits, there's no way to enforce them. PyCharm doesn't stop users checking into version control without running a build first.

Please sign in to leave a comment.