]> git.proxmox.com Git - libgit2.git/commitdiff
It is okay to not have a .gitconfig file
authorRussell Belfer <rb@github.com>
Tue, 20 Nov 2012 18:24:18 +0000 (10:24 -0800)
committerRussell Belfer <rb@github.com>
Tue, 20 Nov 2012 18:24:18 +0000 (10:24 -0800)
Opening a repo is generating an error if you don't have a
.gitconfig file in your home directory, but that should be
legal.

src/config.c
src/repository.c

index 412965b73e3c7e3c28f7ca73432e3dce2a82600c..fc9ea65fe9ba730f4f13ab4509d1f0ea7d172786 100644 (file)
@@ -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;
        }
 
index 38382a9ba1367692abd9f32eb62af38d0d70eccb..92eb6e11d34ed1136db2c1e598dc668fd1803aae 100644 (file)
@@ -450,37 +450,44 @@ 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;
 
        *out = cfg;
        return 0;
@@ -489,7 +496,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)