summaryrefslogtreecommitdiff
path: root/pre-commit.d/20store-empty-directory
blob: 0cab9dff266c78eb77ec7bc3a118b56a1844a426 (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
#!/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