merge-one-file: remove empty directories
authorJunio C Hamano <junkio@cox.net>
Sun, 20 Nov 2005 03:50:44 +0000 (19:50 -0800)
committerJunio C Hamano <junkio@cox.net>
Sun, 20 Nov 2005 03:50:44 +0000 (19:50 -0800)
When the last file in a directory is removed as the result of a
merge, try to rmdir the now-empty directory.

[jc: We probably could use "rmdir -p", but for now we do that by
hand for portability.]

Signed-off-by: Junio C Hamano <junkio@cox.net>
git-merge-one-file.sh

index b08597de29afc6bc1aaddf7b817bc122cd517b04..b285990fb24f8a2a3dc96e27af67b6afbac024c7 100755 (executable)
@@ -25,7 +25,12 @@ case "${1:-.}${2:-.}${3:-.}" in
                echo "Removing $4"
        fi
        if test -f "$4"; then
-               rm -f -- "$4"
+               rm -f -- "$4" &&
+               dn="$4" &&
+               while dn=$(expr "$dn" : '\(.*\)/') && rmdir "$dn" 2>/dev/null
+               do
+                       :;
+               done
        fi &&
                exec git-update-index --remove -- "$4"
        ;;