threads / bug / 55626

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

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

## tl;dr

9 messages between May 5, 2021 and May 5, 2021.

replies: 8people: 3as markdown or json

Theodor Negrescu· May 5, 2021, 18:06 UTC · lore

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

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)

What did you expect to happen? (Expected behavior)
It would list the settings in the file.
What happened instead? (Actual behavior)

fatal: unable to read config file '~/git-settings/.gitconfig': No such file or directory

What's different between what you expected and what actually happened?
The ~ symbol should point to my home folder.
Anything else you want to add:

"git config --file ~/.gitconfig -l" doesn't work either so the ~ symbol is the problem. fatal: unable to read config file '~/.gitconfig': No such file or directory "git config --file .gitconfig -l" works when I run it from my home folder or from git-settings so the --file argument is working.

[System Info] git version: git version 2.31.1.windows.1 cpu: x86_64 built from commit: c5f0be26a7e3846e3b6268d1c6c4800d838c6bbb sizeof-long: 4 sizeof-size_t: 8 shell-path: /bin/sh feature: fsmonitor--daemon uname: Windows 10.0 19042 compiler info: gnuc: 10.2 libc info: no libc information available $SHELL (typically, interactive shell): <unset>

[Enabled Hooks] not run from a git repository - no hooks to show

Theodor Negrescu· May 5, 2021, 18:13 UTC · re: Theodor Negrescu · lore

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

I meant Git config --file!! Sorry, I wrote the wrong thing in the title.

On Wed, May 5, 2021 at 9:06 PM Theodor Negrescu <theodor.negrescu@gmail.com> wrote:

Show 48 quoted lines
>
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
>
> What did you do before the bug happened? (Steps to reproduce your issue)
>
> 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)
>
> What did you expect to happen? (Expected behavior)
>
> It would list the settings in the file.
>
> What happened instead? (Actual behavior)
>
> fatal: unable to read config file '~/git-settings/.gitconfig': No such
> file or directory
>
> What's different between what you expected and what actually happened?
>
> The ~ symbol should point to my home folder.
>
> Anything else you want to add:
>
> "git config --file ~/.gitconfig -l" doesn't work either so the ~
> symbol is the problem.
> fatal: unable to read config file '~/.gitconfig': No such file or directory
> "git config --file .gitconfig -l" works when I run it from my home
> folder or from git-settings so the --file argument is working.
>
> [System Info]
> git version:
> git version 2.31.1.windows.1
> cpu: x86_64
> built from commit: c5f0be26a7e3846e3b6268d1c6c4800d838c6bbb
> sizeof-long: 4
> sizeof-size_t: 8
> shell-path: /bin/sh
> feature: fsmonitor--daemon
> uname: Windows 10.0 19042
> compiler info: gnuc: 10.2
> libc info: no libc information available
> $SHELL (typically, interactive shell): <unset>
>
>
> [Enabled Hooks]
> not run from a git repository - no hooks to show
Jeff King· May 5, 2021, 18:14 UTC · re: Theodor Negrescu · lore

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

On Wed, May 05, 2021 at 09:06:12PM +0300, Theodor Negrescu wrote:
Show 18 quoted lines
> What did you do before the bug happened? (Steps to reproduce your issue)
> 
> 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)
> 
> What did you expect to happen? (Expected behavior)
> 
> It would list the settings in the file.
> 
> What happened instead? (Actual behavior)
> 
> fatal: unable to read config file '~/git-settings/.gitconfig': No such
> file or directory
> 
> What's different between what you expected and what actually happened?
> 
> The ~ symbol should point to my home folder.

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
Show 13 quoted lines
> [System Info]
> git version:
> git version 2.31.1.windows.1
> cpu: x86_64
> built from commit: c5f0be26a7e3846e3b6268d1c6c4800d838c6bbb
> sizeof-long: 4
> sizeof-size_t: 8
> shell-path: /bin/sh
> feature: fsmonitor--daemon
> uname: Windows 10.0 19042
> compiler info: gnuc: 10.2
> libc info: no libc information available
> $SHELL (typically, interactive shell): <unset>

I'd guess this might be related to Windows somehow. Are you entering the command in a bash shell, or via some other mechanism?

-Peff
Eric Sunshine· May 5, 2021, 18:21 UTC · re: Jeff King · lore

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

On Wed, May 5, 2021 at 2:14 PM Jeff King <peff@peff.net> wrote:
Show 14 quoted lines
> 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.

Theodor Negrescu· May 5, 2021, 18:30 UTC · re: Eric Sunshine · lore

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

I'm using powershell, but usually ~ works there. Typing "cd ~" would work for example. Also I tried using the command as an alias and it still didn't work.

On Wed, May 5, 2021 at 9:21 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 20 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.
Jeff King· May 5, 2021, 18:35 UTC · re: Theodor Negrescu · lore

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

On Wed, May 05, 2021 at 09:30:21PM +0300, Theodor Negrescu wrote:
> I'm using powershell, but usually ~ works there. Typing "cd ~" would
> work for example.
> Also I tried using the command as an alias and it still didn't work.

I don't know anything about powershell, but generally "cd" is a builtin to the shell (because it is impacting the shell's environment). So it may be that powershell "cd" expands "~" itself, but that the shell doesn't expand it for executed commands.

There are some Windows folks who hang out on this list, so you may get a better response. But you might also ask in the Git for Windows mailing list:

  https://groups.google.com/g/git-for-windows
-Peff
Theodor Negrescu· May 5, 2021, 18:59 UTC · re: Jeff King · lore

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

You're right, "notepad ~/test.txt" doesn't work either.
I figured out a workaround:
[alias]
    cfg = "!git config --file $(echo ~)/git-settings/.gitconfig "
However what confuses me is that I also have
[core]
    hooksPath = ~/git-settings/hooks
and that ~ works. So why doesn't it work in config --file?
On Wed, May 5, 2021 at 9:35 PM Jeff King <peff@peff.net> wrote:
Show 19 quoted lines
>
> On Wed, May 05, 2021 at 09:30:21PM +0300, Theodor Negrescu wrote:
>
> > I'm using powershell, but usually ~ works there. Typing "cd ~" would
> > work for example.
> > Also I tried using the command as an alias and it still didn't work.
>
> I don't know anything about powershell, but generally "cd" is a builtin
> to the shell (because it is impacting the shell's environment). So it
> may be that powershell "cd" expands "~" itself, but that the shell
> doesn't expand it for executed commands.
>
> There are some Windows folks who hang out on this list, so you may get a
> better response. But you might also ask in the Git for Windows mailing
> list:
>
>   https://groups.google.com/g/git-for-windows
>
> -Peff
Jeff King· May 5, 2021, 19:01 UTC · re: Theodor Negrescu · lore

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

On Wed, May 05, 2021 at 09:59:58PM +0300, Theodor Negrescu wrote:
Show 8 quoted lines
> You're right, "notepad ~/test.txt" doesn't work either.
> I figured out a workaround:
> [alias]
>     cfg = "!git config --file $(echo ~)/git-settings/.gitconfig "
> However what confuses me is that I also have
> [core]
>     hooksPath = ~/git-settings/hooks
> and that ~ works. So why doesn't it work in config --file?

Some config options that refer to paths specifically expand "~", exactly because there is no shell involved when Git reads them.

-Peff
Jeff King· May 5, 2021, 18:32 UTC · re: Eric Sunshine · lore

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

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

← back to recent threads