unit testing - Enforcing code standards in git before commit is accepted -


alright, here's scenario: team of developers wants ensure new code matches defined coding standards , unit tests passing before commit accepted. here's trick, of tests need run on dedicated testing machine , not have access modify git server must done using local commit hook on each dev machine.

while specs pretty strict (we're not switching windows or subversion, example) real world problem there flexibility if have solution fits.

  • we're using git , *nix.
  • the updated code needs sent server run test suite.
  • a list of modified files needs provided ensure match coding standard.
  • its rather large codebase, should send smallest amount of information necessary ensure identical copies of codebase.
  • if tests fail message needs displayed error , commit should blocked.
  • assume trust our dev team , okay allow tests bypassed --no-verify option.

the question: best way test server sync local environment run tests? sort of hash-to-hash matching git patch new commit? skip git altogether , rsync? else altogether?

update 8/7/13: shot myself in foot mentioning remote repo. point isn't block code being pushed shared / remote repo, prevent local commit happening. whether or not considered best practice not point in case, specific small team of developers want exact functionality. question best way achieve goal.

add custom git command which:

  1. temporarily commit
  2. pushes remote server
  3. runs tests (using ci server, post-receive hook, or ssh)
  4. reverts commit if tests fail

create executable called git-test-n-commit , place in path:

#!/bin/bash echo "committing results..." git commit "$@" echo "pushing remote testing server..." git push remote-server-git-url remote-branch -f echo "running tests" ssh remote-server 'cd my_repo; run-my-tests' ||     (echo "tests failed, undoing commit" && git reset head^) 

then instead of calling git commit args, developers can call git test-n-commit args. if tests pass code remain committed. if tests fail if never committed.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -