threads / discuss / 62336

git rebase exec make -C in worktree confuses repo root dir

Subject: git rebase exec make -C in worktree confuses repo root dir

## tl;dr

11 messages between Oct 14, 2024 and Nov 5, 2024.

replies: 10people: 5as markdown or json

David Moberg· Oct 14, 2024, 20:46 UTC · lore

Hi, I tried to minimize this but I haven't been able to come to a much smaller example.

/David "kaddkaka" Moberg
What did you do before the bug happened? (Steps to reproduce your issue)

When doing `git rebase --exec` in a "secondary" worktree, it seems that there is confusion about where the repo root dir is. This sequence of commands can be run to reproduce:

  mktemp -d /tmp/git_bugreport_rebase_exec_worktree_root.XXXXXX
  cd /tmp/git_bugreport_rebase_exec_worktree_root.*
  mkdir repo
  cd repo/
  mkdir dir
  echo -e 'lint:' > dir/Makefile
  echo -e '\tgit rev-parse --show-toplevel' >> dir/Makefile
  echo -e '\tgit grep "banana" -- "$$BANANA"' >> dir/Makefile
  git init
  git add dir
  git commit -m"Intial commit"
  git worktree add ../repo2
  cd ../repo2/
  BANANA=$PWD GIT_EDITOR='sed -i "1s/noop/exec make -C dir\/ lint/"'
git rebase -i HEAD
What did you expect to happen? (Expected behavior)
1. This command should return the worktree toplevel, not a subdirectory
  $ git rev-parse --show-toplevel
  /tmp/tmp.DUUAVQCIKe/repo2
2. And the git grep command should return the match from dir/Makefile,
not Fatal Error
  $ git grep banana
  Makefile:       git grep "banana" -- "$$BANANA"
What happened instead? (Actual behavior)
1. --show-toplevel reports a subdirectory instead of toplevel:
  $ git rev-parse --show-toplevel
  /tmp/tmp.DUUAVQCIKe/repo2/dir
2. git grep complains that the pathspec is outside the repository with
fatal error:
  $ git grep "banana" -- "$BANANA"
  fatal: /tmp/tmp.DUUAVQCIKe/repo2: '/tmp/tmp.DUUAVQCIKe/repo2' is
outside repository at '/tmp/tmp.DUUAVQCIKe/repo2/dir'
  make: *** [Makefile:3: lint] Error 128
  make: Leaving directory '/tmp/tmp.DUUAVQCIKe/repo2/dir'
  warning: execution failed: make -C dir/ lint
What's different between what you expected and what actually happened?
See above.

[System Info] git version: git version 2.43.0 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64 compiler info: gnuc: 13.2 libc info: glibc: 2.39 $SHELL (typically, interactive shell): /usr/bin/bash

[Enabled Hooks]
Taylor Blau· Oct 14, 2024, 21:19 UTC · re: David Moberg · lore

Re: git rebase exec make -C in worktree confuses repo root dir

On Mon, Oct 14, 2024 at 10:46:45PM +0200, David Moberg wrote:
Show 10 quoted lines
> What did you expect to happen? (Expected behavior)
>
> 1. This command should return the worktree toplevel, not a subdirectory
>   $ git rev-parse --show-toplevel
>   /tmp/tmp.DUUAVQCIKe/repo2
>
> 2. And the git grep command should return the match from dir/Makefile,
> not Fatal Error
>   $ git grep banana
>   Makefile:       git grep "banana" -- "$$BANANA"

I am not sure if this is expected behavior or not, but it feels unintentional to me. Perhaps I am missing something funky in your example that is causing it to behave this way.

Does this bisect to anything interesting, or has it always behaved this way?

Thanks, Taylor

David Moberg· Oct 14, 2024, 21:34 UTC · re: Taylor Blau · lore

Re: git rebase exec make -C in worktree confuses repo root dir

I am not sure if this has worked previously. Where/how far back should I look? Is 2 samples from 6 months and 1 year prior reasonable and enough?

I'm not sure if I understand you, What is the behavior you expect? Are you able to reproduce the behavior?

