threads / discuss / 35029

Problem switching branches in submodule

Subject: Problem switching branches in submodule

## tl;dr

6 messages between Sep 26, 2013 and Sep 26, 2013.

replies: 5people: 3as markdown or json

Manish Gill· Sep 26, 2013, 17:20 UTC · lore
Hello,

I have a git repository with lots of submodules. In one particular submodule, I'm having the following problem:

If I try to switch branches at the top-level of that submodule, I succeed.

But, if I try to switch branches in any subsequen levels, I get the following error:

    fatal: internal error: work tree has already been set
    Current worktree: ../path/Mailman3/rest_project
    New worktree: ../path/Mailman3/rest_project/website/public_rest

Here, Mailman3 is the primary repository and "rest_project" is a submodule. I can do "git checkout" just fine inside rest_project, but not after cd-ing into any other repos.

My git version is 1.8.4
Other commands, like git status, push/pull are working fine.
I'd appreciate any help. Thank you.
Jonathan Nieder· Sep 26, 2013, 18:08 UTC · re: Manish Gill · lore

Re: Problem switching branches in submodule

(cc-ing Duy, who knows the setup code well) Manish Gill wrote:

Show 19 quoted lines
> I have a git repository with lots of submodules. In one particular
> submodule, I'm having the following problem:
>
> If I try to switch branches at the top-level of that submodule, I succeed.
>
> But, if I try to switch branches in any subsequen levels, I get the
> following error:
>
>     fatal: internal error: work tree has already been set
>     Current worktree: ../path/Mailman3/rest_project
>     New worktree: ../path/Mailman3/rest_project/website/public_rest
>
> Here, Mailman3 is the primary repository and "rest_project" is a
> submodule. I can do "git checkout" just fine
> inside rest_project, but not after cd-ing into any other repos.
>
> My git version is 1.8.4
>
> Other commands, like git status, push/pull are working fine.
Interesting.  Yeah, this shouldn't happen.

What is the exact command you use to get the above output? Is your repository public (which would let us reproduce it) or can you reproduce it by creating a small artificial test repository?

For comparison, did some previous version of git work ok in the same scenario, or is this the first time you've tried it?

Thanks, Jonathan

Manish Gill· Sep 26, 2013, 18:33 UTC · re: Jonathan Nieder · lore

Re: Problem switching branches in submodule

On 09/26/2013 11:38 PM, Jonathan Nieder wrote:
Show 26 quoted lines
> (cc-ing Duy, who knows the setup code well)
> Manish Gill wrote:
> 
>> I have a git repository with lots of submodules. In one particular
>> submodule, I'm having the following problem:
>>
>> If I try to switch branches at the top-level of that submodule, I succeed.
>>
>> But, if I try to switch branches in any subsequen levels, I get the
>> following error:
>>
>>     fatal: internal error: work tree has already been set
>>     Current worktree: ../path/Mailman3/rest_project
>>     New worktree: ../path/Mailman3/rest_project/website/public_rest
>>
>> Here, Mailman3 is the primary repository and "rest_project" is a
>> submodule. I can do "git checkout" just fine
>> inside rest_project, but not after cd-ing into any other repos.
>>
>> My git version is 1.8.4
>>
>> Other commands, like git status, push/pull are working fine.
> 
> Interesting.  Yeah, this shouldn't happen.
> 
> What is the exact command you use to get the above output?  
git checkout <branch_name>
Is your
> repository public (which would let us reproduce it) or can you
> reproduce it by creating a small artificial test repository
The repo isn't public, I'm afraid.

I should mention what *exactly* happened that led to this. I was trying to publish my branch on Launchpad (using git-remote-bzr). At some point, I had the genius idea to remote the extra stuff from the config file and just try with the bzr:: remote as origin, and instead of doing it via the console, I just replaced the config file.

Annnnyway, I just restored my backed up config file for that submodule in the middle of writing this and seems like things seem to work now.

