MCPcopy Create free account
hub / github.com/git/git / location_options_init

Function location_options_init

builtin/config.c:929–1009  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

927}
928
929static void location_options_init(struct config_location_options *opts,
930 const char *prefix)
931{
932 if (!opts->source.file)
933 opts->source.file = opts->file_to_free =
934 xstrdup_or_null(getenv(CONFIG_ENVIRONMENT));
935
936 if (opts->use_global_config + opts->use_system_config +
937 opts->use_local_config + opts->use_worktree_config +
938 !!opts->source.file + !!opts->source.blob > 1) {
939 error(_("only one config file at a time"));
940 exit(129);
941 }
942
943 if (!startup_info->have_repository) {
944 if (opts->use_local_config)
945 die(_("--local can only be used inside a git repository"));
946 if (opts->source.blob)
947 die(_("--blob can only be used inside a git repository"));
948 if (opts->use_worktree_config)
949 die(_("--worktree can only be used inside a git repository"));
950 }
951
952 if (opts->source.file &&
953 !strcmp(opts->source.file, "-")) {
954 opts->source.file = NULL;
955 opts->source.use_stdin = 1;
956 opts->source.scope = CONFIG_SCOPE_COMMAND;
957 }
958
959 if (opts->use_global_config) {
960 opts->source.file = opts->file_to_free = git_global_config();
961 if (!opts->source.file)
962 /*
963 * It is unknown if HOME/.gitconfig exists, so
964 * we do not know if we should write to XDG
965 * location; error out even if XDG_CONFIG_HOME
966 * is set and points at a sane location.
967 */
968 die(_("$HOME not set"));
969 opts->source.scope = CONFIG_SCOPE_GLOBAL;
970 } else if (opts->use_system_config) {
971 opts->source.file = opts->file_to_free = git_system_config();
972 opts->source.scope = CONFIG_SCOPE_SYSTEM;
973 } else if (opts->use_local_config) {
974 opts->source.file = opts->file_to_free = repo_git_path(the_repository, "config");
975 opts->source.scope = CONFIG_SCOPE_LOCAL;
976 } else if (opts->use_worktree_config) {
977 struct worktree **worktrees = get_worktrees();
978 if (the_repository->repository_format_worktree_config)
979 opts->source.file = opts->file_to_free =
980 repo_git_path(the_repository, "config.worktree");
981 else if (worktrees[0] && worktrees[1])
982 die(_("--worktree cannot be used with multiple "
983 "working trees unless the config\n"
984 "extension worktreeConfig is enabled. "
985 "Please read \"CONFIGURATION FILE\"\n"
986 "section in \"git help worktree\" for details"));

Callers 8

cmd_config_listFunction · 0.85
cmd_config_getFunction · 0.85
cmd_config_setFunction · 0.85
cmd_config_unsetFunction · 0.85
cmd_config_editFunction · 0.85
cmd_config_actionsFunction · 0.85

Calls 12

xstrdup_or_nullFunction · 0.85
errorFunction · 0.85
git_global_configFunction · 0.85
git_system_configFunction · 0.85
repo_git_pathFunction · 0.85
get_worktreesFunction · 0.85
free_worktreesFunction · 0.85
is_absolute_pathFunction · 0.85
prefix_filenameFunction · 0.85
repo_get_common_dirFunction · 0.85
repo_get_git_dirFunction · 0.85
dieFunction · 0.50

Tested by

no test coverage detected