git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Elijah Newren <newren@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] rebase, cherry-pick, revert: only run from toplevel
Date: Wed, 1 Sep 2021 02:30:42 -0400	[thread overview]
Message-ID: <YS8eEtwQvF7TaLCb@coredump.intra.peff.net> (raw)
In-Reply-To: <CABPp-BFET9PhgAh+xvMWzTGD+pW3ujOUXO6JOF1rtFMMpDHZvg@mail.gmail.com>

On Tue, Aug 31, 2021 at 11:08:35PM -0700, Elijah Newren wrote:

> On Tue, Aug 31, 2021 at 10:29 PM Junio C Hamano <gitster@pobox.com> wrote:
> >
> > Elijah Newren <newren@gmail.com> writes:
> >
> > > Ooh, this sounds intriguing to me...but what if we changed that rule
> > > slightly and just decided to never make the cwd go away?  Currently,
> > > the checkout code removes directories if they have no tracked or
> > > untracked or ignored files left, i.e. if they're empty.  What if we
> > > decide to only have remove_scheduled_dirs() remove directories that
> > > are empty AND they are not the current working directory?
> >
> > Is that generally doable?  What would we do when the directory the
> > subcommand was started from (or one of its parent directories) is
> > not just missing but has to be a file in the revision the subcommand
> > is trying to checkout?
> 
> The same problem (an untracked directory is in the way) already exists
> and has to be handled by all relevant subcommands, right?
> 
> In particular, if the current working directory only has untracked
> files in it, then the directory cannot be removed.  That will prevent
> us from checking out the revision we want, so we have to throw an
> error.
> 
> So my idea just piggy backs on that, resulting in the same error also
> being shown when the current working directory has 0 untracked files
> within it.
> 
> Since the whole thread started from, "maybe we should throw an error
> instead of continuing if it would result in the current working
> directory getting deleted", I believe this idea does exactly what we
> were looking for...and nicely tailors the new error cases to precisely
> the situations we wanted them for -- when the current working
> directory would have been removed by the old code.

Yeah, this is definitely what I had in mind for my original suggestion:
extending the "do not delete directory if it contains an untracked file"
rule to the cwd. I guess I was thinking of it as an error, but it really
_isn't_ an error in most cases, as long as we don't need to recreate
another entry there (and if we do, then as you say, the existing error
paths should handle it).

It does leave crufty directories behind in the working tree that Git
would not then delete (because it only cleans up directories after it
removes their contents, and there are no contents left to remove).
That's probably not a big deal, though. If you are moving around history
with things like rebase or bisect, you'd likely move back to a working
tree with the directory anyway. And it's not like you can't end up with
such directories through other means (and "git clean -d" takes care of
them).

So I do like the approach.

-Peff

PS I'm assuming this is all taking the cwd of the process based on the
   original "prefix" (since Git processes generally move up to the
   top-level of the working tree). But that still leaves the problem for
   _other_ processes. E.g., if I am working in two terminals, one could
   be in "subdir/" and I could issue a bisect or rebase command from the
   other at the top-level, which would put one of them into the
   confusing state. You could strengthen the rule to "is _any_ process
   using this as a cwd", but it's hard to do so portably. And I know
   I've been annoyed by similar such safety valves before ("why can't I
   delete this? Argh, some process I don't care about is squatting on
   it").

  reply	other threads:[~2021-09-01  6:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-31  3:03 [PATCH] rebase, cherry-pick, revert: only run from toplevel Elijah Newren via GitGitGadget
2021-08-31  3:05 ` Elijah Newren
2021-08-31  5:55 ` Johannes Sixt
2021-08-31  7:01 ` Jeff King
2021-08-31 20:14   ` Elijah Newren
2021-09-01  2:55     ` Taylor Blau
2021-09-01  4:43       ` Elijah Newren
2021-09-01  4:59         ` Taylor Blau
2021-09-01  6:48           ` Elijah Newren
2021-09-01  5:29     ` Junio C Hamano
2021-09-01  6:08       ` Elijah Newren
2021-09-01  6:30         ` Jeff King [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-11-26  7:31 Leon Dingman

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=YS8eEtwQvF7TaLCb@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --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.
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).