I dunno, this was most likely because of some configuration derp on my part (the new config file didn't contain the branch information most likely). So I guess problem solved!

Thanks for your help.
Jonathan Nieder· Sep 26, 2013, 18:48 UTC · re: Manish Gill · lore

Re: Problem switching branches in submodule

Manish Gill wrote:
> Jonathan Nieder wrote:
>> What is the exact command you use to get the above output?
>
> git checkout <branch_name>

Is <branch_name> a normal branch, a remote-tracking branch, or a branch that doesn't exist yet?

[...]
Show 8 quoted lines
> I should mention what *exactly* happened that led to this. I was trying
> to publish my branch on Launchpad (using git-remote-bzr). At some point,
> I had the genius idea to remote the extra stuff from the config file and
> just try with the bzr:: remote as origin, and instead of doing it via
> the console, I just replaced the config file.
>
> Annnnyway, I just restored my backed up config file for that submodule
> in the middle of writing this and seems like things seem to work now.

If you happen to have a copy of the old config file or remember what it said, that could be helpful (especially if you can still reproduce the problem in case we come up with a fix).

Did the config file have a [core] worktree setting or something similar?

Hmm, Jonathan

Manish Gill· Sep 26, 2013, 19:29 UTC · re: Jonathan Nieder · lore

Re: Problem switching branches in submodule

On 09/27/2013 12:18 AM, Jonathan Nieder wrote:
Show 9 quoted lines
> Manish Gill wrote:
>> Jonathan Nieder wrote:
> 
>>> What is the exact command you use to get the above output?
>>
>> git checkout <branch_name>
> 
> Is <branch_name> a normal branch, a remote-tracking branch, or a
> branch that doesn't exist yet?
Local branch that was supposed to track a remote branch.
Show 14 quoted lines
> 
> [...]
>> I should mention what *exactly* happened that led to this. I was trying
>> to publish my branch on Launchpad (using git-remote-bzr). At some point,
>> I had the genius idea to remote the extra stuff from the config file and
>> just try with the bzr:: remote as origin, and instead of doing it via
>> the console, I just replaced the config file.
>>
>> Annnnyway, I just restored my backed up config file for that submodule
>> in the middle of writing this and seems like things seem to work now.
> 
> If you happen to have a copy of the old config file or remember what it
> said, that could be helpful (especially if you can still reproduce the
> problem in case we come up with a fix).

Config file which was NOT working: http://bpaste.net/show/oaWG3TQarH3BrdjDj5be/

Working config restored from backup: http://bpaste.net/show/nF3ap5fDEAwL9NyqdCmD/

> 
> Did the config file have a [core] worktree setting or something similar?

Looks like the working one had it and the other didn't. Adding the "worktree" setting seems to fix the problem. But shouldn't this work uniformly in the repo? Removing the [core] worktree gives the same error, but only in directories inside the repo. Checkout still works on the top-level. Seems a bit strange I guess.

> 
> Hmm,
> Jonathan
> 
Duy Nguyen· Sep 26, 2013, 23:44 UTC · re: Manish Gill · lore

Re: Problem switching branches in submodule

On Fri, Sep 27, 2013 at 12:20 AM, Manish Gill <mgill25@outlook.com> wrote:
Show 14 quoted lines
> Hello,
>
> I have a git repository with lots of submodules. In one particular
> submodule, I'm having the following problem:
>
> If I try to switch branches at the top-level of that submodule, I succeed.
>
> But, if I try to switch branches in any subsequen levels, I get the
> following error:
>
>     fatal: internal error: work tree has already been set
>     Current worktree: ../path/Mailman3/rest_project
>     New worktree: ../path/Mailman3/rest_project/website/public_rest
>

Can you apply this patch, rebuild git and retry again? It will create a coredump at "fatal:...", which might give me a clue what's going on.. Once you get the coredump, open it with gdb, execute "bt full" and paste the output here.

diff --git a/usage.c b/usage.c
index ed14645..0403091 100644
--- a/usage.c
+++ b/usage.c
@@ -34,6 +34,7 @@ static NORETURN void usage_builtin(const char *err,
va_list params)
 static NORETURN void die_builtin(const char *err, va_list params)
 {
        vreportf("fatal: ", err, params);
+       *(char*)0 = 1;
        exit(128);
 }
-- 
Duy

← back to recent threads