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

Re: [PATCH] Make git-reset delete empty directories

From
Junio C Hamano <junkio@cox.net>
Date
Feb 17, 2006, 08:15 UTC
Message-ID
<7v7j7u8koz.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20060217072616.GA15358@spearce.org>
Shawn Pearce <spearce@spearce.org> writes:
> When git-reset --hard is used and a subdirectory becomes
> empty (as it contains no tracked files in the target tree)
> the empty subdirectory should be removed.

I thought I said it would be a few-liner, but it appears I did not send that message.

This untested one is far simpler, if less efficient, isn't it?
---
diff --git a/git-reset.sh b/git-reset.sh
index fe53fc8..195d043 100755
--- a/git-reset.sh
+++ b/git-reset.sh
@@ -88,6 +88,9 @@ case "$reset_type" in
 				# it is ok if this fails -- it may already
 				# have been culled by checkout-index.
 				unlink $_;
+				while (s|/[^/]*$|| && $_ ne "") {
+					rmdir($_) or last;
+				}
 			}
 		}
 	' $tmp-exists
Previous: Shawn PearceNext: Shawn Pearce
Message 2 of 4 in “Make git-reset delete empty directories”
  1. Make git-reset delete empty directoriesShawn Pearce, Feb 17, 2006
  2. Junio C HamanoFeb 17, 2006
  3. Shawn PearceFeb 17, 2006
  4. Shawn PearceFeb 17, 2006

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.