Prevent git from removing a directory when the last file in it has been removed,...
authorJoey Hess <joey@gnu.kitenet.net>
Sun, 25 Jan 2009 19:30:36 +0000 (14:30 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Sun, 25 Jan 2009 19:30:48 +0000 (14:30 -0500)
commit.d/40git-rm
debian/changelog

index d2c51c206a675cb000a7592918ea13ce8ef7bf8d..26f492aad553495d8904ac5b3c45ee46cfa212a9 100755 (executable)
@@ -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
index af9b501398226f6cebc71fcf7ed27241a004db47..968e1d79ac496f6bf4f321e82bc717f502dd1982 100644 (file)
@@ -1,8 +1,11 @@
-etckeeper (0.26) UNRELEASED; urgency=low
+etckeeper (0.26) unstable; urgency=low
 
   * Add Japanese debconf translation. Closes: #512869
+  * 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
 
- -- Joey Hess <joeyh@debian.org>  Sat, 24 Jan 2009 12:35:29 -0500
+ -- Joey Hess <joeyh@debian.org>  Sun, 25 Jan 2009 13:55:56 -0500
 
 etckeeper (0.25) unstable; urgency=low