/David
Den mån 14 okt. 2024 kl 23:19 skrev Taylor Blau <me@ttaylorr.com>:
Show 22 quoted lines
>
> On Mon, Oct 14, 2024 at 10:46:45PM +0200, David Moberg wrote:
> > What did you expect to happen? (Expected behavior)
> >
> > 1. This command should return the worktree toplevel, not a subdirectory
> >   $ git rev-parse --show-toplevel
> >   /tmp/tmp.DUUAVQCIKe/repo2
> >
> > 2. And the git grep command should return the match from dir/Makefile,
> > not Fatal Error
> >   $ git grep banana
> >   Makefile:       git grep "banana" -- "$$BANANA"
>
> I am not sure if this is expected behavior or not, but it feels
> unintentional to me. Perhaps I am missing something funky in your
> example that is causing it to behave this way.
>
> Does this bisect to anything interesting, or has it always behaved this
> way?
>
> Thanks,
> Taylor
Eric Sunshine· Oct 15, 2024, 07:11 UTC · re: Taylor Blau · lore

Re: git rebase exec make -C in worktree confuses repo root dir

On Mon, Oct 14, 2024 at 5:19 PM Taylor Blau <me@ttaylorr.com> wrote:
Show 13 quoted lines
> On Mon, Oct 14, 2024 at 10:46:45PM +0200, David Moberg wrote:
> > 1. This command should return the worktree toplevel, not a subdirectory
> >   $ git rev-parse --show-toplevel
> >   /tmp/tmp.DUUAVQCIKe/repo2
> >
> > 2. And the git grep command should return the match from dir/Makefile,
> > not Fatal Error
> >   $ git grep banana
> >   Makefile:       git grep "banana" -- "$$BANANA"
>
> I am not sure if this is expected behavior or not, but it feels
> unintentional to me. Perhaps I am missing something funky in your
> example that is causing it to behave this way.

This looks like unintentional behavior; probably a bug. It seems to be triggered by `git rebase -i` setting GIT_DIR. Here's an even simpler reproduction recipe:

    % git init foo
    % cd foo
    % mkdir dir
    % echo foo >dir/file
    % git add dir/file
    % git commit -m foo
    % git worktree add ../bar
    % cd ../bar
    % git -C dir rev-parse --show-toplevel
    /.../bar
    % GIT_DIR=../../foo/.git/worktrees/bar \
        git -C dir rev-parse --show-toplevel
    /.../bar/dir

The `git rev-parse --show-toplevel` invocation with GIT_DIR set is incorrectly returning `/.../bar/dir` rather than `/.../bar`.

David Moberg· Oct 15, 2024, 18:55 UTC · re: Eric Sunshine · lore

Re: git rebase exec make -C in worktree confuses repo root dir

Thanks, that is indeed a much smaller example and it seems to exhibit the same issue. Can we figure out how to fix it?

Den tis 15 okt. 2024 kl 09:11 skrev Eric Sunshine <sunshine@sunshineco.com>:
Show 36 quoted lines
>
> On Mon, Oct 14, 2024 at 5:19 PM Taylor Blau <me@ttaylorr.com> wrote:
> > On Mon, Oct 14, 2024 at 10:46:45PM +0200, David Moberg wrote:
> > > 1. This command should return the worktree toplevel, not a subdirectory
> > >   $ git rev-parse --show-toplevel
> > >   /tmp/tmp.DUUAVQCIKe/repo2
> > >
> > > 2. And the git grep command should return the match from dir/Makefile,
> > > not Fatal Error
> > >   $ git grep banana
> > >   Makefile:       git grep "banana" -- "$$BANANA"
> >
> > I am not sure if this is expected behavior or not, but it feels
> > unintentional to me. Perhaps I am missing something funky in your
> > example that is causing it to behave this way.
>
> This looks like unintentional behavior; probably a bug. It seems to be
> triggered by `git rebase -i` setting GIT_DIR. Here's an even simpler
> reproduction recipe:
>
>     % git init foo
>     % cd foo
>     % mkdir dir
>     % echo foo >dir/file
>     % git add dir/file
>     % git commit -m foo
>     % git worktree add ../bar
>     % cd ../bar
>     % git -C dir rev-parse --show-toplevel
>     /.../bar
>     % GIT_DIR=../../foo/.git/worktrees/bar \
>         git -C dir rev-parse --show-toplevel
>     /.../bar/dir
>
> The `git rev-parse --show-toplevel` invocation with GIT_DIR set is
> incorrectly returning `/.../bar/dir` rather than `/.../bar`.
Eric Sunshine· Oct 15, 2024, 20:01 UTC · re: David Moberg · lore

Re: git rebase exec make -C in worktree confuses repo root dir

On Tue, Oct 15, 2024 at 2:55 PM David Moberg <kaddkaka@gmail.com> wrote:
Show 24 quoted lines
> Den tis 15 okt. 2024 kl 09:11 skrev Eric Sunshine <sunshine@sunshineco.com>:
> > This looks like unintentional behavior; probably a bug. It seems to be
> > triggered by `git rebase -i` setting GIT_DIR. Here's an even simpler
> > reproduction recipe:
> >
> >     % git init foo
> >     % cd foo
> >     % mkdir dir
> >     % echo foo >dir/file
> >     % git add dir/file
> >     % git commit -m foo
> >     % git worktree add ../bar
> >     % cd ../bar
> >     % git -C dir rev-parse --show-toplevel
> >     /.../bar
> >     % GIT_DIR=../../foo/.git/worktrees/bar \
> >         git -C dir rev-parse --show-toplevel
> >     /.../bar/dir
> >
> > The `git rev-parse --show-toplevel` invocation with GIT_DIR set is
> > incorrectly returning `/.../bar/dir` rather than `/.../bar`.
>
> Thanks, that is indeed a much smaller example and it seems to exhibit
> the same issue. Can we figure out how to fix it?

Someone is going to have to dig into the code, but my Git time is very limited right now, so perhaps someone else can do the digging.

If you want an immediate workaround for the problem for your specific use-case, you can probably unset GIT_DIR in your `exec` instruction.

(By the way, please avoid top-posting when you reply on this list; instead, post inline as I did here.)

Phillip Wood· Oct 16, 2024, 09:15 UTC · re: Eric Sunshine · lore

Re: git rebase exec make -C in worktree confuses repo root dir

On 15/10/2024 21:01, Eric Sunshine wrote:
Show 28 quoted lines
> On Tue, Oct 15, 2024 at 2:55 PM David Moberg <kaddkaka@gmail.com> wrote:
>> Den tis 15 okt. 2024 kl 09:11 skrev Eric Sunshine <sunshine@sunshineco.com>:
>>> This looks like unintentional behavior; probably a bug. It seems to be
>>> triggered by `git rebase -i` setting GIT_DIR. Here's an even simpler
>>> reproduction recipe:
>>>
>>>      % git init foo
>>>      % cd foo
>>>      % mkdir dir
>>>      % echo foo >dir/file
>>>      % git add dir/file
>>>      % git commit -m foo
>>>      % git worktree add ../bar
>>>      % cd ../bar
>>>      % git -C dir rev-parse --show-toplevel
>>>      /.../bar
>>>      % GIT_DIR=../../foo/.git/worktrees/bar \
>>>          git -C dir rev-parse --show-toplevel
>>>      /.../bar/dir
>>>
>>> The `git rev-parse --show-toplevel` invocation with GIT_DIR set is
>>> incorrectly returning `/.../bar/dir` rather than `/.../bar`.
>>
>> Thanks, that is indeed a much smaller example and it seems to exhibit
>> the same issue. Can we figure out how to fix it?
> 
> Someone is going to have to dig into the code, but my Git time is very
> limited right now, so perhaps someone else can do the digging.

I'm about to go off the list until the 29th so I wont be working on it soon either but I think the problem is that git sets $GIT_DIR when it is run from a linked worktree. I've reproduced the commit message from ff5b7913f0a (sequencer, stash: fix running from worktree subdir, 2022-01-26) below which I think explains the problem we're seeing here. Unfortunately the approach of setting $GIT_WORK_TREE used in that commit won't work for exec commands as they may be run in a different worktree. Naively I feel that if setup_git_directory() has found ".git" then any git subprocesses run in the worktree should also be able to find ".git" and so it should not be setting $GIT_DIR but there maybe there is some subtlety I'm missing

     commit ff5b7913f0af62c26682b0376d0aa2d7f5d74b2e
     Author: Elijah Newren <newren@gmail.com>
     Date:   Wed Jan 26 01:43:45 2022 +0000
     sequencer, stash: fix running from worktree subdir
     In commits bc3ae46b42 ("rebase: do not attempt to remove
     startup_info->original_cwd", 2021-12-09) and 0fce211ccc ("stash: do
     not attempt to remove startup_info->original_cwd", 2021-12-09), we
     wanted to allow the subprocess to know which directory the parent
     process was running from, so that the subprocess could protect it.
     However...
     When run from a non-main worktree, setup_git_directory() will note
     that the discovered git directory
     (/PATH/TO/.git/worktree/non-main-worktree) does not match
     DEFAULT_GIT_DIR_ENVIRONMENT (see setup_discovered_git_dir()), and
     decide to set GIT_DIR in the environment.  This matters because...
     Whenever git is run with the GIT_DIR environment variable set, and
     GIT_WORK_TREE not set, it presumes that '.' is the working tree.
     So...
     This combination results in the subcommand being very confused about
     the working tree.  Fix it by also setting the GIT_WORK_TREE
     environment variable along with setting cmd.dir.
     A possibly more involved fix we could consider for later would be to
     make setup.c set GIT_WORK_TREE whenever (a) it discovers both the
     git directory and the working tree and (b) it decides to set GIT_DIR
     in the environment.  I did not attempt that here as such would be
     too big of a change for a 2.35.1 release.
     Test-case-by: Glen Choo <chooglen@google.com>
     Signed-off-by: Elijah Newren <newren@gmail.com>
     Signed-off-by: Junio C Hamano <gitster@pobox.com>
> If you want an immediate workaround for the problem for your specific
> use-case, you can probably unset GIT_DIR in your `exec` instruction.

Indeed I think that should work in this case. Unfortunately we cannot do that unconditionally when running exec commands as the user may have set GIT_DIR when running "git rebase"

Best Wishes
Phillip
> (By the way, please avoid top-posting when you reply on this list;
> instead, post inline as I did here.)
> 
Taylor Blau· Oct 16, 2024, 20:36 UTC · re: Phillip Wood · lore

Re: git rebase exec make -C in worktree confuses repo root dir

On Wed, Oct 16, 2024 at 10:15:49AM +0100, Phillip Wood wrote:
Show 40 quoted lines
> On 15/10/2024 21:01, Eric Sunshine wrote:
> > On Tue, Oct 15, 2024 at 2:55 PM David Moberg <kaddkaka@gmail.com> wrote:
> > > Den tis 15 okt. 2024 kl 09:11 skrev Eric Sunshine <sunshine@sunshineco.com>:
> > > > This looks like unintentional behavior; probably a bug. It seems to be
> > > > triggered by `git rebase -i` setting GIT_DIR. Here's an even simpler
> > > > reproduction recipe:
> > > >
> > > >      % git init foo
> > > >      % cd foo
> > > >      % mkdir dir
> > > >      % echo foo >dir/file
> > > >      % git add dir/file
> > > >      % git commit -m foo
> > > >      % git worktree add ../bar
> > > >      % cd ../bar
> > > >      % git -C dir rev-parse --show-toplevel
> > > >      /.../bar
> > > >      % GIT_DIR=../../foo/.git/worktrees/bar \
> > > >          git -C dir rev-parse --show-toplevel
> > > >      /.../bar/dir
> > > >
> > > > The `git rev-parse --show-toplevel` invocation with GIT_DIR set is
> > > > incorrectly returning `/.../bar/dir` rather than `/.../bar`.
> > >
> > > Thanks, that is indeed a much smaller example and it seems to exhibit
> > > the same issue. Can we figure out how to fix it?
> >
> > Someone is going to have to dig into the code, but my Git time is very
> > limited right now, so perhaps someone else can do the digging.
>
> I'm about to go off the list until the 29th so I wont be working on it soon
> either but I think the problem is that git sets $GIT_DIR when it is run from
> a linked worktree. I've reproduced the commit message from ff5b7913f0a
> (sequencer, stash: fix running from worktree subdir, 2022-01-26) below which
> I think explains the problem we're seeing here. Unfortunately the approach
> of setting $GIT_WORK_TREE used in that commit won't work for exec commands
> as they may be run in a different worktree. Naively I feel that if
> setup_git_directory() has found ".git" then any git subprocesses run in the
> worktree should also be able to find ".git" and so it should not be setting
> $GIT_DIR but there maybe there is some subtlety I'm missing
Let's see if that commit's author Elijah (CC'd) has any other thoughts.

Thanks, Taylor

Elijah Newren· Oct 17, 2024, 21:16 UTC · re: Taylor Blau · lore

Re: git rebase exec make -C in worktree confuses repo root dir

On Wed, Oct 16, 2024 at 1:36 PM Taylor Blau <me@ttaylorr.com> wrote:
Show 47 quoted lines
>
> On Wed, Oct 16, 2024 at 10:15:49AM +0100, Phillip Wood wrote:
> > On 15/10/2024 21:01, Eric Sunshine wrote:
> > > On Tue, Oct 15, 2024 at 2:55 PM David Moberg <kaddkaka@gmail.com> wrote:
> > > > Den tis 15 okt. 2024 kl 09:11 skrev Eric Sunshine <sunshine@sunshineco.com>:
> > > > > This looks like unintentional behavior; probably a bug. It seems to be
> > > > > triggered by `git rebase -i` setting GIT_DIR. Here's an even simpler
> > > > > reproduction recipe:
> > > > >
> > > > >      % git init foo
> > > > >      % cd foo
> > > > >      % mkdir dir
> > > > >      % echo foo >dir/file
> > > > >      % git add dir/file
> > > > >      % git commit -m foo
> > > > >      % git worktree add ../bar
> > > > >      % cd ../bar
> > > > >      % git -C dir rev-parse --show-toplevel
> > > > >      /.../bar
> > > > >      % GIT_DIR=../../foo/.git/worktrees/bar \
> > > > >          git -C dir rev-parse --show-toplevel
> > > > >      /.../bar/dir
> > > > >
> > > > > The `git rev-parse --show-toplevel` invocation with GIT_DIR set is
> > > > > incorrectly returning `/.../bar/dir` rather than `/.../bar`.
> > > >
> > > > Thanks, that is indeed a much smaller example and it seems to exhibit
> > > > the same issue. Can we figure out how to fix it?
> > >
> > > Someone is going to have to dig into the code, but my Git time is very
> > > limited right now, so perhaps someone else can do the digging.
> >
> > I'm about to go off the list until the 29th so I wont be working on it soon
> > either but I think the problem is that git sets $GIT_DIR when it is run from
> > a linked worktree. I've reproduced the commit message from ff5b7913f0a
> > (sequencer, stash: fix running from worktree subdir, 2022-01-26) below which
> > I think explains the problem we're seeing here. Unfortunately the approach
> > of setting $GIT_WORK_TREE used in that commit won't work for exec commands
> > as they may be run in a different worktree. Naively I feel that if
> > setup_git_directory() has found ".git" then any git subprocesses run in the
> > worktree should also be able to find ".git" and so it should not be setting
> > $GIT_DIR but there maybe there is some subtlety I'm missing
>
> Let's see if that commit's author Elijah (CC'd) has any other thoughts.
>
> Thanks,
> Taylor

My commit merely pointed out that long before that commit came along, if GIT_DIR is set but GIT_WORK_TREE is not, then the working tree is assumed to be ".". As such, a command like the above where `--show-toplevel` is run with just GIT_DIR set (to anything) will merely expand "." and show you that path.

If you are going to be having subprocesses that depend upon the git
directory and the git working tree, I think there are two options:
  * Set GIT_WORK_TREE in addition to GIT_DIR (as my patch does in certain cases)
  * Stop setting GIT_DIR if you're not going to set GIT_WORK_TREE

The second point is a bit harder since setup.c automatically sets GIT_DIR for you in various cases, so if you want to go that route it really means you'd have to actively unset GIT_DIR in those cases. But, you'd have to be careful since you only want to unset it when setup_discovered_git_dir() sets it for you, not when the user who invoked your command had manually set GIT_DIR. So, there is a little bit of a pickle here...

Eric Sunshine· Oct 16, 2024, 21:12 UTC · re: Phillip Wood · lore

Re: git rebase exec make -C in worktree confuses repo root dir

On Wed, Oct 16, 2024 at 5:15 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 20 quoted lines
> On 15/10/2024 21:01, Eric Sunshine wrote:
> >> Den tis 15 okt. 2024 kl 09:11 skrev Eric Sunshine <sunshine@sunshineco.com>:
> >>> This looks like unintentional behavior; probably a bug. It seems to be
> >>> triggered by `git rebase -i` setting GIT_DIR. [...]
> >>>      % git -C dir rev-parse --show-toplevel
> >>>      /.../bar
> >>>      % GIT_DIR=../../foo/.git/worktrees/bar \
> >>>          git -C dir rev-parse --show-toplevel
> >>>      /.../bar/dir
> >>>
> >>> The `git rev-parse --show-toplevel` invocation with GIT_DIR set is
> >>> incorrectly returning `/.../bar/dir` rather than `/.../bar`.
>
> I'm about to go off the list until the 29th so I wont be working on it
> soon either but I think the problem is that git sets $GIT_DIR when it is
> run from a linked worktree. I've reproduced the commit message from
> ff5b7913f0a (sequencer, stash: fix running from worktree subdir,
> 2022-01-26) below which I think explains the problem we're seeing here.
> Unfortunately the approach of setting $GIT_WORK_TREE used in that commit
> won't work for exec commands as they may be run in a different worktree.

Maybe. Maybe not. exec'ing a command in a worktree other than the current worktree may be a "don't do it if it hurts" situation. The same shortcoming you describe would crop up when exec'ing a command in a foreign repository from the one in which `git rebase -i` is being run. If we look at it that way ("don't do it if it hurts"), then perhaps a documentation update is warranted; something along the lines [1] which gives explains that GIT_* environment variables should be cleared by a Git hook if it needs to peek into a foreign repository or other worktree. It's not a perfectly satisfactory answer, but would at least (somewhat?) allay your concern about `git rebase -i` setting GIT_WORK_TREE automatically.

[1]: https://lore.kernel.org/git/pull.1457.git.1673171924727.gitgitgadget@gmail.com/
phillip.wood123@gmail.com· Nov 5, 2024, 15:24 UTC · re: Eric Sunshine · lore

Re: git rebase exec make -C in worktree confuses repo root dir

On 16/10/2024 22:12, Eric Sunshine wrote:
Show 33 quoted lines
> On Wed, Oct 16, 2024 at 5:15 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>> On 15/10/2024 21:01, Eric Sunshine wrote:
>>>> Den tis 15 okt. 2024 kl 09:11 skrev Eric Sunshine <sunshine@sunshineco.com>:
>>>>> This looks like unintentional behavior; probably a bug. It seems to be
>>>>> triggered by `git rebase -i` setting GIT_DIR. [...]
>>>>>       % git -C dir rev-parse --show-toplevel
>>>>>       /.../bar
>>>>>       % GIT_DIR=../../foo/.git/worktrees/bar \
>>>>>           git -C dir rev-parse --show-toplevel
>>>>>       /.../bar/dir
>>>>>
>>>>> The `git rev-parse --show-toplevel` invocation with GIT_DIR set is
>>>>> incorrectly returning `/.../bar/dir` rather than `/.../bar`.
>>
>> I'm about to go off the list until the 29th so I wont be working on it
>> soon either but I think the problem is that git sets $GIT_DIR when it is
>> run from a linked worktree. I've reproduced the commit message from
>> ff5b7913f0a (sequencer, stash: fix running from worktree subdir,
>> 2022-01-26) below which I think explains the problem we're seeing here.
>> Unfortunately the approach of setting $GIT_WORK_TREE used in that commit
>> won't work for exec commands as they may be run in a different worktree.
> 
> Maybe. Maybe not. exec'ing a command in a worktree other than the
> current worktree may be a "don't do it if it hurts" situation. The
> same shortcoming you describe would crop up when exec'ing a command in
> a foreign repository from the one in which `git rebase -i` is being
> run. If we look at it that way ("don't do it if it hurts"), then
> perhaps a documentation update is warranted; something along the lines
> [1] which gives explains that GIT_* environment variables should be
> cleared by a Git hook if it needs to peek into a foreign repository or
> other worktree. It's not a perfectly satisfactory answer, but would at
> least (somewhat?) allay your concern about `git rebase -i` setting
> GIT_WORK_TREE automatically.

That's certainly the simplest way forward. Until 434e0636db1 (sequencer: do not export GIT_DIR and GIT_WORK_TREE for 'exec', 2021-12-04) we set both GIT_DIR and GIT_WORK_TREE when running an exec command. As the message for that commit explains that behavior did not match the scripted rebase which was the motivation to stop doing it. Unfortunately that left us in the situation where git will sometimes set GIT_DIR when the user has not. Ideally I'd like to understand why we're setting GIT_DIR in setup_git_dir() when, at least at fist sight, it seems to be unnecessary. I think that would take some time so maybe we should just go back to setting GIT_DIR and GIT_WORK_TREE in the sequencer when running "exec" commands.

Best Wishes
Phillip
> [1]: https://lore.kernel.org/git/pull.1457.git.1673171924727.gitgitgadget@gmail.com/

← back to recent threads