TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Setting up pre-commit tests with Git

22 pointsby dduvnjakover 11 years ago

6 comments

hamdalover 11 years ago
I&#x27;m not sure if this is a good practice. As project grows, running tests takes more time - remember that tests are not only unit tests which should run quickly, there are acceptance tests which can take some time to run. Waiting for commit to finish can become painfully slow.<p>Additionally, I like to commit partial solutions to feature branch as I work. Later I will fix the mess with rebase - this workflow wouldn&#x27;t work.<p>You need CI anyway, so I&#x27;d leave tests there, and let the developer decide when to run the unit tests on his machine.
评论 #6869804 未加载
yawaraminover 11 years ago
IMO we shouldn&#x27;t have to jump through hoops to be able to commit. Let people commit whatever they want and then run tests to decide if you want to merge in their branches.<p>The workflow should encourage people to commit early and often to safeguard the work they&#x27;ve been doing as much as possible. It&#x27;s very frustrating to lose work because it wasn&#x27;t in the git object store.
评论 #6870341 未加载
exDM69over 11 years ago
Wouldn&#x27;t it be a lot better choice to make this a post-receive hook on your Git server? E.g. run the tests before code gets accepted to master.<p>I often intentionally commit code that doesn&#x27;t work (pass tests or even compile), but not to master branch. One of the big advantages of Git is that you can share code with your team mates even if that code doesn&#x27;t work yet.
评论 #6870128 未加载
Simucalover 11 years ago
At my work I setup a pre-commit hook that my team uses to run Uncrustify, a source-code beautifier. If the style of the commit doesn&#x27;t match our rules for that language it will spit out a command for you to run to fix it. I think overall it has been a big win for our team. Uncrustify runs almost instantly and having a uniformly styled code-base is worth the small inconvenience.
评论 #6872821 未加载
seanhandleyover 11 years ago
I can see this working if you&#x27;re collaborating without Github&#x27;s pull requests.<p>Personally I&#x27;d want to scope it to only run the test suite for merge commits onto the master branch since it&#x27;s reasonable in development branches to commit changes with failing tests.
IanCalover 11 years ago
Warning, this won&#x27;t check the code you&#x27;re committing, it&#x27;ll check the code you have in your working directory. You need to stash all non staged changes before running the tests.