I guess the HOME environment variable is not set in the scope of your
program and hence git cannot find $HOME/.gitconfig
Markus
Then I wonder how you can set and query global git config options, it
doesn't work for me without %HOME% on cmd.exe, which is no surprise
after looking into the sources.
Could you please set %HOME% and test again?
> - there is a %HOMEPATH% in both which I think is
> the window's equivalent.
And there is %HOMEDRIVE% and these concatenated together seem to form
%USERPROFILE%, at least for me.
Markus
Well, from the source and because it doesn't work for me.
Can you investigate, where (in which path in the filesystem) your global
.gitconfig exactly is, when you do your "git config --global
testing.testGlobal true", which works for you without %HOME%?
> ... Is git (when called) cause
> itself to form a new shell or similar which wraps the environmental
> variables it needs?
The parts that are written in C, i.e. the built-ins like git-config,
shouldn't need a shell.
> What I'll do is try to get a test sequence put together tonight /
> tomorrow morning to work out why loading a global variable works in
> cmd.exe without %HOME% being set
I just tried some things under Linux.
1) default, $HOME set to /home/markus
$ git config --global section.key value
worked as expected, of course
2)
$ export HOME=
$ git config --global section.key value
error: could not lock config file /.gitconfig
So here git wants to use /.gitconfig, where only root has access to.
3)
$ unset HOME
$ git config --global section.key value
$ fatal: $HOME not set
The relevant part of the source with 2 comments from me:
char *home = getenv("HOME");
if (home) {
/* 1) and 2) go here */
char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
config_exclusive_filename = user_config;
} else {
/* 3) goes here */
die("$HOME not set");
}
Maybe, although %HOME% is not set, cmd.exe (sometimes?) treats it as an
empty string and writes to /.gitconfig, which then will become C:\.gitconfig?
I think I can remember having seen C:\.gitconfig under Windows at
work, but now under Windows in Qemu I get the expected error "fatal:
$HOME not set". Maybe you have C:\.gitconfig as well on your drive?
Markus
The issue seems to be that when %HOME% was not set when git is called
as a process (through a start process command) then you cant get at
git global variables.
This is because in builtin-config.c there is some code which says
literally "get the HOME parameter".
However when I am in the cmd shell (cmd.exe) on both my XP computer,
my Vista 64 and my Vista 32 computers, this seems to work fine without
the %HOME% variable being set.
My .gitconfig file is (on my vista 32 computer) stored in my HOMEPATH
location (c:\users\syn\), and there is no .gitconfig file in the root
of C: (which would happen if %HOME% was interpreted as being empty and
"/.gitconfig" gets translated to c:\gitconfig)
Finally that this behaviour is different to Markus's on his Windows
test environment.
I streamlined my "git test program" so that what it does now is 1)
print out the environmental variable of HOME in *its* process,
followed by the environmental variable that is set in the start.info
of its child process (the git process) and finally, the results of the
"git config section.key".
Hope that helps
Syn.
Demonstration
C:\test>echo %HOME%
%HOME%
C:\test>git config --global section.key value
C:\test>git config section.key
value
C:\test>GitTestApp.exe
env. HOME value ]
StartInfo Home ]
section.key ]
C:\test>type c:\Users\syn\.gitconfig
[user]
name = Syn
<snip snip snip>
[testing]
testglobal = true
[section]
key = value
C:\test>set HOME=c:\users\Syn
C:\test>echo %HOME%
c:\users\Syn
C:\test>git config section.key
value
C:\test>GitTestApp.exe
env. HOME value ] c:\users\Syn
StartInfo Home ]c:\users\Syn
section.key ] value
/// Just confirming it a second time...
C:\test>set HOME=
C:\test>echo %HOME%
%HOME%
C:\test>GitTestApp.exe
env. HOME value ]
StartInfo Home ]
section.key ]
C:\test>git config section.key
value
On Fri, 10 Apr 2009, Dr Syn wrote:
> The issue seems to be that when %HOME% was not set when git is called as
> a process (through a start process command) then you cant get at git
> global variables.
If HOME is unset, it is set to the value of $USERPROFILE (or in cmd speak:
%USERPROFILE%).
Hth,
Dscho
For msys git bash, but not for cmd.exe
I was just reminded of this message when fetching the latest msysgit
with the commit "Add /git-cmd.bat, a shortcut to launch cmd with the
PATH set up properly".
Markus
On Sat, 18 Apr 2009, Markus Heidelberg wrote:
> Johannes Schindelin, 14.04.2009:
>
> > On Fri, 10 Apr 2009, Dr Syn wrote:
> >
> > > The issue seems to be that when %HOME% was not set when git is
> > > called as a process (through a start process command) then you cant
> > > get at git global variables.
> >
> > If HOME is unset, it is set to the value of $USERPROFILE (or in cmd
> > speak: %USERPROFILE%).
>
> For msys git bash, but not for cmd.exe
But from cmd.exe, you should call git.cmd and gitk.cmd from /cmd/, not
what is in /bin/...
Ciao,
Dscho
Oh, thanks, didn't know that. I installed without touching PATH and
manually added bin/ to it. Now I know, why I had to set HOME manually, too.
And I wondered how the installer would accomplish "Only Git will be
added to your PATH", now that's clear :)
In fact, just this week it occured the first time that I needed to start
gitk from cmd.exe and I wondered why it's not in bin/ but cmd/. Now
that's clear as well.
Markus