开发者

How to have git disregard unstaged changes on a post/pre-commit hook

开发者 https://www.devze.com 2023-03-24 06:22 出处:网络
I am trying to do the commit should pass all tests to succeed automation in my rails project. The problem is that I use git add --patch quite a lot before I commit and I want my tests to only run on t

I am trying to do the commit should pass all tests to succeed automation in my rails project. The problem is that I use git add --patch quite a lot before I commit and I want my tests to only run on the staged changes.

Solution 1: do a git stash --keep-index on the pre-commit or a simple git stash on the post commit, followed by the hook (rake tests) and git stash pop. This means that I'll have to wait for it to finish and while it runs, I won't have access to my unstaged changes.

Solution 2: I setup a new local repo (the tester) and setup the post-commit hook from the first repo (the development) to push to the tester repo. The tester repo should have a post-receive hook to run the tests and inform me (via email or whateva) whether it passes or开发者_运维百科 fails to fix the commit before I push.

The second solution sounds much better (I guess) even though there will be differences on the repos due to ignored files.

Do you have another solution to propose?


Take a look at git-new-workdir (you can find it in the git repository contrib/workdir). It creates a new working directory you can use to run the tests.


I have finally resorted in Solution 2 which then evolved into a mini continuous testing system.

0

精彩评论

暂无评论...
验证码 换一张
取 消