diff options
Diffstat (limited to 'pre-commit.d')
-rwxr-xr-x | pre-commit.d/20store-empty-directory | 27 | ||||
-rwxr-xr-x | pre-commit.d/20warn-hardlinks | 10 | ||||
-rwxr-xr-x | pre-commit.d/20warn-special-file | 12 | ||||
-rwxr-xr-x | pre-commit.d/30store-metadata | 25 | ||||
-rw-r--r-- | pre-commit.d/README | 2 |
5 files changed, 76 insertions, 0 deletions
diff --git a/pre-commit.d/20store-empty-directory b/pre-commit.d/20store-empty-directory new file mode 100755 index 0000000..0cab9df --- /dev/null +++ b/pre-commit.d/20store-empty-directory @@ -0,0 +1,27 @@ +#!/bin/sh +set -e + +# These version control systems do not track directories, so empty +# directories must be stored specially. +if [ "$VCS" = git ] || [ "$VCS" = hg ]; then + # Make sure the file is not readable by others, since it can leak + # information about contents of non-readable directories in /etc. + umask 077 + + if [ -e .etckeeper ]; then + egrep -v '^mkdir ' .etckeeper > .etckeeper.new || true + fi + find -type d -empty | grep -v /.git/ | grep -v /.hg/ | sort | + sed -e "s/^/mkdir -p '/" -e "s/\$/'/" >> .etckeeper.new + + if [ ! -e .etckeeper ] || ! cmp -s .etckeeper .etckeeper.new ; then + mv -f .etckeeper.new .etckeeper + if [ "$VCS" = git ]; then + git add .etckeeper + elif [ "$VCS" = hg ]; then + hg add .etckeeper + fi + else + rm -f .etckeeper.new + fi +fi diff --git a/pre-commit.d/20warn-hardlinks b/pre-commit.d/20warn-hardlinks new file mode 100755 index 0000000..8716dbd --- /dev/null +++ b/pre-commit.d/20warn-hardlinks @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +if [ "$VCS" = git ] || [ "$VCS" = hg ]; then + hardlinks=$(find -type f -not -links 1 | grep -v /.git/) || true + if [ -n "$hardlinks" ]; then + echo "etckeeper warning: hardlinked files could cause problems with $VCS:" >&2 + echo "$hardlinks" >&2 + fi +fi diff --git a/pre-commit.d/20warn-special-file b/pre-commit.d/20warn-special-file new file mode 100755 index 0000000..42e812b --- /dev/null +++ b/pre-commit.d/20warn-special-file @@ -0,0 +1,12 @@ +#!/bin/sh +set -e + +if [ "$VCS" = git ] || [ "$VCS" = hg ]; then + special=$(find -not -type d -not -type f -not -type l | grep -v /.git/) || true + if [ -n "$special" ]; then + echo "etckeeper warning: special files could cause problems with $VCS:" >&2 + echo "$special" >&2 + fi +fi + +true diff --git a/pre-commit.d/30store-metadata b/pre-commit.d/30store-metadata new file mode 100755 index 0000000..959e714 --- /dev/null +++ b/pre-commit.d/30store-metadata @@ -0,0 +1,25 @@ +#!/bin/sh +set -e + +if [ "$VCS" = git ] || [ "$VCS" = hg ]; then + # Make sure the file is not readable by others, since it can leak + # information about contents of non-readable directories in /etc. + umask 077 + + # ensure the file exists so that it will list its own metadata + if [ ! -e .metadata ]; then + metastore --save + fi + + # metastore doesn't produce the same output file for the same metadata + # everytime, so avoid changing the file if nothing really changed. + if [ ! -z "$(metastore --compare)" ]; then + metastore --save + + if [ "$VCS" = git ]; then + git add .metadata + elif [ "$VCS" = hg ]; then + hg add .metadata + fi + fi +fi diff --git a/pre-commit.d/README b/pre-commit.d/README new file mode 100644 index 0000000..051d094 --- /dev/null +++ b/pre-commit.d/README @@ -0,0 +1,2 @@ +This is run by a git pre-commit hook before committing changes to the +repository. This can be used for storing metadata, and for sanity checks. |