GIT pre-commit hook problem with "git commit -m 'text' file.c" syntax

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!
I am writing a "pre-hook" script, which will be responsible for checking style (formatting/indenting) of the C source code. The script at the beginning executes "git diff --name-only -z --cached HEAD" in order to get all the committed changes, then it makes a two copies of the staged file, one is kept as an original and the second one is formatted by "astyle" program. Then I am creating patch using "git diff" between the original file and formatted one. After that I am applying patch (asking user some questions before doing that) to the index or to the file in the working tree (behaviour depends on the situation, if the file was staged and modified after that (git status returns file as "staged" and "modified but NOT staged") I am applying changes to index using "git apply -v --cached patch", otherwise if the file was staged and no changes to it were made afterwards (git status returns file as "staged" only) I am modifying file in the working tree using "git apply -v patch" and adding modified file to stage using "git add my_file.c"). Everything works fine till the moment when user modifies a file and commits it using command "git commit -m 'comment' my_file.c". After that the committed file looks ok (also in git log etc.) but when I type "git status" or use "gitk" I see some leftovers. Gitk shows a "local changes checked to index but not committed" -- this is a raw file before applying a patch -- and "local uncommitted changes not checked into index" -- this is a file after patch was applied. The manual says that listing files as arguments to the commit command, make the git ignore changes staged in the index, and instead record the current content of the listed files. I would like to ask you if there is a way to force commit to ALWAYS add files before commit? Can I distinguish, that the commit was executed using syntax "git commit -m 'text' file.c"? Is there any other solution for my problem?

Thank you for your time!
Michal Dudek

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]