git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Add a way to disable «git clean» per repo
@ 2023-04-01 20:50 Guillem Jover
  2023-04-03 17:36 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Guillem Jover @ 2023-04-01 20:50 UTC (permalink / raw)
  To: git

Hi!

[ I initially filed this in the Debian bug tracking system as it
  seemed to me that filing a feature request on a mailing list had
  a great potential to get lost. But I guess I can try anyway. :) ]

For repositories that are not tracking code, say when storing your ~/
under git, or to store say collections of data files such as photos,
texts or similar, you might end up using .gitignore to unclutter
«git status». The problem is that both ignored and non-ignored
untracked files can be “precious”, as in not version-tracked by losing
them might imply data loss.

Accidentally running «git clean -xdf» or «git clean -Xdf» might be
catastrophic there. But for the ~/ case (or any such tracking in a
parent of git trees, this is even worse, as an accidental «cd» too
much while in some code repo might end up accidentally recursively
running those «git clean» on an unexpected working tree and all of
its subdirectories (except for other git working trees).

I tend to be rather careful with this, but I recently had a scare
where this happened to me, and lost a few (not essential) files before
I noticed and Ctrl-C'd git. I then set out to try to disable git clean
on these situations, but I see no way to do that as aliases do not work
with built-ins, and adding a ~/bin/git wrapper to check for this seems
extremely cumbersome.

It would thus be nice if there was an option that could be set to
completely disable «git clean» on a repo. I guess it might make sense
to disable for any untracked file, or perhaps for ignored and/or
non-ignored. So that these kind of work trees could be protected.

Thanks,
Guillem

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

* Re: Add a way to disable «git clean» per repo
  2023-04-01 20:50 Add a way to disable «git clean» per repo Guillem Jover
@ 2023-04-03 17:36 ` Junio C Hamano
  2023-04-09 17:01   ` Guillem Jover
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2023-04-03 17:36 UTC (permalink / raw)
  To: Guillem Jover; +Cc: git

Guillem Jover <guillem@hadrons.org> writes:

> Accidentally running «git clean -xdf» or «git clean -Xdf» might be
> catastrophic there.

So would accidentally running "rm -fr" there be catastrophic, too.
I doubt it would make much sense to file a feature request to Debian
or GNU/FSF to disable "rm -r" in certain directories.  I am not sure
why "git clean" should be any different.

Commands like "git clean" require "-f" before they become overly
destructuve for a reason.  clean.requireForce defaults to true for
the same reason.

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

* Re: Add a way to disable «git clean» per repo
  2023-04-03 17:36 ` Junio C Hamano
@ 2023-04-09 17:01   ` Guillem Jover
  2023-04-10 13:32     ` Thomas Guyot
  0 siblings, 1 reply; 4+ messages in thread
From: Guillem Jover @ 2023-04-09 17:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Hi!

On Mon, 2023-04-03 at 10:36:25 -0700, Junio C Hamano wrote:
> Guillem Jover <guillem@hadrons.org> writes:
> > Accidentally running «git clean -xdf» or «git clean -Xdf» might be
> > catastrophic there.
> 
> So would accidentally running "rm -fr" there be catastrophic, too.

Sure.

> I doubt it would make much sense to file a feature request to Debian
> or GNU/FSF to disable "rm -r" in certain directories.  I am not sure
> why "git clean" should be any different.

Right, but I see a substantial difference though, «git clean» is
part of the git toolset to manage among other things specific work
trees, where that behavior is controlled through configuration, and
is as such confined within those specific realms, where also the
properties of what is being tracked might be different.
(With GNU coreutils rm you can confine it within one filesystem with
--one-file-system, but TBH I've never had the need to use it AFAIR,
and it's not enabled by default.)

> Commands like "git clean" require "-f" before they become overly
> destructuve for a reason.  clean.requireForce defaults to true for
> the same reason.

Right, I guess that's another reason for me why I see these («rm» vs
«git clean») as not being entirely comparable. Using «rm» requires in
most cases no force options, even when removing recursively (with -r),
while «git clean» by default will fail fatally (for all invocations
AFAICS?), so perhaps I'm holding it wrong, but when you end up invoking
a command very often (f.ex. to make sure your project is building from
a clean state), which requires using a force option (because passing -i
would become very cumbersome very quick), that becomes a habit or part
of your muscle-memory (perhaps a bad one), that means I tend to not pay
as much attention as I'd do when running «rm -rf» (also because of the
confinement I mentioned above).

For now it occurred to me that I could create dummy git repos in
parent directories to act as «git clean» barriers, so that it does not
propagate further up in the directory tree, but that still seems like
a hack, and I'd really like to protect specific work trees where I know
I never want to be able to run «git clean».

Thanks,
Guillem

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

* Re: Add a way to disable «git clean» per repo
  2023-04-09 17:01   ` Guillem Jover
@ 2023-04-10 13:32     ` Thomas Guyot
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Guyot @ 2023-04-10 13:32 UTC (permalink / raw)
  To: Guillem Jover, Junio C Hamano, git

On 2023-04-09 13:01, Guillem Jover wrote:
>> I doubt it would make much sense to file a feature request to Debian
>> or GNU/FSF to disable "rm -r" in certain directories.  I am not sure
>> why "git clean" should be any different.
> Right, but I see a substantial difference though, «git clean» is
> part of the git toolset to manage among other things specific work
> trees, where that behavior is controlled through configuration, and
> is as such confined within those specific realms, where also the
> properties of what is being tracked might be different.
> (With GNU coreutils rm you can confine it within one filesystem with
> --one-file-system, but TBH I've never had the need to use it AFAIR,
> and it's not enabled by default.)
>

Hi Guillem,

I agree with Junio here - there are many ways you could adapt your use 
of Git to safely manage these types of repos... for starters I don't 
like storing the .git directly in the folders I'm tracking, I always use 
separate repos with a script to compare the contents vs the real 
filesystem. Something like:


#!/bin/sh
diff -ur `hostname -s`/ / |grep -v "^Only in /"


In this example the repo tracks files from / on multiple hosts using 
hostname as the first component; diff won't descend into "new" dirs so 
this runs very fast too, and can be piped to diffstat to get a summary 
of changed files.


Also if you fear accidentally recalling a dangerous clean command from 
history, you can set HISTCONTROL=ignoreboth then prefix any dangerous 
command with a space, or use HISTIGNORE to selectively ignore got clean 
commands. That works with other dangerous commands like sudo reboot, rm 
-rf, etc...


The HISTCONTROL way is even better imho as I would always save/recall 
the command with -n appended (no-op) to review what would be done (ex 
sometimes there could be a virtualenv in the way that I forgot to remove 
from ignores) and only when I'm happy I'd remove the -n and insert a 
space in front so the command doesn't get saved.

Regards,

-- 
Thomas

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

end of thread, other threads:[~2023-04-10 13:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-01 20:50 Add a way to disable «git clean» per repo Guillem Jover
2023-04-03 17:36 ` Junio C Hamano
2023-04-09 17:01   ` Guillem Jover
2023-04-10 13:32     ` Thomas Guyot

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).