Re-creating files during pre-capture?

I have set up a task mvn java-formatter:format

in the pre-commit hook. This task will format the Java source codes.

pushd src/ > /dev/null

mvn java-formatter:format
RETVAL=$?
if (($RETVAL == 1)); then
        exit 1
fi

popd > /dev/null

      

I need to add new formatted source files to commit. How can i do this?

+3


source to share


2 answers


The pre-commit hook must contain git add

to change the index to be committed.

See for example " git pre-commit

hook, add file to index
".

Try it git add -A :/.

(see " Add as in the root folder of the repository ")



If you only need to add the files that have already been supplied, you need to:

+5


source


It can be done, but requires a complex script.

You can find the same problem here. There it updates the version of the file on every commit instead of formatting the code. It works completely: https://github.com/addonszz/Galileo/tree/master/githooks



Then you simply replace the algorithm for replacing the version file with the file 'updateVersion.sh', according to your Code Formatting algorithm. You may need to change a few things, like removing the branch restriction, because there the script only works if you are on a development branch.

Also, it will only modify the file if supplied. If the file is not supplied, it will do nothing. More precisely, he prints what he does at every turn.

0


source







All Articles