summaryrefslogtreecommitdiff
path: root/commit.d/40git-rm
blob: 26f492aad553495d8904ac5b3c45ee46cfa212a9 (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

IFS='
'

if [ "$VCS" = git ] && [ -d .git ]; then
	for file in $(git ls-files --deleted); do
		if [ ! -d "$file" ]; then
			# git removes directories when the last file
			# in them is removed, but empty directories
			# may be significant in /etc. Touch a flag file
			# to prevent git from removing the directory.
			dir="$(dirname "$file")"
			flagfile=""
			if [ -d "$dir" ] && 
			   [ -n "$(find "$dir" -maxdepth 0 -empty)" ]; then
				flagfile="$dir/.etckeeper-keep-empty"
				touch "$flagfile"
			fi
			git rm --quiet "$file"
			if [ -n "$flagfile" ]; then
				rm -f "$flagfile"
			fi
		fi
	done
fi