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

Re: BUG: Git path --config doesn't work with ~ symbol

From
Jeff King <peff@peff.net>
Date
May 5, 2021, 18:32 UTC
Message-ID
<YJLkw59nxAU6/vVT@coredump.intra.peff.net>
In-Reply-To
<CAPig+cTX179z5MrTvSmgYGzZdc4xz=2G_ffHsyVOXsKVHrL93w@mail.gmail.com>
On Wed, May 05, 2021 at 02:21:38PM -0400, Eric Sunshine wrote:
Show 19 quoted lines
> On Wed, May 5, 2021 at 2:14 PM Jeff King <peff@peff.net> wrote:
> > On Wed, May 05, 2021 at 09:06:12PM +0300, Theodor Negrescu wrote:
> > > I ran the command "git config --file ~/git-settings/.gitconfig -l"
> > > (git-settings is a repo where I keep my config, the global one is just
> > > an include)
> >
> > I don't think this is a bug in git-config. It is generally the shell
> > that is responsible for expanding "~" and passing along the result to
> > commands. E.g.:
> >
> >   $ strace -e execve git config --file ~/foo --list
> >   execve("/home/peff/local/git/current/bin/git", ["git", "config", "--file", "/home/peff/foo", "--list"], 0x7ffc10a88130 /* 55 vars */) = 0
> >
> > I'd guess this might be related to Windows somehow. Are you entering the
> > command in a bash shell, or via some other mechanism?
> 
> Is OPT_FILENAME supposed to handle tilde-expansion? I ask because
> git-config is using OPT_STRING for this option, whereas other commands
> use OPT_FILENAME for their `--file` options.

No, I don't think so. The point of OPT_FILENAME() is that it handles the directory-change from setting up the git directory before we even the the cmd_*() function.

But that isn't necessary here, because cmd_config() applies the prefix manually. So this works as expected:

  $ git init
  $ mkdir subdir
  $ git config --file=foo my.dir root
  $ git config --file=subdir/foo my.dir sub
  $ git config --file=foo --list
  my.dir=root
  $ cd subdir
  $ git config --file=foo --list
  my.dir=sub

Possibly the code could be simplified a little by using OPT_FILENAME(), though.

-Peff
Previous: Jeff King
Message 9 of 9 in “BUG: Git path --config doesn't work with ~ symbol”
  1. Theodor NegrescuMay 5, 2021
  2. Theodor NegrescuMay 5, 2021
  3. Jeff KingMay 5, 2021
  4. Eric SunshineMay 5, 2021
  5. Theodor NegrescuMay 5, 2021
  6. Jeff KingMay 5, 2021
  7. Theodor NegrescuMay 5, 2021
  8. Jeff KingMay 5, 2021
  9. Jeff KingMay 5, 2021

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.