# Bug with worktrees...

3 messages from 2015-08-27 to 2015-08-28. Participants: John Szakmeister, Eric Sunshine.
Thread: https://gitlist.dev/t/40200

## John Szakmeister, 2015-08-27 19:03

Subject: Bug with worktrees...
Message-ID: <CAEBDL5UQSvS=t1dUKYqK6R=xHU6RU3bS72w-i02ey-Y_VB9KMQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAEBDL5UQSvS%3Dt1dUKYqK6R%3DxHU6RU3bS72w-i02ey-Y_VB9KMQ%40mail.gmail.com

```
My apologies if this has already been reported, but I ran into an
interesting bug with worktrees.  In particular, I have an alias 'st'
that maps to 'status -sb'.  When running this under a subdirectory of
a worktree created with 'git worktree add', it fails complaining that
the work tree has already been set.

Here's a script to reproduce the problem:
    git init test-repo
    cd test-repo
    git config --local alias.st 'status -sb'
    mkdir subdir
    echo file > subdir/file.txt
    git add subdir/file.txt
    git commit -m 'add file'
    git branch foo
    git worktree add ../new-worktree foo
    cd ../new-worktree/subdir
    echo "new line" >> file.txt
    echo "this will work"
    git status -sb
    echo "this fails"
    git st

When I run it, I see this:

Initialized empty Git repository in
/home/jszakmeister/tmp/test-case/test-repo/.git/
[master (root-commit) 1ec5360] add file
 1 file changed, 1 insertion(+)
 create mode 100644 subdir/file.txt
Enter ../new-worktree (identifier new-worktree)
Switched to branch 'foo'
this will work
## foo
this fails
fatal: internal error: work tree has already been set
Current worktree: /home/jszakmeister/tmp/test-case/new-worktree
New worktree: /home/jszakmeister/tmp/test-case/new-worktree/subdir

Hope this helps!

-John

```

## Eric Sunshine, 2015-08-28 02:55

Subject: Re: Bug with worktrees...
Message-ID: <CAPig+cTkeOywRH1-_4Zi9jOd5r1cXa9vJhYAYXhF3E+SSE_GeA@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcTkeOywRH1-_4Zi9jOd5r1cXa9vJhYAYXhF3E%2BSSE_GeA%40mail.gmail.com
In-Reply-To: <CAEBDL5UQSvS=t1dUKYqK6R=xHU6RU3bS72w-i02ey-Y_VB9KMQ@mail.gmail.com>

```
On Thu, Aug 27, 2015 at 3:03 PM, John Szakmeister <john@szakmeister.net> wrote:
> My apologies if this has already been reported, but I ran into an
> interesting bug with worktrees.  In particular, I have an alias 'st'
> that maps to 'status -sb'.  When running this under a subdirectory of
> a worktree created with 'git worktree add', it fails complaining that
> the work tree has already been set.
>
> Here's a script to reproduce the problem:
>     git init test-repo
>     cd test-repo
>     git config --local alias.st 'status -sb'
>     mkdir subdir
>     echo file > subdir/file.txt
>     git add subdir/file.txt
>     git commit -m 'add file'
>     git branch foo
>     git worktree add ../new-worktree foo
>     cd ../new-worktree/subdir
>     echo "new line" >> file.txt
>     echo "this will work"
>     git status -sb
>     echo "this fails"
>     git st
>
> When I run it, I see this:
> [...]
> fatal: internal error: work tree has already been set
> Current worktree: /home/jszakmeister/tmp/test-case/new-worktree
> New worktree: /home/jszakmeister/tmp/test-case/new-worktree/subdir

I can reproduce with 2.5.0 but not 'master'. Bisection reveals that
this was fixed by d95138e (setup: set env $GIT_WORK_TREE when work
tree is set, like $GIT_DIR, 2015-06-26), and was reported previously
here [1].

[1]: http://git.661346.n2.nabble.com/Linked-workdirs-break-typo-correction-td7634347.html

```

## John Szakmeister, 2015-08-28 10:27

Subject: Re: Bug with worktrees...
Message-ID: <CAEBDL5W9Ly_tsE35OG+MGZkA0V41FEoewZTWk9EPZxXQHnRF6A@mail.gmail.com>
URL: https://gitlist.dev/e/CAEBDL5W9Ly_tsE35OG%2BMGZkA0V41FEoewZTWk9EPZxXQHnRF6A%40mail.gmail.com
In-Reply-To: <CAPig+cTkeOywRH1-_4Zi9jOd5r1cXa9vJhYAYXhF3E+SSE_GeA@mail.gmail.com>

```
On Thu, Aug 27, 2015 at 10:55 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
[snip]
> I can reproduce with 2.5.0 but not 'master'. Bisection reveals that
> this was fixed by d95138e (setup: set env $GIT_WORK_TREE when work
> tree is set, like $GIT_DIR, 2015-06-26), and was reported previously
> here [1].

I had done a quick search but didn't turn up that thread.  Thank you Eric!

-John

```
