git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* BUG: Git path --config doesn't work with ~ symbol
@ 2021-05-05 18:06 Theodor Negrescu
  2021-05-05 18:13 ` Theodor Negrescu
  2021-05-05 18:14 ` Jeff King
  0 siblings, 2 replies; 9+ messages in thread
From: Theodor Negrescu @ 2021-05-05 18:06 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: BUG: Git path --config doesn't work with ~ symbol
  2021-05-05 18:06 BUG: Git path --config doesn't work with ~ symbol Theodor Negrescu
@ 2021-05-05 18:13 ` Theodor Negrescu
  2021-05-05 18:14 ` Jeff King
  1 sibling, 0 replies; 9+ messages in thread
From: Theodor Negrescu @ 2021-05-05 18:13 UTC (permalink / raw)
  To: git

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:
>
> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: BUG: Git path --config doesn't work with ~ symbol
  2021-05-05 18:06 BUG: Git path --config doesn't work with ~ symbol Theodor Negrescu
  2021-05-05 18:13 ` Theodor Negrescu
@ 2021-05-05 18:14 ` Jeff King
  2021-05-05 18:21   ` Eric Sunshine
  1 sibling, 1 reply; 9+ messages in thread
From: Jeff King @ 2021-05-05 18:14 UTC (permalink / raw)
  To: Theodor Negrescu; +Cc: git

On Wed, May 05, 2021 at 09:06:12PM +0300, Theodor Negrescu wrote:

> 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

> [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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: BUG: Git path --config doesn't work with ~ symbol
  2021-05-05 18:14 ` Jeff King
@ 2021-05-05 18:21   ` Eric Sunshine
  2021-05-05 18:30     ` Theodor Negrescu
  2021-05-05 18:32     ` Jeff King
  0 siblings, 2 replies; 9+ messages in thread
From: Eric Sunshine @ 2021-05-05 18:21 UTC (permalink / raw)
  To: Jeff King; +Cc: Theodor Negrescu, Git List

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: BUG: Git path --config doesn't work with ~ symbol
  2021-05-05 18:21   ` Eric Sunshine
@ 2021-05-05 18:30     ` Theodor Negrescu
  2021-05-05 18:35       ` Jeff King
  2021-05-05 18:32     ` Jeff King
  1 sibling, 1 reply; 9+ messages in thread
From: Theodor Negrescu @ 2021-05-05 18:30 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Jeff King, Git List

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:
>
> 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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: BUG: Git path --config doesn't work with ~ symbol
  2021-05-05 18:21   ` Eric Sunshine
  2021-05-05 18:30     ` Theodor Negrescu
@ 2021-05-05 18:32     ` Jeff King
  1 sibling, 0 replies; 9+ messages in thread
From: Jeff King @ 2021-05-05 18:32 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Theodor Negrescu, Git List

On Wed, May 05, 2021 at 02:21:38PM -0400, Eric Sunshine wrote:

> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: BUG: Git path --config doesn't work with ~ symbol
  2021-05-05 18:30     ` Theodor Negrescu
@ 2021-05-05 18:35       ` Jeff King
  2021-05-05 18:59         ` Theodor Negrescu
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff King @ 2021-05-05 18:35 UTC (permalink / raw)
  To: Theodor Negrescu; +Cc: Eric Sunshine, Git List

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: BUG: Git path --config doesn't work with ~ symbol
  2021-05-05 18:35       ` Jeff King
@ 2021-05-05 18:59         ` Theodor Negrescu
  2021-05-05 19:01           ` Jeff King
  0 siblings, 1 reply; 9+ messages in thread
From: Theodor Negrescu @ 2021-05-05 18:59 UTC (permalink / raw)
  To: Jeff King; +Cc: Eric Sunshine, Git List

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:
>
> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: BUG: Git path --config doesn't work with ~ symbol
  2021-05-05 18:59         ` Theodor Negrescu
@ 2021-05-05 19:01           ` Jeff King
  0 siblings, 0 replies; 9+ messages in thread
From: Jeff King @ 2021-05-05 19:01 UTC (permalink / raw)
  To: Theodor Negrescu; +Cc: Eric Sunshine, Git List

On Wed, May 05, 2021 at 09:59:58PM +0300, Theodor Negrescu wrote:

> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-05-05 19:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05 18:06 BUG: Git path --config doesn't work with ~ symbol Theodor Negrescu
2021-05-05 18:13 ` Theodor Negrescu
2021-05-05 18:14 ` Jeff King
2021-05-05 18:21   ` Eric Sunshine
2021-05-05 18:30     ` Theodor Negrescu
2021-05-05 18:35       ` Jeff King
2021-05-05 18:59         ` Theodor Negrescu
2021-05-05 19:01           ` Jeff King
2021-05-05 18:32     ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).