config: Fix compilation in MSVC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
diff --git a/src/config.c b/src/config.c
index 2b2bdb0..b802ba5 100644
--- a/src/config.c
+++ b/src/config.c
@@ -303,7 +303,8 @@ int git_config_get_string(git_config *cfg, const char *name, const char **out)
{
file_internal *internal;
git_config_file *file;
- int i, error;
+ int error = GIT_ENOTFOUND;
+ unsigned int i;
if (cfg->files.length == 0)
return git__throw(GIT_EINVALIDARGS, "Cannot get variable value; no files open in the `git_config` instance");
@@ -311,11 +312,10 @@ int git_config_get_string(git_config *cfg, const char *name, const char **out)
for (i = 0; i < cfg->files.length; ++i) {
internal = git_vector_get(&cfg->files, i);
file = internal->file;
- error = file->get(file, name, out);
- if (error == GIT_SUCCESS)
- break;
+ if ((error = file->get(file, name, out)) == GIT_SUCCESS)
+ return GIT_SUCCESS;
}
- return error;
+ return git__throw(error, "Config value '%s' not found", name);
}
diff --git a/tests/t15-config.c b/tests/t15-config.c
index 78cd9b5..5e5b4b1 100644
--- a/tests/t15-config.c
+++ b/tests/t15-config.c
@@ -212,18 +212,11 @@ END_TEST
BEGIN_TEST(config10, "a repo's config overrides the global config")
git_repository *repo;
- char home_orig[GIT_PATH_MAX];
- char *home;
git_config *cfg;
int version;
- home = getenv("HOME");
- strcpy(home_orig, home);
- setenv("HOME", CONFIG_BASE, 1);
-
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- must_pass(git_repository_config(&cfg, repo, NULL, NULL));
- setenv("HOME", home_orig, 1);
+ must_pass(git_repository_config(&cfg, repo, CONFIG_BASE "/.gitconfig", NULL));
must_pass(git_config_get_int(cfg, "core.repositoryformatversion", &version));
must_be_true(version == 0);
git_config_free(cfg);