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

Re: [PATCH] Export GIT_DIR after setting it

From
Björn Steinbrink <b.steinbrink@gmx.de>
Date
May 15, 2008, 17:55 UTC
Message-ID
<20080515175555.GA13003@atjola.homenet>
In-Reply-To
<7vlk2bh45u.fsf@gitster.siamese.dyndns.org>
On 2008.05.15 10:23:57 -0700, Junio C Hamano wrote:
Show 15 quoted lines
> "martin f. krafft" <madduck@madduck.net> writes:
> 
> > The only problem I see now is when an external command (or the shell
> > script) can't properly deal with GIT_DIR being set, but then that's
> > a whole different bug.
> 
> One thing that we did not have to worry about when git-sh-setup was
> invented is GIT_WORK_TREE and its cousin core.worktree.  When the user
> uses GIT_DIR _but_ wants to work from a subdirectory of the checked out
> work tree, the user _must_ tell git where the top of the work tree is; in
> other words, setting and exporting only GIT_DIR is a misconfiguration.
> 
> I have a suspicion that "the whole different bug" is what bit you --
> perhaps some places need to also set and export GIT_WORK_TREE as well when
> the do GIT_DIR.

For completeness, here's an actual example of how it breaks: doener@atjola:g $ git_fake_bare_checkout() {

Show 12 quoted lines
>                 url="$1"
>                 repo="$2"
>                 worktree="$3"
>                 git clone --no-checkout "$url" "$repo"
>                 cd "$repo"
>                 mkdir -p "$worktree"
>                 git read-tree HEAD
>                 git checkout-index -a --prefix="$worktree" || true
>                 git config core.worktree "$worktree"
>                 mv .git/* .
>                 rmdir .git
>         }

doener@atjola:g $ git_fake_bare_checkout git://git.madduck.net/etc/git.git git.git ../ Initialized empty Git repository in /home/doener/g/git.git/.git/ Receiving objects: 100% (6/6), done. remote: Counting objects: 6, done. remote: Compressing objects: 100% (4/4), done. remote: Total 6 (delta 0), reused 0 (delta 0) doener@atjola:git.git (master) $ git fetch doener@atjola:git.git (master) $ git pull fatal: Not a git repository fatal: Not a git repository fatal: Not a git repository

So the git directory is not called .git but git.git, with core.worktree set to "../". When "git fetch" is called directly, it correctly finds that the git dir is "." Same for "git pull", but as GIT_DIR is neither set in the environment, nor exported by git-pull, the commands that get executed by git-pull do not find the git dir, because git-pull does cd_to_toplevel first, and obviously the other commands won't look for git.git, but just .git.

It kind of feels like a bug that git-pull does not export GIT_DIR there, but you could probably also argue that it is wrong not to have GIT_DIR set in the environment when using a non-standard name for the git dir. Hm?

Björn
Previous: Junio C HamanoNext: martin f. krafft
Message 5 of 9 in “Export GIT_DIR after setting it”
  1. Export GIT_DIR after setting itmartin f. krafft, May 14, 2008
  2. Junio C HamanoMay 15, 2008
  3. martin f. krafftMay 15, 2008
  4. Junio C HamanoMay 15, 2008
  5. Björn SteinbrinkMay 15, 2008
  6. martin f. krafftMay 15, 2008
  7. Björn SteinbrinkMay 15, 2008
  8. martin f. krafftMay 16, 2008
  9. martin f. krafftMay 20, 2008

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.