Skip to content

Commit

Permalink
git_config(): not having a per-repo config file is not an error
Browse files Browse the repository at this point in the history
Currently git_config() returns an error if there is no repo config file
available (cwd is not a git repo); it will correctly parse the system
and global config files, but still return an error.

It doesn't affect anything else since almost nobody is checking for the
return code (with the exception of 'git remote update').

A reorganization in 'git config' would benefit from being able to
properly detect errors in git_config() without the noise generated when
cwd is not a git repo.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Felipe Contreras authored and Junio C Hamano committed Feb 22, 2009
1 parent 414f2e5 commit aa38740
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,28 +637,37 @@ int git_config_global(void)

int git_config(config_fn_t fn, void *data)
{
int ret = 0;
int ret = 0, found = 0;
char *repo_config = NULL;
const char *home = NULL;

/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
if (config_exclusive_filename)
return git_config_from_file(fn, config_exclusive_filename, data);
if (git_config_system() && !access(git_etc_gitconfig(), R_OK))
if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) {
ret += git_config_from_file(fn, git_etc_gitconfig(),
data);
found += 1;
}

home = getenv("HOME");
if (git_config_global() && home) {
char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
if (!access(user_config, R_OK))
if (!access(user_config, R_OK)) {
ret += git_config_from_file(fn, user_config, data);
found += 1;
}
free(user_config);
}

repo_config = git_pathdup("config");
ret += git_config_from_file(fn, repo_config, data);
if (!access(repo_config, R_OK)) {
ret += git_config_from_file(fn, repo_config, data);
found += 1;
}
free(repo_config);
if (found == 0)
return -1;
return ret;
}

Expand Down

0 comments on commit aa38740

Please sign in to comment.