/* * Note: This function is private for a reason, the '.gitmodules' file should * not be used as as a mechanism to retrieve arbitrary configuration stored in * the repository. * * Runs the provided config function on the '.gitmodules' file found in the * working directory. */ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void *data) { if (repo->worktree) { struct git_config_source config_source = { 0 }; const struct config_options opts = { 0 }; struct object_id oid; char *file; file = repo_worktree_path(repo, GITMODULES_FILE); if (file_exists(file)) { config_source.file = file; } else if (repo->submodule_prefix) { /* * When get_oid and config_with_options, used below, * become able to work on a specific repository, this * warning branch can be removed. */ warning("nested submodules without %s in the working tree are not supported yet", GITMODULES_FILE); goto out; } else if (get_oid(GITMODULES_INDEX, &oid) >= 0) { config_source.blob = GITMODULES_INDEX; } else if (get_oid(GITMODULES_HEAD, &oid) >= 0) { config_source.blob = GITMODULES_HEAD; } else { goto out; } config_with_options(fn, data, &config_source, &opts); out: free(file); } }
int git_get_config(const char *key, char *buffer, int size) { const char *home, *system, *programdata; struct config_buf buf; struct git_config_source config_source = { 0 }; struct config_options opts = { 0 }; opts.respect_includes = 1; buf.buf=buffer; buf.size=size; buf.seen = 0; buf.key = key; if (have_git_dir()) { opts.git_dir = get_git_dir(); char* local = git_pathdup("config"); config_source.file = local; config_with_options(get_config, &buf, &config_source, &opts); free(local); if (buf.seen) return !buf.seen; } home = get_windows_home_directory(); if (home) { char* global = xstrdup(mkpath("%s/.gitconfig", home)); if (global) { config_source.file = global; config_with_options(get_config, &buf, &config_source, &opts); free(global); if (buf.seen) return !buf.seen; } char* globalxdg = xstrdup(mkpath("%s/.config/git/config", home)); if (globalxdg) { config_source.file = globalxdg; config_with_options(get_config, &buf, &config_source, &opts); free(globalxdg); if (buf.seen) return !buf.seen; } } system = git_etc_gitconfig(); if (system) { config_source.file = system; config_with_options(get_config, &buf, &config_source, &opts); if (buf.seen) return !buf.seen; } programdata = git_program_data_config(); if (programdata) { config_source.file = programdata; config_with_options(get_config, &buf, &config_source, &opts); } return !buf.seen; }