Skip to content

Commit e6f1550

Browse files
committed
Merge branch 'jn/warn-on-inaccessible-loosen' into maint
When attempting to read the XDG-style $HOME/.config/git/config and finding that $HOME/.config/git is a file, we gave a wrong error message, instead of treating the case as "a custom config file does not exist there" and moving on. * jn/warn-on-inaccessible-loosen: config: exit on error accessing any config file doc: advertise GIT_CONFIG_NOSYSTEM config: treat user and xdg config permission problems as errors config, gitignore: failure to access with ENOTDIR is ok
2 parents 22fd1c8 + 8f2bbe4 commit e6f1550

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

Documentation/git-config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ GIT_CONFIG::
240240
Using the "--global" option forces this to ~/.gitconfig. Using the
241241
"--system" option forces this to $(prefix)/etc/gitconfig.
242242

243+
GIT_CONFIG_NOSYSTEM::
244+
Whether to skip reading settings from the system-wide
245+
$(prefix)/etc/gitconfig file. See linkgit:git[1] for details.
246+
243247
See also <<FILES>>.
244248

245249

Documentation/git.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,14 @@ for further details.
772772
and read the password from its STDOUT. See also the 'core.askpass'
773773
option in linkgit:git-config[1].
774774

775+
'GIT_CONFIG_NOSYSTEM'::
776+
Whether to skip reading settings from the system-wide
777+
`$(prefix)/etc/gitconfig` file. This environment variable can
778+
be used along with `$HOME` and `$XDG_CONFIG_HOME` to create a
779+
predictable environment for a picky script, or you can set it
780+
temporarily to avoid using a buggy `/etc/gitconfig` file while
781+
waiting for someone with sufficient permissions to fix it.
782+
775783
'GIT_FLUSH'::
776784
If this environment variable is set to "1", then commands such
777785
as 'git blame' (in incremental mode), 'git rev-list', 'git log',

config.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int handle_path_include(const char *path, struct config_include_data *inc
5858
path = buf.buf;
5959
}
6060

61-
if (!access_or_warn(path, R_OK)) {
61+
if (!access_or_die(path, R_OK)) {
6262
if (++inc->depth > MAX_INCLUDE_DEPTH)
6363
die(include_depth_advice, MAX_INCLUDE_DEPTH, path,
6464
cf && cf->name ? cf->name : "the command line");
@@ -938,23 +938,23 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
938938

939939
home_config_paths(&user_config, &xdg_config, "config");
940940

941-
if (git_config_system() && !access_or_warn(git_etc_gitconfig(), R_OK)) {
941+
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK)) {
942942
ret += git_config_from_file(fn, git_etc_gitconfig(),
943943
data);
944944
found += 1;
945945
}
946946

947-
if (xdg_config && !access_or_warn(xdg_config, R_OK)) {
947+
if (xdg_config && !access_or_die(xdg_config, R_OK)) {
948948
ret += git_config_from_file(fn, xdg_config, data);
949949
found += 1;
950950
}
951951

952-
if (user_config && !access_or_warn(user_config, R_OK)) {
952+
if (user_config && !access_or_die(user_config, R_OK)) {
953953
ret += git_config_from_file(fn, user_config, data);
954954
found += 1;
955955
}
956956

957-
if (repo_config && !access_or_warn(repo_config, R_OK)) {
957+
if (repo_config && !access_or_die(repo_config, R_OK)) {
958958
ret += git_config_from_file(fn, repo_config, data);
959959
found += 1;
960960
}

git-compat-util.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,12 @@ int rmdir_or_warn(const char *path);
637637
*/
638638
int remove_or_warn(unsigned int mode, const char *path);
639639

640-
/* Call access(2), but warn for any error besides ENOENT. */
640+
/*
641+
* Call access(2), but warn for any error except "missing file"
642+
* (ENOENT or ENOTDIR).
643+
*/
641644
int access_or_warn(const char *path, int mode);
645+
int access_or_die(const char *path, int mode);
642646

643647
/* Warn on an inaccessible file that ought to be accessible */
644648
void warn_on_inaccessible(const char *path);

wrapper.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,19 @@ void warn_on_inaccessible(const char *path)
411411
int access_or_warn(const char *path, int mode)
412412
{
413413
int ret = access(path, mode);
414-
if (ret && errno != ENOENT)
414+
if (ret && errno != ENOENT && errno != ENOTDIR)
415415
warn_on_inaccessible(path);
416416
return ret;
417417
}
418418

419+
int access_or_die(const char *path, int mode)
420+
{
421+
int ret = access(path, mode);
422+
if (ret && errno != ENOENT && errno != ENOTDIR)
423+
die_errno(_("unable to access '%s'"), path);
424+
return ret;
425+
}
426+
419427
struct passwd *xgetpwuid_self(void)
420428
{
421429
struct passwd *pw;

0 commit comments

Comments
 (0)