86e974ca16bcafc5acb5b9357028e7e3b7758637
[jelmer/etckeeper.git] / pre-commit.d / 30store-metadata
1 #!/bin/sh
2 set -e
3
4 if [ "$VCS" = git ] || [ "$VCS" = hg ] || [ "$VCS" = bzr ]; then
5         # Make sure the file is not readable by others, since it can leak
6         # information about contents of non-readable directories in /etc.
7         umask 077
8
9         # ensure the file exists so that it will list its own metadata
10         if [ ! -e .metadata ]; then
11                 metastore --save
12         fi
13
14         # metastore doesn't produce the same output file for the same metadata
15         # everytime, so avoid changing the file if nothing really changed.
16         if [ ! -z "$(metastore --compare)" ]; then
17                 metastore --save
18
19                 # stage the file as part of the current commit
20                 if [ "$VCS" = git ]; then
21                         git add .metadata
22                 fi
23                 # hg and bzr add not done, they will automatically
24                 # include the file in the current commit
25         fi
26 fi