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

Re: [PATCH] make git barf when an alias changes environment variables

From
MLMatthias Lederhofer <matled@gmx.net>
Date
Jun 13, 2007, 05:41 UTC
Message-ID
<20070613054136.GA27476@moooo.ath.cx>
In-Reply-To
<7vejkgh1jf.fsf@assigned-by-dhcp.pobox.com>
Junio C Hamano <gitster@pobox.com> wrote:
Show 11 quoted lines
> What does this patch do when you do this?
> 
> 	: Because I usually work with this repository...
>       $ GIT_DIR=$some_repository
>       $ export GIT_DIR
> 
>       : Then much later, I happen to visit another repository
>       : to take a peek...
> 	$ cd $somewhere_else
>       $ git --git-dir .git some-command
> 
This one has no alias involved as far as I see, so there is no change.

The patch makes git barf when an alias changes the environment (i.e. an alias uses --git-dir/--work-tree/--bare). When git has read the configuration file to find out about aliases setup_git_env has been called and a pointer returned by getenv("GIT_DIR") is already stored in a static pointer. If the environment variable is changed afterwards git might or might not use the new value depending on the implementation.

That is what my example shows: FreeBSD libc reuses the old memory location if the new value of an environment variable fits in the old place. Because setup_git_env uses xstrdup on the object dir and some other directories the old value is used for those but the new one is used for git_dir (which is just a pointer returned by getenv). This way HEAD is read from the new repository but objects are searched in the old repository.

Previous: Junio C Hamano
Message 3 of 3 in “make git barf when an alias changes environment variables”
  1. make git barf when an alias changes environment variablesMatthias Lederhofer, Jun 8, 2007
  2. Junio C HamanoJun 13, 2007
  3. Matthias LederhoferJun 13, 2007

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.