@matheusbsbs / matheus-bagliano / commits / aa38740791
Fork 0

git_config(): not having a per-repo config file is not an error

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>

Felipe Contreras committed Feb 21, 2009 at 02:48 UTC aa387407914a574d41df4d64328498d093337ccd
1 file changed +13 -4
config.c
+13 -4
@@ -637,28 +637,37 @@ int git_config_global(void)
637
638 int git_config(config_fn_t fn, void *data)
639 {
640 - int ret = 0;
640 + int ret = 0, found = 0;
641 char *repo_config = NULL;
642 const char *home = NULL;
643
644 /* Setting $GIT_CONFIG makes git read _only_ the given config file. */
645 if (config_exclusive_filename)
646 return git_config_from_file(fn, config_exclusive_filename, data);
647 - if (git_config_system() && !access(git_etc_gitconfig(), R_OK))
647 + if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) {
648 ret += git_config_from_file(fn, git_etc_gitconfig(),
649 data);
650 + found += 1;
651 + }
652
653 home = getenv("HOME");
654 if (git_config_global() && home) {
655 char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
654 - if (!access(user_config, R_OK))
656 + if (!access(user_config, R_OK)) {
657 ret += git_config_from_file(fn, user_config, data);
658 + found += 1;
659 + }
660 free(user_config);
661 }
662
663 repo_config = git_pathdup("config");
660 - ret += git_config_from_file(fn, repo_config, data);
664 + if (!access(repo_config, R_OK)) {
665 + ret += git_config_from_file(fn, repo_config, data);
666 + found += 1;
667 + }
668 free(repo_config);
669 + if (found == 0)
670 + return -1;
671 return ret;
672 }
673