Re: what should "git clean -n -f [-d] [-x] <pattern>" do?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jan 27, 2024, at 14:25, Sergey Organov wrote:
> Junio C Hamano <gitster@xxxxxxxxx> writes:
>
>> Sergey Organov <sorganov@xxxxxxxxx> writes:

I agree with Sergey.

Let’s suppose I’ve never used git-clean(1) (and I almost never use
it). I read the man page to find out what it’s about. Oh, it removes
files that I haven’t tracked. That sounds dangerous. But I see under
`-n, --dry-run` that I can simulate what it would do:

   “ Don’t actually remove anything, just show what would be done.

Great, this is what I want. So this seems to mean to run `git clean` and
just tell me what would happen. But now I’ve already read that it
requires `--force` in order to do anything. Which means that I don’t
want to just run:

```
git clean --dry-run
```

Since I presume that would give me the “no `--force` provided”
error. Which means that I want to tack on `--force`:

```
git clean --dry-run --force
```

Now I figure that this will run `git clean --force` but switch real
deletion with printing the filenames.[1]

Junio wrote:

> What I find broken is that giving one 'f' and one 'n' in different
> order, i.e. "-f -n" and "-n -f", does not do what I expect.  If you
> are choosing between do-it (f) and do-not-do-it (n), you ought to be
> able to rely on the usual last-one-wins rule.  That I find broken.

Now suppose I have noticed that some git(1) commands have these
`--[no-]do-it` options. I know that I can leverage this to override a
previous option. And that is useful when I for example have an alias
with `--do-it` but for this invocation I want `--no-do-it`. I read about
`--force` here but see that there is no `--no-force`. I then assume that
the only things that have to do with `--force` or not is that option and
the `requireForce` configuration variable.

I’ve also seen `--force` in other git(1) commands. And they usually are
about some specific scenario rather than the whole command itself, since
e.g. committing one too many times doesn’t really hurt. But I understand
how `--force` applies to all the useful work that git-clean(1) does
because all the useful work is also destructive work. So this is what I
expect from these options in general:

1. `--force`: require for the subset of actions that are potentially
   dangerous or may be unwanted in some way
2. `--dry-run`: simulate the action (specifically print everything that
   would happen but don’t do anything to `.git`, to untracked files, or
   anything else)

And I expect these two to be orthogonal. Because I might want—if the
option is there—to simulate some `--force` (e.g. `git push --force`)
with a `--dry-run`. As in: what would be printed? I wouldn’t expect
`--force` to override `--dry-run`.

† 1: I’m never this careful in real life. But this is about deleting
   files without any (from Git) recovery so I guess some prudence is
   required in this case.

-- 
Kristoffer Haugsbakk





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux