# 'git rev-parse --show-toplevel' errors out with per-worktree configs

3 messages from 2020-07-14 to 2020-07-14. Participants: Clement Moyroud.
Thread: https://gitlist.dev/t/53858

## Clement Moyroud, 2020-07-14 19:40

Subject: 'git rev-parse --show-toplevel' errors out with per-worktree configs
Message-ID: <CABXAcUxw5EA6jPB93C-Cfg-tycLMQSKUgrLkLXSQUZPHeEva9Q@mail.gmail.com>
URL: https://gitlist.dev/e/CABXAcUxw5EA6jPB93C-Cfg-tycLMQSKUgrLkLXSQUZPHeEva9Q%40mail.gmail.com

```
Hello,

I have a bare repository clone that I create worktrees off. This works
fine, including 'git rev-parse --show-toplevel'.

I enabled per-worktree configs using 'git config --local
extensions.worktreeconfig=true', and now I can't get the toplevel
anymore:
> git rev-parse --show-toplevel
fatal: this operation must be run in a work tree

Disabling per-worktree configs makes it work again. This also works
fine on a non-bare repository clone.

IOW, this works:
git clone <url> non-bare
(cd non-bare && git worktree add -b master2 ../wtree1 master)
(cd wtree1 && git rev-parse --show-toplevel)

This does not:
git clone -c extensions.worktreeConfig=true <url> bare.git
(cd bare.git && git worktree add -b master2 ../wtree2 master)
(cd wtree2 && git rev-parse --show-toplevel)

Is this a bug, or am I missing something?

Thanks,

Clément

```

## Clement Moyroud, 2020-07-14 21:34

Subject: Re: 'git rev-parse --show-toplevel' errors out with per-worktree configs
Message-ID: <CABXAcUx9ubCi485xoawSERH4pEjAFJcfGbdNiRL7KkwAmFrMsw@mail.gmail.com>
URL: https://gitlist.dev/e/CABXAcUx9ubCi485xoawSERH4pEjAFJcfGbdNiRL7KkwAmFrMsw%40mail.gmail.com
In-Reply-To: <CABXAcUzvZgHwsfL8VaevnDeyyce_5sWtd2istA55CgnzFE1Z6A@mail.gmail.com>

```
> > IOW, this works:
> > git clone <url> non-bare
> > (cd non-bare && git worktree add -b master2 ../wtree1 master)
> > (cd wtree1 && git rev-parse --show-toplevel)
> >
> > This does not:
> > git clone -c extensions.worktreeConfig=true <url> bare.git
> > (cd bare.git && git worktree add -b master2 ../wtree2 master)
> > (cd wtree2 && git rev-parse --show-toplevel)
> >
>
> Sorry, I mixed up my examples.
>
> This works:
> git clone -c extensions.worktreeConfig=true <url> non-bare
> (cd non-bare && git worktree add -b master2 ../wtree1 master)
> (cd wtree1 && git rev-parse --show-toplevel)
>
> This does not:
> git clone -c extensions.worktreeConfig=true --mirror <url> bare.git
> (cd bare.git && git worktree add -b master2 ../wtree2 master)
> (cd wtree2 && git rev-parse --show-toplevel)

OK, I figured it out by looking at environment.c. The issue is that
the base mirror is bare, but the worktree isn't. This makes it work:
(cd wtree2 && git config --worktree core.bare true)

This is confusing - should this be set automatically, or referenced
more clearly in the 'Configuration File' section of the git-worktree
doc?

Thanks,

Clément

```

## Clement Moyroud, 2020-07-14 20:38

Subject: Re: 'git rev-parse --show-toplevel' errors out with per-worktree configs
Message-ID: <CABXAcUzvZgHwsfL8VaevnDeyyce_5sWtd2istA55CgnzFE1Z6A@mail.gmail.com>
URL: https://gitlist.dev/e/CABXAcUzvZgHwsfL8VaevnDeyyce_5sWtd2istA55CgnzFE1Z6A%40mail.gmail.com
In-Reply-To: <CABXAcUxw5EA6jPB93C-Cfg-tycLMQSKUgrLkLXSQUZPHeEva9Q@mail.gmail.com>

```
> IOW, this works:
> git clone <url> non-bare
> (cd non-bare && git worktree add -b master2 ../wtree1 master)
> (cd wtree1 && git rev-parse --show-toplevel)
>
> This does not:
> git clone -c extensions.worktreeConfig=true <url> bare.git
> (cd bare.git && git worktree add -b master2 ../wtree2 master)
> (cd wtree2 && git rev-parse --show-toplevel)
>

Sorry, I mixed up my examples.

This works:
git clone -c extensions.worktreeConfig=true <url> non-bare
(cd non-bare && git worktree add -b master2 ../wtree1 master)
(cd wtree1 && git rev-parse --show-toplevel)

This does not:
git clone -c extensions.worktreeConfig=true --mirror <url> bare.git
(cd bare.git && git worktree add -b master2 ../wtree2 master)
(cd wtree2 && git rev-parse --show-toplevel)

```
