Re: [Bug] Rebase from worktree subdir is broken (was Re: [PATCH v5 07/11] rebase: do not attempt to remove startup_info->original_cwd)

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

 



On Tue, Jan 25, 2022 at 6:59 PM Elijah Newren <newren@xxxxxxxxx> wrote:
> On Tue, Jan 25, 2022 at 12:27 PM Glen Choo <chooglen@xxxxxxxxxx> wrote:
> > This commit (which is already in master) introduces a bug that breaks
> > rebase when rebasing inside a subdirectory of a worktree. You can see
> > that the below test fails with:
>
> There's nothing wrong with running checkout from a subdirectory.  It
> is unfortunate that setup.c auto-discovers both the git directory and
> the working tree, but sets GIT_DIR without setting GIT_WORK_TREE in
> the case of a non-main worktree; it's not particularly friendly for
> subcommands.  Of course, it's also unfortunate that sequencer still
> forks subprocesses other than those requested by a user with e.g.
> --exec.
>
> But, anyway, I've got a patch that I'll send as soon as it passes CI
> (https://github.com/git/git/pull/1205).
>
> > +test_expect_success 'rebase when inside worktree subdirectory' '
> > +       git init main-wt &&
> > +       (
> > +               cd main-wt &&
> > +               git commit --allow-empty -m "initial" &&
> > +               # create commit with foo/bar/baz
> > +               mkdir -p foo/bar &&
> > +               touch foo/bar/baz &&
> > +               git add foo/bar/baz &&
> > +               git commit -m "add foo/bar/baz" &&
> > +               # create commit with a/b/c
> > +               mkdir -p a/b &&
> > +               touch a/b/c &&
> > +               git add a/b/c &&
> > +               git commit -m "add a/b/c" &&
> > +               # create another branch for our other worktree
> > +               git branch other &&
> > +               git worktree add ../other-wt other &&
> > +               (
> > +                       cd ../other-wt &&
> > +                       mkdir -p random/dir &&
> > +                       (
> > +                               cd random/dir &&
> > +                               git rebase --onto HEAD^^ HEAD^  # drops the HEAD^ commit
> > +                       )
> > +               )
> > +       )
> > +'

This is entirely minor, but all the inner subshells in this test are
superfluous. The outermost (...) will ensure that the working
directory is restored regardless of whether anything within its body
fails, no matter how much you `cd` around. Thus, all the inner
subshells could be dropped.

An alternative would be to close the outermost subshell immediately
after `git worktree add`:

    git init main-wt &&
    (
        cd main-wt &&
        ...
        git worktree add ../other-wt other
    ) &&
    mkdir -p other-wt/random/dir &&
    (
        cd other-wt/random/dir &&
        ...
    )

however, that may not buy you any clarity.



[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