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

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

From
Shawn Pearce <spearce@spearce.org>
Date
Feb 17, 2006, 15:16 UTC
Message-ID
<20060217151654.GA26362@spearce.org>
In-Reply-To
<7v7j7u8koz.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> wrote:
> I thought I said it would be a few-liner, but it appears I did
> not send that message.
You did.  Somehow I forgot that request.  I wrote a simple approach
similar to what you show below then tried to make it slightly
more efficient by only attempting to delete each directory once.
Obviously that wasn't wise on my part.  :-)
 
Show 18 quoted lines
> 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

I just ran it through the test script (t7101-reset.sh) that I included in my patch and it passed, so clearly the version above would be the better version to include.

Since it was untested before you are welcome to include the test script with your version. :-)

-- 
Shawn.
Previous: Junio C HamanoNext: Shawn Pearce
Message 3 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.