diff options
author | Russell Belfer <rb@github.com> | 2012-11-20 15:02:06 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-11-20 15:02:06 -0800 |
commit | 54be4d57ed3cfbfb8c970f04422f840bcb731ddd (patch) | |
tree | faad955f7f6b8d0e079ff9860b647ac369a83229 | |
parent | f0ebf82e1afe4736dc294c16431c15685294f0b6 (diff) | |
parent | 38f7d026dce92ec6774a8d6e13499ea83461f287 (diff) | |
download | libgit2-54be4d57ed3cfbfb8c970f04422f840bcb731ddd.tar.gz |
Merge pull request #1092 from arrbee/legal-to-not-have-gitconfig
It is okay to not have a .gitconfig file
-rw-r--r-- | src/config.c | 2 | ||||
-rw-r--r-- | src/repository.c | 45 |
2 files changed, 28 insertions, 19 deletions
diff --git a/src/config.c b/src/config.c index 412965b73..fc9ea65fe 100644 --- a/src/config.c +++ b/src/config.c @@ -93,7 +93,7 @@ int git_config_add_file_ondisk( assert(cfg && path); if (!git_path_isfile(path)) { - giterr_set(GITERR_CONFIG, "File '%s' doesn't exists.", path); + giterr_set(GITERR_CONFIG, "Cannot find config file '%s'", path); return GIT_ENOTFOUND; } diff --git a/src/repository.c b/src/repository.c index 38382a9ba..f82dc108b 100644 --- a/src/repository.c +++ b/src/repository.c @@ -450,37 +450,46 @@ static int load_config( const char *xdg_config_path, const char *system_config_path) { + int error; git_buf config_path = GIT_BUF_INIT; git_config *cfg = NULL; assert(repo && out); - if (git_config_new(&cfg) < 0) - return -1; + if ((error = git_config_new(&cfg)) < 0) + return error; - if (git_buf_joinpath( - &config_path, repo->path_repository, GIT_CONFIG_FILENAME_INREPO) < 0) + error = git_buf_joinpath( + &config_path, repo->path_repository, GIT_CONFIG_FILENAME_INREPO); + if (error < 0) goto on_error; - if (git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, 0) < 0) + if ((error = git_config_add_file_ondisk( + cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, 0)) < 0 && + error != GIT_ENOTFOUND) goto on_error; git_buf_free(&config_path); - if (global_config_path != NULL) { - if (git_config_add_file_ondisk(cfg, global_config_path, GIT_CONFIG_LEVEL_GLOBAL, 0) < 0) - goto on_error; - } + if (global_config_path != NULL && + (error = git_config_add_file_ondisk( + cfg, global_config_path, GIT_CONFIG_LEVEL_GLOBAL, 0)) < 0 && + error != GIT_ENOTFOUND) + goto on_error; - if (xdg_config_path != NULL) { - if (git_config_add_file_ondisk(cfg, xdg_config_path, GIT_CONFIG_LEVEL_XDG, 0) < 0) - goto on_error; - } + if (xdg_config_path != NULL && + (error = git_config_add_file_ondisk( + cfg, xdg_config_path, GIT_CONFIG_LEVEL_XDG, 0)) < 0 && + error != GIT_ENOTFOUND) + goto on_error; - if (system_config_path != NULL) { - if (git_config_add_file_ondisk(cfg, system_config_path, GIT_CONFIG_LEVEL_SYSTEM, 0) < 0) - goto on_error; - } + if (system_config_path != NULL && + (error = git_config_add_file_ondisk( + cfg, system_config_path, GIT_CONFIG_LEVEL_SYSTEM, 0)) < 0 && + error != GIT_ENOTFOUND) + goto on_error; + + giterr_clear(); /* clear any lingering ENOTFOUND errors */ *out = cfg; return 0; @@ -489,7 +498,7 @@ on_error: git_buf_free(&config_path); git_config_free(cfg); *out = NULL; - return -1; + return error; } int git_repository_config__weakptr(git_config **out, git_repository *repo) |