Mercurial > repos > fubar > egapx_runner
annotate oldgit/hooks/pre-commit.sample @ 2:a3b158471bd3 draft
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
author | fubar |
---|---|
date | Sun, 04 Aug 2024 00:06:43 +0000 |
parents | |
children |
rev | line source |
---|---|
2
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
1 #!/bin/sh |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
2 # |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
3 # An example hook script to verify what is about to be committed. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
4 # Called by "git commit" with no arguments. The hook should |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
5 # exit with non-zero status after issuing an appropriate message if |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
6 # it wants to stop the commit. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
7 # |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
8 # To enable this hook, rename this file to "pre-commit". |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
9 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
10 if git rev-parse --verify HEAD >/dev/null 2>&1 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
11 then |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
12 against=HEAD |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
13 else |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
14 # Initial commit: diff against an empty tree object |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
15 against=$(git hash-object -t tree /dev/null) |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
16 fi |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
17 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
18 # If you want to allow non-ASCII filenames set this variable to true. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
19 allownonascii=$(git config --type=bool hooks.allownonascii) |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
20 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
21 # Redirect output to stderr. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
22 exec 1>&2 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
23 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
24 # Cross platform projects tend to avoid non-ASCII filenames; prevent |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
25 # them from being added to the repository. We exploit the fact that the |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
26 # printable range starts at the space character and ends with tilde. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
27 if [ "$allownonascii" != "true" ] && |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
28 # Note that the use of brackets around a tr range is ok here, (it's |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
29 # even required, for portability to Solaris 10's /usr/bin/tr), since |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
30 # the square bracket bytes happen to fall in the designated range. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
31 test $(git diff --cached --name-only --diff-filter=A -z $against | |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
32 LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
33 then |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
34 cat <<\EOF |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
35 Error: Attempt to add a non-ASCII file name. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
36 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
37 This can cause problems if you want to work with people on other platforms. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
38 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
39 To be portable it is advisable to rename the file. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
40 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
41 If you know what you are doing you can disable this check using: |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
42 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
43 git config hooks.allownonascii true |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
44 EOF |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
45 exit 1 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
46 fi |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
47 |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
48 # If there are whitespace errors, print the offending file names and fail. |
a3b158471bd3
planemo upload for repository https://github.com/ncbi/egapx commit 98875ef7eda9323fc9991970103954e9097d9e73
fubar
parents:
diff
changeset
|
49 exec git diff-index --check --cached $against -- |