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

Re: [PATCH] git clean: Don't automatically remove directories when run within subdirectory

From
Shawn Bohrer <shawn.bohrer@gmail.com>
Date
Apr 15, 2008, 14:26 UTC
Message-ID
<20080415142601.GB10548@mediacenter>
In-Reply-To
<48044C33.20006@broadpark.no>
On Tue, Apr 15, 2008 at 08:33:23AM +0200, Joachim Berdal Haga wrote:
Show 30 quoted lines
> Shawn Bohrer wrote:
> > On Mon, Apr 14, 2008 at 08:18:13PM +0200, Joachim Berdal Haga wrote:
> >> I think that the best option would be to never remove a directory, even if
> >> given explicitly, unless -d is given. Because my gut feeling is that when a
> >> directory name is specified, it is most often meant as "clean inside the
> >> given directory", ie. as a path delimiter.
> > 
> > If there are no tracked files the only difference between the dir/ and
> > dir case is that the former will leave behind an empty directory.  So
> > the difference between too much and too little is of little importance.
> 
> No, check this out; note that only in the very last case dir/subdir/subfile
> would be removed.
> 
> $ git init; mkdir -p dir/subdir; touch dir/file dir/subdir/subfile
> Initialized empty Git repository in .git/
> $ touch dir/tracked-file; git add dir/tracked-file
> $ ~/src/git/git-clean -n dir/
> Would remove dir/file
> Would not remove dir/subdir/
> $ ~/src/git/git-clean -n dir
> Would remove dir/file
> Would not remove dir/subdir/
> $ git rm -f dir/tracked-file
> rm 'dir/tracked-file'
> $ ~/src/git/git-clean -n dir/
> Would remove dir/file
> Would not remove dir/subdir/
> $ ~/src/git/git-clean -n dir
> Would remove dir/

Ah of course, this is the behavior with my patch. Before it would have removed everything which is the same bug you initially reported :)

Show 11 quoted lines
> > However,
> > 
> > git clean dir
> > Would not remove dir/
> > 
> > is a little strange.
> 
> Yes, although it could be made less strange by adding a short explanation,
> like "Would not remove dir/ (-d not given)". But I also think that the
> difference between "dir" and "dir/" is very (too?) subtle in this case and
> therefore should require explicit approval/action from the user.

Yeah, I don't know how I feel about this. I do think that the behavior with my current patch is technically correct, but you may be right that a trailing slash is subtle. In most cases I use my shell's tab completion witch adds the trailing slash, and only remove it when needed. Additionally, I could argue that by default we require explicit action to clean files by requiring -n or -f so hopefully users try -n first (I do).

-- Shawn

Previous: Joachim Berdal HagaNext: Joachim Berdal Haga
Message 12 of 14 in “git clean removes directories when not asked to”
  1. Joachim B HagaApr 8, 2008
  2. Joachim B HagaApr 8, 2008
  3. Re: git clean removes directories when not asked toJoachim B Haga, Apr 9, 2008
  4. git clean: Don't automatically remove directories when run within subdirectoryShawn Bohrer, Apr 13, 2008
  5. git clean: Add test to verify directories aren't removed with a prefixShawn Bohrer, Apr 13, 2008
  6. Joachim Berdal HagaApr 14, 2008
  7. Junio C HamanoApr 14, 2008
  8. Shawn BohrerApr 14, 2008
  9. Joachim Berdal HagaApr 14, 2008
  10. Shawn BohrerApr 15, 2008
  11. Joachim Berdal HagaApr 15, 2008
  12. Shawn BohrerApr 15, 2008
  13. Joachim Berdal HagaApr 15, 2008
  14. git clean: Don't automatically remove directories when run within subdirectoryShawn Bohrer, Apr 15, 2008

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.