Robert Collins | 18c9bbd | 2015-07-10 14:00:11 +1200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # An example hook script to transform a patch taken from an email |
| 4 | # by git am. |
| 5 | # |
| 6 | # The hook should exit with non-zero status after issuing an |
| 7 | # appropriate message if it wants to stop the commit. The hook is |
| 8 | # allowed to edit the patch file. |
| 9 | # |
| 10 | # To enable this hook, rename this file to "applypatch-transform". |
| 11 | # |
| 12 | # This example changes the path of Lib/unittest/mock.py to mock.py |
| 13 | # Lib/unittest/tests/testmock to tests and Misc/NEWS to NEWS, and |
| 14 | # finally skips any patches that did not alter mock.py or its tests. |
| 15 | |
| 16 | set -eux |
| 17 | |
| 18 | patch_path=$1 |
| 19 | |
| 20 | # Pull out mock.py |
| 21 | filterdiff --clean --strip 3 --addprefix=a/mock/ -i 'a/Lib/unittest/mock.py' -i 'b/Lib/unittest/mock.py' $patch_path > $patch_path.mock |
| 22 | # And the tests |
| 23 | filterdiff --clean --strip 5 --addprefix=a/mock/tests/ -i 'a/Lib/unittest/test/testmock/*.py' -i 'b/Lib/unittest/test/testmock/*.py' $patch_path > $patch_path.tests |
| 24 | # Lastly we want to pick up any NEWS entries. |
| 25 | filterdiff --strip 2 --addprefix=a/ -i a/Misc/NEWS -i b/Misc/NEWS $patch_path > $patch_path.NEWS |
| 26 | cp $patch_path $patch_path.orig |
| 27 | # bash |
| 28 | cat $patch_path.mock $patch_path.tests > $patch_path |
| 29 | filtered=$(cat $patch_path) |
| 30 | if [ -n "${filtered}" ]; then |
| 31 | cat $patch_path.NEWS >> $patch_path |
| 32 | exitcode=0 |
| 33 | else |
| 34 | exitcode=1 |
| 35 | fi |
| 36 | |
| 37 | rm $patch_path.mock $patch_path.tests $patch_path.NEWS |
| 38 | exit $exitcode |