From 76dc563df1afffe55a516714577dafcfb09952bb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 25 Jan 2009 14:30:36 -0500 Subject: Prevent git from removing a directory when the last file in it has been removed, but the directory is left existing and empty, by touching a flag file before calling git rm. Closes: 513006 --- commit.d/40git-rm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'commit.d/40git-rm') diff --git a/commit.d/40git-rm b/commit.d/40git-rm index d2c51c2..26f492a 100755 --- a/commit.d/40git-rm +++ b/commit.d/40git-rm @@ -6,8 +6,22 @@ IFS=' if [ "$VCS" = git ] && [ -d .git ]; then for file in $(git ls-files --deleted); do - if [ ! -d "$file" ]; then + 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 -- cgit v1.2.3