git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <junkio@cox.net>
Date
Nov 20, 2005, 04:14 UTC
Message-ID
<7v4q683qhe.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0511190957320.13959@g5.osdl.org>

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>
---
    Linus Torvalds <torvalds@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
Previous: Linus TorvaldsNext: Linus Torvalds
Message 2 of 8 in “Re: please pull powerpc-merge.git”
  1. Linus TorvaldsNov 19, 2005
  2. merge-one-file: remove empty directoriesJunio C Hamano, Nov 20, 2005
  3. Linus TorvaldsNov 20, 2005
  4. H. Peter AnvinNov 20, 2005
  5. Alex RiesenNov 21, 2005
  6. Johannes SchindelinNov 21, 2005
  7. merge-recursive::removeFile: remove empty directoriesJunio C Hamano, Nov 20, 2005
  8. Fredrik KuivinenNov 20, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.