[PATCH] merge-one-file: remove empty directories

Junio C Hamano junkio at cox.net
Sun Nov 20 15:14:37 EST 2005


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 at cox.net>

---
    Linus Torvalds <torvalds at osdl.org> writes:

    > [ Junio, Fredrik, you're cc'd because the "merge-one-file" logic doesn't 
    >   clean up empty directories after removing a file in merge ]

    Here is the one for merge-one-file that is used by 'git pull
    -s resolve'.  Next patch will be the merge-recursive one.

 git-merge-one-file.sh |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

applies-to: fbe4060a1b8ba894be5767ffc27402f94f356882
397c76697f898e0341699fba8ef783f3342329c7
diff --git a/git-merge-one-file.sh b/git-merge-one-file.sh
index b08597d..b285990 100755
--- a/git-merge-one-file.sh
+++ b/git-merge-one-file.sh
@@ -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"
 	;;
---
0.99.9.GIT




More information about the Linuxppc64-dev mailing list