@@ -370,9 +370,9 @@ names do not conflict with those that are used by Git itself and
other popular tools, and describe them in your documentation.
Variables marked with '(Protected config only)' are only respected when
-they are specified in protected configuration. This includes global and
-system-level config, and excludes repository config, the command line
-option `-c`, and environment variables. For more details, see the
+they are specified in protected configuration. This includes global,
+system-level config, the command line option `-c`, and environment
+variables, and excludes repository config. For more details, see the
'protected configuration' entry in linkgit:gitglossary[7].
include::config/advice.txt[]
@@ -494,12 +494,12 @@ Protected configuration includes:
- system-level config, e.g. `/etc/git/config`
- global config, e.g. `$XDG_CONFIG_HOME/git/config` and
`$HOME/.gitconfig`
+- the command line option `-c` and its equivalent environment variables
+
Protected configuration excludes:
+
- repository config, e.g. `$GIT_DIR/config` and
`$GIT_DIR/config.worktree`
-- the command line option `-c` and its equivalent environment variables
[[def_reachable]]reachable::
All of the ancestors of a given <<def_commit,commit>> are said to be
@@ -2373,6 +2373,11 @@ int git_configset_add_file(struct config_set *cs, const char *filename)
return git_config_from_file(config_set_callback, filename, cs);
}
+int git_configset_add_parameters(struct config_set *cs)
+{
+ return git_config_from_parameters(config_set_callback, cs);
+}
+
int git_configset_get_value(struct config_set *cs, const char *key, const char **value)
{
const struct string_list *values = NULL;
@@ -2628,6 +2633,7 @@ static void read_protected_config(void)
git_configset_add_file(the_repository->protected_config, system_config);
git_configset_add_file(the_repository->protected_config, xdg_config);
git_configset_add_file(the_repository->protected_config, user_config);
+ git_configset_add_parameters(the_repository->protected_config);
free(system_config);
free(xdg_config);
@@ -446,6 +446,15 @@ void git_configset_init(struct config_set *cs);
*/
int git_configset_add_file(struct config_set *cs, const char *filename);
+/**
+ * Parses command line options and environment variables, and adds the
+ * variable-value pairs to the `config_set`. Returns 0 on success, or -1
+ * if there is an error in parsing. The caller decides whether to free
+ * the incomplete configset or continue using it when the function
+ * returns -1.
+ */
+int git_configset_add_parameters(struct config_set *cs);
+
/**
* Finds and returns the value list, sorted in order of increasing priority
* for the configuration variable `key` and config set `cs`. When the
@@ -16,24 +16,20 @@ test_expect_success 'safe.directory is not set' '
expect_rejected_dir
'
-test_expect_success 'ignoring safe.directory on the command line' '
- test_must_fail git -c safe.directory="$(pwd)" status 2>err &&
- grep "unsafe repository" err
+test_expect_success 'safe.directory on the command line' '
+ git -c safe.directory="$(pwd)" status
'
-test_expect_success 'ignoring safe.directory in the environment' '
- test_must_fail env GIT_CONFIG_COUNT=1 \
- GIT_CONFIG_KEY_0="safe.directory" \
- GIT_CONFIG_VALUE_0="$(pwd)" \
- git status 2>err &&
- grep "unsafe repository" err
+test_expect_success 'safe.directory in the environment' '
+ env GIT_CONFIG_COUNT=1 \
+ GIT_CONFIG_KEY_0="safe.directory" \
+ GIT_CONFIG_VALUE_0="$(pwd)" \
+ git status
'
-test_expect_success 'ignoring safe.directory in GIT_CONFIG_PARAMETERS' '
- test_must_fail env \
- GIT_CONFIG_PARAMETERS="${SQ}safe.directory${SQ}=${SQ}$(pwd)${SQ}" \
- git status 2>err &&
- grep "unsafe repository" err
+test_expect_success 'safe.directory in GIT_CONFIG_PARAMETERS' '
+ env GIT_CONFIG_PARAMETERS="${SQ}safe.directory${SQ}=${SQ}$(pwd)${SQ}" \
+ git status
'
test_expect_success 'ignoring safe.directory in repo config' '
@@ -56,8 +56,7 @@ test_expect_success 'discovery.bare on the command line' '
git config --global discovery.bare never &&
(
cd outer-repo/bare-repo &&
- test_must_fail git -c discovery.bare=always rev-parse --git-dir 2>err &&
- grep "discovery.bare" err
+ git -c discovery.bare=always rev-parse --git-dir
)
'