git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Forcing git top-level

From
Jeff King <peff@peff.net>
Date
Mar 31, 2015, 18:15 UTC
Message-ID
<20150331181552.GC19206@peff.net>
In-Reply-To
<0FD999DB-3DBF-40D4-8128-715BDC49EAAB@free.fr>
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
Previous: Cedric GavaNext: Jeff King
Message 2 of 11 in “Forcing git top-level”
  1. Cedric GavaMar 31, 2015
  2. Jeff KingMar 31, 2015
  3. init: don't set core.worktree when initializing /.gitJeff King, Mar 31, 2015
  4. Jonathan NiederMar 31, 2015
  5. init: don't set core.worktree when initializing /.gitJeff King, Apr 2, 2015
  6. Jonathan NiederApr 2, 2015
  7. t1509: update prepare script to be able to run t1509 in chroot againNguyễn Thái Ngọc Duy, Apr 3, 2015
  8. Jeff KingApr 3, 2015
  9. Duy NguyenApr 3, 2015
  10. Junio C HamanoApr 11, 2015
  11. t1509: update prepare script to be able to run t1509 in chroot againNguyễn Thái Ngọc Duy, Apr 18, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.