Skip to content

Commit 4f43e97

Browse files
committed
Merge branch 'jn/warn-on-inaccessible-loosen'
Deal with a situation where .config/git is a file and we notice .config/git/config is not readable due to ENOTDIR, not ENOENT. * 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 1965f8c + 8f2bbe4 commit 4f43e97

5 files changed

Lines changed: 31 additions & 7 deletions

File tree

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
@@ -777,6 +777,14 @@ for further details.
777777
and read the password from its STDOUT. See also the 'core.askpass'
778778
option in linkgit:git-config[1].
779779

780+
'GIT_CONFIG_NOSYSTEM'::
781+
Whether to skip reading settings from the system-wide
782+
`$(prefix)/etc/gitconfig` file. This environment variable can
783+
be used along with `$HOME` and `$XDG_CONFIG_HOME` to create a
784+
predictable environment for a picky script, or you can set it
785+
temporarily to avoid using a buggy `/etc/gitconfig` file while
786+
waiting for someone with sufficient permissions to fix it.
787+
780788
'GIT_FLUSH'::
781789
If this environment variable is set to "1", then commands such
782790
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");
@@ -940,23 +940,23 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
940940

941941
home_config_paths(&user_config, &xdg_config, "config");
942942

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

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

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

959-
if (repo_config && !access_or_warn(repo_config, R_OK)) {
959+
if (repo_config && !access_or_die(repo_config, R_OK)) {
960960
ret += git_config_from_file(fn, repo_config, data);
961961
found += 1;
962962
}

git-compat-util.h

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

657-
/* Call access(2), but warn for any error besides ENOENT. */
657+
/*
658+
* Call access(2), but warn for any error except "missing file"
659+
* (ENOENT or ENOTDIR).
660+
*/
658661
int access_or_warn(const char *path, int mode);
662+
int access_or_die(const char *path, int mode);
659663

660664
/* Warn on an inaccessible file that ought to be accessible */
661665
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)