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

Re: GIT_DIR vs. --git-dir

From
Jeff King <peff@peff.net>
Date
Sep 24, 2012, 14:49 UTC
Message-ID
<20120924144929.GA10349@sigill.intra.peff.net>
In-Reply-To
<5060097F.9050203@drmicha.warpmail.net>
On Mon, Sep 24, 2012 at 09:19:27AM +0200, Michael J Gruber wrote:
Show 19 quoted lines
> [mjg@localhost ~]$ GIT_DIR=~/.githome git rev-parse --show-toplevel
> /home/mjg
> 
> [mjg@localhost ~]$ git --git-dir=~/.githome rev-parse --show-toplevel
> fatal: Not a git repository: '~/.githome'
> 
> Huh? Ok, so most users probably would not try further and blame git, but:
> 
> [mjg@localhost ~]$ git --git-dir=/home/mjg/.githome rev-parse
> --show-toplevel
> /home/mjg
> 
> (All this is with core.worktree set to /home/mjg.)
> 
> So, while I do understand that we don't expand '~' in any of these cases
> and it's only a matter of bash tilde expansion kicking in or not, we
> might want to do something about it. (--git-dir=$HOME/.githome gets
> expanded, as well, and --git-dir=.githome works from the appropriate cwd
> only).
Bash is even weirder than you might think. Try this:
  $ echo ~/foo
  /home/peff/foo
  $ echo arg=~/foo
  arg=/home/peff/foo
  $ echo --arg=~/foo
  --arg=~/foo

That is, it expands on the right-hand side of an "=" (which, from my reading of the bash manual, means it considers it a word split), but refuses to expand after an "=" that is part of a long option.

The first one is definitely correct. It would be convenient for your use case to expand the third one, and it logically follows from the second one. However, dash does not expand the second one. I'm not sure if this is a bug in bash, or simply a grey area where the two shells do not agree.

But it makes me wonder if the world would be better served by a bash option to always enable tilde expansion after an "=". That would solve your issue, and it would make the same feature work for every other git long option, as well as for other programs.

-Peff
Previous: Michael J GruberNext: Michael J Gruber
Message 15 of 17 in “GIT_DIR vs. --git-dir”
  1. Michael J GruberSep 24, 2012
  2. Nguyen Thai Ngoc DuySep 24, 2012
  3. Michael J GruberSep 24, 2012
  4. Nguyen Thai Ngoc DuySep 24, 2012
  5. Michael J GruberSep 24, 2012
  6. git: expand user path in --git-dirMichael J Gruber, Sep 24, 2012
  7. Jeff KingSep 24, 2012
  8. Michael J GruberSep 24, 2012
  9. Junio C HamanoSep 24, 2012
  10. Jan EngelhardtSep 25, 2012
  11. Michael J GruberSep 25, 2012
  12. Andreas SchwabSep 24, 2012
  13. Junio C HamanoSep 24, 2012
  14. Michael J GruberSep 24, 2012
  15. Jeff KingSep 24, 2012
  16. Michael J GruberSep 24, 2012
  17. Andreas SchwabSep 24, 2012

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.