git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [Feature request] Add -u option to git rm to delete untracked files
@ 2020-05-26 21:21 Erik Janssen
  2020-05-27  7:34 ` Jeff King
  2020-05-27 12:44 ` Đoàn Trần Công Danh
  0 siblings, 2 replies; 5+ messages in thread
From: Erik Janssen @ 2020-05-26 21:21 UTC (permalink / raw)
  To: git

Hello All,


Would it be feasible to add a -u option to git rm to specify that I also want a file deleted if it is not tracked by git?
Currently, git rm -f can remove files in whatever state it seems, except when it is untracked. 
By allowing a -u option (-u: also delete untracked files) I would be sure that the file is gone while it would also make sure that it doesn't break past behaviour where people perhaps rely on git rm to leave untracked files alone.


Kind regards,


Erik Janssen.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Feature request] Add -u option to git rm to delete untracked files
  2020-05-26 21:21 [Feature request] Add -u option to git rm to delete untracked files Erik Janssen
@ 2020-05-27  7:34 ` Jeff King
  2020-05-27 12:44 ` Đoàn Trần Công Danh
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff King @ 2020-05-27  7:34 UTC (permalink / raw)
  To: Erik Janssen; +Cc: git

On Tue, May 26, 2020 at 11:21:23PM +0200, Erik Janssen wrote:

> Would it be feasible to add a -u option to git rm to specify that I
> also want a file deleted if it is not tracked by git?

It might be a little tricky, as I suspect the code is starting from the
set of tracked files, and then applying the arguments of pathspecs (but
I didn't look too carefully, so I might be wrong).

The "git clean" command is made for this (and starts by iterating over
the filesystem), and does exactly what you want. But I guess you are
hoping for a state where you can just run "git rm" without having to
think about whether the file is tracked or not.

-Peff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Feature request] Add -u option to git rm to delete untracked files
  2020-05-26 21:21 [Feature request] Add -u option to git rm to delete untracked files Erik Janssen
  2020-05-27  7:34 ` Jeff King
@ 2020-05-27 12:44 ` Đoàn Trần Công Danh
  2020-05-27 14:29   ` Randall S. Becker
  1 sibling, 1 reply; 5+ messages in thread
From: Đoàn Trần Công Danh @ 2020-05-27 12:44 UTC (permalink / raw)
  To: Erik Janssen; +Cc: git

On 2020-05-26 23:21:23+0200, Erik Janssen <eaw.janssen@chello.nl> wrote:
> Would it be feasible to add a -u option to git rm to specify that
> I also want a file deleted if it is not tracked by git?
> Currently, git rm -f can remove files in whatever state it seems,
> except when it is untracked. 
> By allowing a -u option (-u: also delete untracked files) I would be
> sure that the file is gone while it would also make sure that it
> doesn't break past behaviour where people perhaps rely on git rm to
> leave untracked files alone.

I _think_ remove untracked file is pretty much risky operation,
and it should be done separately/independently (via git-clean(1)).

Let's assume we have -u|--untracked,
nothing (probably) can stop our users from:

	git rm -u src
	git rm -u .

Even git-clean(1) requires either --force or --interactive
because it's too much risky to begin with.

If we think Git as a FileSystem, its rm should only care about its
tracked file. I prefer to just rm(1) instead of "git-rm -u".

-- 
Danh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [Feature request] Add -u option to git rm to delete untracked files
  2020-05-27 12:44 ` Đoàn Trần Công Danh
@ 2020-05-27 14:29   ` Randall S. Becker
  2020-05-27 19:31     ` Erik Janssen
  0 siblings, 1 reply; 5+ messages in thread
From: Randall S. Becker @ 2020-05-27 14:29 UTC (permalink / raw)
  To: 'Đoàn Trần Công Danh',
	'Erik Janssen'
  Cc: git

