| 927 | } |
| 928 | |
| 929 | static 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")); |
no test coverage detected