Skip to content

Commit 2bcfa09

Browse files
committed
Merge branch 'kb/windows-wide-config'
2 parents 9c9dc30 + 3efe9db commit 2bcfa09

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

Documentation/config.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ the Git commands' behavior. The `.git/config` file in each repository
66
is used to store the configuration for that repository, and
77
`$HOME/.gitconfig` is used to store a per-user configuration as
88
fallback values for the `.git/config` file. The file `/etc/gitconfig`
9-
can be used to store a system-wide default configuration. On Windows,
10-
configuration can also be stored in `C:\ProgramData\Git\config`; This
11-
file will be used also by libgit2-based software.
9+
can be used to store a system-wide default configuration
10+
(`%PROGRAMDATA%/gitconfig` on Windows).
1211

1312
The configuration variables are used by both the Git plumbing
1413
and the porcelains. The variables are divided into sections, wherein

Documentation/git-config.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ See also <<FILES>>.
123123
For reading options: read only from system-wide `$(prefix)/etc/gitconfig`
124124
rather than from all available files.
125125
+
126+
On Windows, the system-wide config file is `%PROGRAMDATA%/gitconfig`.
127+
+
126128
See also <<FILES>>.
127129

128130
--local::
@@ -225,7 +227,7 @@ If not set explicitly with '--file', there are four files where
225227
'git config' will search for configuration options:
226228

227229
$(prefix)/etc/gitconfig::
228-
System-wide configuration file.
230+
System-wide configuration file (`%PROGRAMDATA%/gitconfig` on Windows).
229231

230232
$XDG_CONFIG_HOME/git/config::
231233
Second user-specific configuration file. If $XDG_CONFIG_HOME is not set

Documentation/git.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,8 @@ for further details.
940940

941941
'GIT_CONFIG_NOSYSTEM'::
942942
Whether to skip reading settings from the system-wide
943-
`$(prefix)/etc/gitconfig` file. This environment variable can
943+
`$(prefix)/etc/gitconfig` file (`%PROGRAMDATA%/gitconfig`
944+
on Windows). This environment variable can
944945
be used along with `$HOME` and `$XDG_CONFIG_HOME` to create a
945946
predictable environment for a picky script, or you can set it
946947
temporarily to avoid using a buggy `/etc/gitconfig` file while

Documentation/gitattributes.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ for a single user should be placed in a file specified by the
8484
Its default value is $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME
8585
is either not set or empty, $HOME/.config/git/attributes is used instead.
8686
Attributes for all users on a system should be placed in the
87-
`$(prefix)/etc/gitattributes` file.
87+
`$(prefix)/etc/gitattributes` file (`%PROGRAMDATA%/gitattributes` on
88+
Windows).
8889

8990
Sometimes you would need to override an setting of an attribute
9091
for a path to `Unspecified` state. This can be done by listing

config.mak.uname

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ endif
330330
ifeq ($(uname_S),Windows)
331331
GIT_VERSION := $(GIT_VERSION).MSVC
332332
pathsep = ;
333+
sysconfdir = /etc
333334
HAVE_ALLOCA_H = YesPlease
334335
NO_PREAD = YesPlease
335336
NEEDS_CRYPTO_WITH_SSL = YesPlease
@@ -484,6 +485,7 @@ ifeq ($(uname_S),NONSTOP_KERNEL)
484485
endif
485486
ifneq (,$(findstring MINGW,$(uname_S)))
486487
pathsep = ;
488+
sysconfdir = /etc
487489
HAVE_ALLOCA_H = YesPlease
488490
NO_PREAD = YesPlease
489491
NEEDS_CRYPTO_WITH_SSL = YesPlease
@@ -532,6 +534,10 @@ ifneq (,$(findstring MINGW,$(uname_S)))
532534
ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
533535
htmldir = share/doc/git/$(firstword $(subst -, ,$(GIT_VERSION)))/html
534536
prefix =
537+
# prevent conversion to Windows path on MSys1 (see
538+
# http://www.mingw.org/wiki/Posix_path_conversion)
539+
ETC_GITCONFIG = //etc\gitconfig
540+
ETC_GITATTRIBUTES = //etc\gitattributes
535541
INSTALL = /bin/install
536542
EXTLIBS += /mingw/lib/libz.a
537543
NO_R_TO_GCC_LINKER = YesPlease

exec_cmd.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,24 @@ char *system_path(const char *path)
1515
#endif
1616
struct strbuf d = STRBUF_INIT;
1717

18-
if (is_absolute_path(path))
18+
if (is_absolute_path(path)) {
19+
#ifdef _WIN32
20+
/*
21+
* On Windows (all variants), replace '/etc' with %PROGRAMDATA%
22+
* (or %ALLUSERSPROFILE% in case of Windows XP)
23+
*/
24+
if (!strncmp(path, "/etc/", 5)) {
25+
const char *sysconfdir = getenv("PROGRAMDATA");
26+
if (!sysconfdir)
27+
sysconfdir = getenv("ALLUSERSPROFILE");
28+
if (sysconfdir) {
29+
strbuf_addf(&d, "%s/%s", sysconfdir, path + 5);
30+
return strbuf_detach(&d, NULL);
31+
}
32+
}
33+
#endif
1934
return xstrdup(path);
35+
}
2036

2137
#ifdef RUNTIME_PREFIX
2238
assert(argv0_path);

0 commit comments

Comments
 (0)