On May 27, 2020 8:45 AM, Ðoàn Tr?n Công Danh wrote:
> To: Erik Janssen <eaw.janssen@chello.nl>
> Cc: git@vger.kernel.org
> Subject: Re: [Feature request] Add -u option to git rm to delete untracked
> files
> 
> On 2020-05-26 23:21:23+0200, Erik Janssen <eaw.janssen@chello.nl> wrote:
> > Would it be feasible to add a -u option to git rm to specify that I
> > also want a file deleted if it is not tracked by git?
> > Currently, git rm -f can remove files in whatever state it seems,
> > except when it is untracked.
> > By allowing a -u option (-u: also delete untracked files) I would be
> > sure that the file is gone while it would also make sure that it
> > doesn't break past behaviour where people perhaps rely on git rm to
> > leave untracked files alone.
> 
> I _think_ remove untracked file is pretty much risky operation, and it should
> be done separately/independently (via git-clean(1)).

A git alias could easily be set up to do this, of course dangerous because of what git-clean does without any arguments:

    git config --global alias.rmu 'clean -f --'

> Let's assume we have -u|--untracked,
> nothing (probably) can stop our users from:
> 
> 	git rm -u src
> 	git rm -u .
> 
> Even git-clean(1) requires either --force or --interactive because it's too
> much risky to begin with.
> 
> If we think Git as a FileSystem, its rm should only care about its tracked file. I
> prefer to just rm(1) instead of "git-rm -u".


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [Feature request] Add -u option to git rm to delete untracked files
  2020-05-27 14:29   ` Randall S. Becker
@ 2020-05-27 19:31     ` Erik Janssen
  0 siblings, 0 replies; 5+ messages in thread
From: Erik Janssen @ 2020-05-27 19:31 UTC (permalink / raw)
  To: git; +Cc: Randall S. Becker, Đoàn Trần Công Danh

Hello All,

Thanks for the responses!
I was not aware of the alias option, but it gave me the following idea that seems to work:
git config --global alias.rmclean '!git rm -r -f $1; git clean -f $1'

A dir with a untracked file 'file1' will give:
git rmclean file1
fatal: pathspec 'file1' did not match any files
Removing file1
but effectively the file is gone.

A dir with a tracked file 'file2' will give:
git rmclean file2
rm 'file2'

alternatively, ignore the errors:
git config --global alias.rmclean '!git rm -r -f $1 2>/dev/null; git clean -f $1 2>/dev/null'

some setup as above, untracked file1, tracked file2 in one go:
git rmclean .

gives:
rm 'file2'
Removing file1

So I think I solved my own question :-)

Kind regards,
Erik.


> Op 27 mei 2020 om 16:29 schreef "Randall S. Becker" <rsbecker@nexbridge.com>:
> 
> 
> On May 27, 2020 8:45 AM, Ðoàn Tr?n Công Danh wrote:
> > To: Erik Janssen <eaw.janssen@chello.nl>
> > Cc: git@vger.kernel.org
> > Subject: Re: [Feature request] Add -u option to git rm to delete untracked
> > files
> > 
> > On 2020-05-26 23:21:23+0200, Erik Janssen <eaw.janssen@chello.nl> wrote:
> > > Would it be feasible to add a -u option to git rm to specify that I
> > > also want a file deleted if it is not tracked by git?
> > > Currently, git rm -f can remove files in whatever state it seems,
> > > except when it is untracked.
> > > By allowing a -u option (-u: also delete untracked files) I would be
> > > sure that the file is gone while it would also make sure that it
> > > doesn't break past behaviour where people perhaps rely on git rm to
> > > leave untracked files alone.
> > 
> > I _think_ remove untracked file is pretty much risky operation, and it should
> > be done separately/independently (via git-clean(1)).
> 
> A git alias could easily be set up to do this, of course dangerous because of what git-clean does without any arguments:
> 
>     git config --global alias.rmu 'clean -f --'
> 
> > Let's assume we have -u|--untracked,
> > nothing (probably) can stop our users from:
> > 
> > 	git rm -u src
> > 	git rm -u .
> > 
> > Even git-clean(1) requires either --force or --interactive because it's too
> > much risky to begin with.
> > 
> > If we think Git as a FileSystem, its rm should only care about its tracked file. I
> > prefer to just rm(1) instead of "git-rm -u".
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-27 19:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26 21:21 [Feature request] Add -u option to git rm to delete untracked files Erik Janssen
2020-05-27  7:34 ` Jeff King
2020-05-27 12:44 ` Đoàn Trần Công Danh
2020-05-27 14:29   ` Randall S. Becker
2020-05-27 19:31     ` Erik Janssen

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).