All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Organov <sorganov@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Elijah Newren <newren@gmail.com>,  git@vger.kernel.org
Subject: Re: what should "git clean -n -f [-d] [-x] <pattern>" do?
Date: Thu, 25 Jan 2024 20:11:29 +0300	[thread overview]
Message-ID: <87il3h72ym.fsf@osv.gnss.ru> (raw)
In-Reply-To: <xmqqa5ouhckj.fsf@gitster.g> (Junio C. Hamano's message of "Wed, 24 Jan 2024 09:21:32 -0800")

Junio C Hamano <gitster@pobox.com> writes:

> Sergey Organov <sorganov@gmail.com> writes:
>
>> Whereas obsoleting second -f in favor of new --nested-repo might be a
>> good idea indeed, I believe it's still a mistake for "dry run" to
>> somehow interfere with -f, sorry.
>
> No need to be sorry ;-)
>
> I actually think the true culprit of making this an odd-man-out is
> that the use of "-f" in "git clean", especially with its use of the
> configuration variable clean.requireForce that defaults to true, is
> utterly non-standard.
>
> The usual pattern of defining what "-f" does is that the "git foo"
> command without any options does its common thing but refuses to
> perform undesirable operations (e.g. "git add ."  adds everything
> but refrains from adding ignored paths). And "git foo -f" is a way
> to also perform what it commonly skips.
>
> In contrast, with clean.requireForce that defaults to true, "git
> clean" does not do anything useful by default.  Without such a
> safety, "git clean" would be a way to clean expendable paths, and
> "git clean -f" might be to also clean precious paths.  But it does
> not work that way.  It always requires "-f" to do anything.  Worse
> yet, it is not even "by default it acts as if -n is given and -f is
> a way to countermand that implicit -n".  It is "you must give me
> either -f (i.e. please do work) or -n (i.e. please show what you
> would do) before I do anything".
>
>   $ git clean
>   fatal: clean.requireForce defaults to true and neither -i, -n, nor -f given; refusing to clean
>
> Given that, it is hard to argue that it would be a natural end-user
> expectation that the command does something useful (i.e. show what
> would be done) when it is given "-f" and "-n" at the same time.
> What makes this a rather nonsense UI is the fact that "-f" does not
> work the way we would expect for this command.

I think we all agree that current UI is a kind of nonsense, but have
different views of the optimal target interface. My points are as
following:

1. The fact that bare "git clean" only produces error by default is
probably a good thing, as removal of untracked files is unrecoverable
operation in Git domain, so requiring -f by default is probably a good
thing as well, provided the *only* operation that "git clean" performs
is dangerous enough.

2. The "-n" behavior is pure nonsense.

So, how do we fix (2)? Let's try mental experiment. Suppose there is no
"-n" option for "git clean" and we are going to implement it. We start
from:

  $ git clean
  fatal: clean.requireForce defaults to true and neither -i nor -f given; refusing to clean
  $ git clean -f
  removing "a"
  removing "b"
  $

Please notice that there is no "-n" in the error message as there is no
such option yet in our experiment.

Now we are going to introduce "dry run" option "-n". Most simple and
obvious way to do it is to set internal flag "dry_run" and then at every
invocation of "remove(file_name)" put an if(dry_run) that will just
print(file_name) instead or removing it. Let's suppose we did just that.
We get this behavior:

  $ git clean -n
  fatal: clean.requireForce defaults to true and neither -i nor -f given; refusing to clean
  $ git clean -f -n
  would remove "a"
  would remove "b"
  $ git clean -f -f -n
  would remove "a"
  would remove "b"
  would remove "sub/a"
  $

I see this as logical, clean, and straightforward behavior, meeting user
expectations for "dry run" option, so I suggest to do just that.

Thanks,
-- Sergey Organov.

  reply	other threads:[~2024-01-25 17:11 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-09 20:20 what should "git clean -n -f [-d] [-x] <pattern>" do? Junio C Hamano
2024-01-09 22:04 ` Sergey Organov
2024-01-19  2:07 ` Elijah Newren
2024-01-23 15:10   ` Sergey Organov
2024-01-23 18:34     ` Junio C Hamano
2024-01-24  8:23       ` Sergey Organov
2024-01-24 17:21         ` Junio C Hamano
2024-01-25 17:11           ` Sergey Organov [this message]
2024-01-25 17:46             ` Junio C Hamano
2024-01-25 20:27               ` Sergey Organov
2024-01-25 20:31                 ` Sergey Organov
2024-01-26  7:44                   ` Junio C Hamano
2024-01-26 12:09                     ` Sergey Organov
2024-01-27 10:00                       ` Junio C Hamano
2024-01-27 13:25                         ` Sergey Organov
2024-01-29 19:40                           ` Kristoffer Haugsbakk
2024-01-31 13:04                           ` Sergey Organov
2024-01-29  9:35                         ` Sergey Organov
2024-01-29 18:20                           ` Jeff King
2024-01-29 21:49                             ` Sergey Organov
2024-01-30  5:44                               ` Jeff King
2024-01-30  5:53                                 ` Junio C Hamano
2024-02-29 19:07 ` [PATCH] clean: improve -n and -f implementation and documentation Sergey Organov
2024-03-01 13:20   ` Jean-Noël Avila
2024-03-01 14:34     ` Sergey Organov
2024-03-01 15:29       ` Kristoffer Haugsbakk
2024-03-01 18:07         ` Junio C Hamano
2024-03-02 19:47       ` Jean-Noël AVILA
2024-03-02 20:09         ` Sergey Organov
2024-03-02 21:07           ` Junio C Hamano
2024-03-02 23:48             ` Sergey Organov
2024-03-03  9:54               ` Sergey Organov
2024-03-01 18:07     ` Junio C Hamano
2024-03-01 18:30       ` Junio C Hamano
2024-03-01 19:31       ` Sergey Organov
2024-03-02 16:31   ` Junio C Hamano
2024-03-02 19:59     ` Sergey Organov
2024-03-03  9:50   ` [PATCH v2] " Sergey Organov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87il3h72ym.fsf@osv.gnss.ru \
    --to=sorganov@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=newren@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.