Subject: Re: Forcing git top-level

From: Jeff King <[email-masked]>
Date: Tue, 31 Mar 2015 14:15:52 -0400

On Tue, Mar 31, 2015 at 11:25:58AM +0200, Cedric Gava wrote:

> I’ve copied a .git folder located at the root (/) of a filesystem,
> into another directory (/home/mydir). If I issue a git rev-parse
> —show-toplevel I got "/"...
> I would like to change the top-level to point to /home/mydir.

Try running "git config --unset core.worktree" in the .git dir.

It looks like "git init" will write a core.worktree entry in this case,
even though it isn't technically needed. I think it is due to these
lines in builtin/init-db.c:

                if (!starts_with(git_dir, work_tree) ||
                    strcmp(git_dir + strlen(work_tree), "/.git")) {
                        git_config_set("core.worktree", work_tree);
                }

The check returns a false positive for the root directory because we
only have one slash (i.e., appending "/.git" to our worktree would be
"//.git" in this case).

-Peff