diff options
Diffstat (limited to 'pre-commit.d')
-rwxr-xr-x | pre-commit.d/20store-empty-directory | 34 | ||||
-rwxr-xr-x | pre-commit.d/20warn-hardlinks | 11 | ||||
-rwxr-xr-x | pre-commit.d/20warn-special-file | 11 | ||||
-rwxr-xr-x | pre-commit.d/30store-metadata | 31 |
4 files changed, 54 insertions, 33 deletions
diff --git a/pre-commit.d/20store-empty-directory b/pre-commit.d/20store-empty-directory index e0f9538..0cab9df 100755 --- a/pre-commit.d/20store-empty-directory +++ b/pre-commit.d/20store-empty-directory @@ -1,19 +1,27 @@ #!/bin/sh set -e -# Make sure the file is not readable by others, since it can leak -# information about contents of non-readable directories in /etc. -umask 077 +# 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/ | sort | - sed -e "s/^/mkdir -p '/" -e "s/\$/'/" >> .etckeeper.new + 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 - git add .etckeeper -else - rm -f .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 index 3dd7a96..8716dbd 100755 --- a/pre-commit.d/20warn-hardlinks +++ b/pre-commit.d/20warn-hardlinks @@ -1,7 +1,10 @@ #!/bin/sh set -e -hardlinks=$(find -type f -not -links 1 | grep -v /.git/) || true -if [ -n "$hardlinks" ]; then - echo "etckeeper warning: hardlinked files could cause problems with git:" >&2 - echo "$hardlinks" >&2 + +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 index cb4d019..42e812b 100755 --- a/pre-commit.d/20warn-special-file +++ b/pre-commit.d/20warn-special-file @@ -1,9 +1,12 @@ #!/bin/sh set -e -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 git:" >&2 - echo "$special" >&2 + +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 index b878abd..959e714 100755 --- a/pre-commit.d/30store-metadata +++ b/pre-commit.d/30store-metadata @@ -1,18 +1,25 @@ #!/bin/sh set -e -# 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 [ "$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 + # 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 -# 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 - git add .metadata + if [ "$VCS" = git ]; then + git add .metadata + elif [ "$VCS" = hg ]; then + hg add .metadata + fi + fi fi |