git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Elijah Newren <newren@gmail.com>
To: Jeff King <peff@peff.net>
Cc: 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: Tue, 31 Aug 2021 13:14:55 -0700	[thread overview]
Message-ID: <CABPp-BFmU+RaAjq4_0-PSfRgH1Jc63nN0fMuDWk2+iDbdz7CCA@mail.gmail.com> (raw)
In-Reply-To: <YS3Tv7UfNkF+adry@coredump.intra.peff.net>

On Tue, Aug 31, 2021 at 12:01 AM Jeff King <peff@peff.net> wrote:
>
> On Tue, Aug 31, 2021 at 03:03:50AM +0000, Elijah Newren via GitGitGadget wrote:
>
> > From: Elijah Newren <newren@gmail.com>
> >
> > Allowing rebase, cherry-pick and revert to run from subdirectories
> > inevitably leads to eventual user confusion.  For example, if they
> > are within a directory that was created by one of the patches being
> > rebased, then the rebase operation could hit a conflict before the
> > directory is restored leading the user to be running from a directory
> > that no longer exists.  Similarly with cherry-pick and revert, those
> > operations could result in the directory being removed.
> >
> > Similar to bisect, simply require that these commands be run from the
> > toplevel to avoid such problems.
>
> IMHO this is too draconian. You are occasionally helping people who are
> in a directory which goes away over the course of the operation. But you
> are hurting everyone who _isn't_ in that situation, and who needlessly
> has to re-issue their command after doing a "cd".
>
> I think we'd be much better served to do even a rudimentary analysis of
> whether the operation will be a problem. E.g., if we taught the checkout
> code to error out when the cwd is going to disappear, then:
>
>   - we'd protect the user from confusion during regular sight-seeing via
>     "git checkout v0.99" and so forth
>
>   - we'd protect the most common cases for git-rebase (your patches
>     introduce "subdir/", but it is not yet in the parent directory). We
>     wouldn't preemptively avoid a rebase where subdir/ disappears and
>     then reappears in the middle of the series. We could find such a
>     case by iterating over the patches, but IMHO it's not worth the
>     computation.
>
>   - we could likewise protect git-bisect, making it more reasonable to
>     loosen its current restriction
>
>   - we might want to teach similar logic to sequencer operations, so
>     that applying a patch would likewise error-out. That would protect
>     cherry-pick and revert, but also make the "subdir/ disappears
>     mid-patch-series" case pretty nice: the specific patch that deletes
>     it would fail to apply, and then you could "cd .. && git rebase
>     --continue".
>
>     I suspect that the "oops, we're going to delete cwd" code would end
>     up in unpack-trees anyway, which means that both checkout and all of
>     this sequencer operations would use the same code.

Well, sequencer uses the merge machinery, and merge-ort creates a
toplevel merge tree that includes conflict markers in files and
whatnot, and then only updates the working tree via checkout().  So,
yeah, it really should be the same codepath.

> Now I have spent zero time looking into actually coding this, so it may
> turn out to be much trickier than I am suggesting. But this seems like a
> much more fruitful direction, where we can protect users in cases where
> they benefit (and give them sensible and actionable error messages),
> without bothering people in the majority of cases where their cwd
> doesn't go away.

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?

Granted, that could leave a directory in the way of files from other
revisions, but the same was already true in the analogous situation
where there were leftover untracked files in some directory.  Since
all our code paths already have to handle directories leftover due to
untracked files, perhaps avoiding removing the current working
directory would just automatically work for us?  (I think it'd handle
all of checkout, bisect, rebase, cherry-pick, revert, and merge.)

  reply	other threads:[~2021-08-31 20:15 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 [this message]
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
  -- 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=CABPp-BFmU+RaAjq4_0-PSfRgH1Jc63nN0fMuDWk2+iDbdz7CCA@mail.gmail.com \
    --to=newren@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=peff@peff.net \
    /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).