0

Possible Duplicate:
Git pre-commit hook : changed/added files

It may be good to add a code verifier or checker of some sort before you commit a list of source codes. Facebook even integrated automated tests into the committing process( or so I heard). What I need is a way to get the list of files that is going to be committed, not just edited. Here is a few reasons for this:

  1. git commit -m "message" can modify default message bypasses prepare-message and commit-msg hooks when I tried to use them to get files.
  2. pre-commit hook do not get any arguments from the git commit command so it is not easy to tell what files are being committed, especially from a partial commit.
  3. We have multiple users on one shared workstation, one shared user and one shared local repository( I can do nothing about it, I just do my job there ), so I do not want to verify other's codes when I commit mine (pretty sure this feeling is mutual). So if I use git diff-index --name-only HEAD, I get more codes to verify than I want to.
  4. Automation is awesome and I think it's cool to install a code verifier in the hooks.
  5. The committing process has better to be aborted if the verification fails.

If there is any other way to automatically verify the codes in the ways that I described, pleeease tell me how. I really need this. Thank you very much.

Community
  • 1
  • 1
Rex Xia
  • 53
  • 6
  • Have you seen [Git pre-commit hook : changed/added files](http://stackoverflow.com/q/2412450) – CharlesB Aug 28 '12 at 14:14
  • Yes I have, but when I need the committed file lists from a partial commit, I don't know how to get them. I don't need all the files that have been modified, I just need those in the commit command. – Rex Xia Aug 29 '12 at 06:38
  • sorry but I have no idea what a partial commit is, can you explain? – CharlesB Aug 29 '12 at 06:54
  • If I have modified three files but only commit two, using `git commit file_1 file_2`, then how could pre-commit hook get to know I have only committed two files? If I use `git diff` I get three modified files instead of two. – Rex Xia Aug 29 '12 at 07:32
  • as stated in the link above, `git diff --cached` gives you only the staged files, that's what you want – CharlesB Aug 29 '12 at 07:37

0 Answers0