summaryrefslogtreecommitdiff
path: root/commit.d
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-01-25 14:30:36 -0500
committerJoey Hess <joey@gnu.kitenet.net>2009-01-25 14:30:48 -0500
commit76dc563df1afffe55a516714577dafcfb09952bb (patch)
tree8e0ee2e244d49cfeba6d52b86b14a5f4e56261a4 /commit.d
parent29dea62419d8232f9243a3521aab3fdd603d78a0 (diff)
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
Diffstat (limited to 'commit.d')
-rwxr-xr-xcommit.d/40git-rm16
1 files changed, 15 insertions, 1 deletions
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