summaryrefslogtreecommitdiff
path: root/pre-commit.d/20store-empty-directory
blob: a52a38387114f6871a22b683ed2b425eeed75acd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/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
		# stage the file as part of the current commit
		if [ "$VCS" = git ]; then
			git add .etckeeper
		fi
		# hg add not done, hg will automatically include the file
		# in the current commit
	else
		rm -f .etckeeper.new
	fi
fi