summaryrefslogtreecommitdiff
path: root/t/t1300-config.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t1300-config.sh')
-rwxr-xr-xt/t1300-config.sh241
1 files changed, 236 insertions, 5 deletions
diff --git a/t/t1300-config.sh b/t/t1300-config.sh
index 1a4156c704..e0dd5d65ce 100755
--- a/t/t1300-config.sh
+++ b/t/t1300-config.sh
@@ -5,6 +5,9 @@
test_description='Test git config in different settings'
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
. ./test-lib.sh
test_expect_success 'clear default config' '
@@ -672,6 +675,13 @@ test_expect_success 'invalid unit' '
test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual
'
+test_expect_success 'invalid unit boolean' '
+ git config commit.gpgsign "1true" &&
+ test_cmp_config 1true commit.gpgsign &&
+ test_must_fail git config --bool --get commit.gpgsign 2>actual &&
+ test_i18ngrep "bad boolean config value .1true. for .commit.gpgsign." actual
+'
+
test_expect_success 'line number is reported correctly' '
printf "[bool]\n\tvar\n" >invalid &&
test_must_fail git config -f invalid --path bool.var 2>actual &&
@@ -1046,8 +1056,8 @@ test_expect_success 'check split_cmdline return' "
echo foo > foo &&
git add foo &&
git commit -m 'initial commit' &&
- git config branch.master.mergeoptions 'echo \"' &&
- test_must_fail git merge master
+ git config branch.main.mergeoptions 'echo \"' &&
+ test_must_fail git merge main
"
test_expect_success 'git -c "key=value" support' '
@@ -1286,6 +1296,58 @@ test_expect_success 'git -c is not confused by empty environment' '
GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
'
+test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' '
+ v="${SQ}key.one=foo${SQ}" &&
+ v="$v ${SQ}key.two=bar${SQ}" &&
+ v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" &&
+ GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
+ cat >expect <<-EOF &&
+ key.one foo
+ key.two bar
+ key.ambiguous section.whatever=value
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' '
+ v="${SQ}key.one${SQ}=${SQ}foo${SQ}" &&
+ v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" &&
+ v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" &&
+ GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
+ cat >expect <<-EOF &&
+ key.one foo
+ key.two bar
+ key.ambiguous=section.whatever value
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'old and new-style entries can mix' '
+ v="${SQ}key.oldone=oldfoo${SQ}" &&
+ v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" &&
+ v="$v ${SQ}key.oldtwo=oldbar${SQ}" &&
+ v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" &&
+ GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
+ cat >expect <<-EOF &&
+ key.oldone oldfoo
+ key.newone newfoo
+ key.oldtwo oldbar
+ key.newtwo newbar
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'old and new bools with ambiguous subsection' '
+ v="${SQ}key.with=equals.oldbool${SQ}" &&
+ v="$v ${SQ}key.with=equals.newbool${SQ}=" &&
+ GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual &&
+ cat >expect <<-EOF &&
+ key.with equals.oldbool
+ key.with=equals.newbool
+ EOF
+ test_cmp expect actual
+'
+
test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
cat >expect <<-\EOF &&
env.one one
@@ -1308,6 +1370,173 @@ test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
git config --get-regexp "env.*"
'
+test_expect_success 'git --config-env=key=envvar support' '
+ cat >expect <<-\EOF &&
+ value
+ value
+ false
+ EOF
+ {
+ ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
+ ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase &&
+ ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag
+ } >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git --config-env fails with invalid parameters' '
+ test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error &&
+ test_i18ngrep "invalid config format: foo.flag" error &&
+ test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error &&
+ test_i18ngrep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error &&
+ sane_unset NONEXISTENT &&
+ test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error &&
+ test_i18ngrep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error
+'
+
+test_expect_success 'git -c and --config-env work together' '
+ cat >expect <<-\EOF &&
+ bar.cmd cmd-value
+ bar.env env-value
+ EOF
+ ENVVAR=env-value git \
+ -c bar.cmd=cmd-value \
+ --config-env=bar.env=ENVVAR \
+ config --get-regexp "^bar.*" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git -c and --config-env override each other' '
+ cat >expect <<-\EOF &&
+ env
+ cmd
+ EOF
+ {
+ ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar &&
+ ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar
+ } >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '--config-env handles keys with equals' '
+ echo value=with=equals >expect &&
+ ENVVAR=value=with=equals git \
+ --config-env=section.subsection=with=equals.key=ENVVAR \
+ config section.subsection=with=equals.key >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'git config handles environment config pairs' '
+ GIT_CONFIG_COUNT=2 \
+ GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \
+ GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \
+ git config --get-regexp "pair.*" >actual &&
+ cat >expect <<-EOF &&
+ pair.one foo
+ pair.two bar
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'git config ignores pairs without count' '
+ test_must_fail env GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
+ git config pair.one 2>error &&
+ test_must_be_empty error
+'
+
+test_expect_success 'git config ignores pairs with zero count' '
+ test_must_fail env \
+ GIT_CONFIG_COUNT=0 \
+ GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
+ git config pair.one
+'
+
+test_expect_success 'git config ignores pairs exceeding count' '
+ GIT_CONFIG_COUNT=1 \
+ GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
+ GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \
+ git config --get-regexp "pair.*" >actual &&
+ cat >expect <<-EOF &&
+ pair.one value
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'git config ignores pairs with zero count' '
+ test_must_fail env \
+ GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
+ git config pair.one >error &&
+ test_must_be_empty error
+'
+
+test_expect_success 'git config ignores pairs with empty count' '
+ test_must_fail env \
+ GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \
+ git config pair.one >error &&
+ test_must_be_empty error
+'
+
+test_expect_success 'git config fails with invalid count' '
+ test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error &&
+ test_i18ngrep "bogus count" error &&
+ test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error &&
+ test_i18ngrep "too many entries" error
+'
+
+test_expect_success 'git config fails with missing config key' '
+ test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \
+ git config --list 2>error &&
+ test_i18ngrep "missing config key" error
+'
+
+test_expect_success 'git config fails with missing config value' '
+ test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \
+ git config --list 2>error &&
+ test_i18ngrep "missing config value" error
+'
+
+test_expect_success 'git config fails with invalid config pair key' '
+ test_must_fail env GIT_CONFIG_COUNT=1 \
+ GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \
+ git config --list &&
+ test_must_fail env GIT_CONFIG_COUNT=1 \
+ GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \
+ git config --list
+'
+
+test_expect_success 'environment overrides config file' '
+ test_when_finished "rm -f .git/config" &&
+ cat >.git/config <<-EOF &&
+ [pair]
+ one = value
+ EOF
+ GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \
+ git config pair.one >actual &&
+ cat >expect <<-EOF &&
+ override
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' '
+ GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
+ GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \
+ git config pair.one >actual &&
+ cat >expect <<-EOF &&
+ override
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'command line overrides environment config' '
+ GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \
+ git -c pair.one=override config pair.one >actual &&
+ cat >expect <<-EOF &&
+ override
+ EOF
+ test_cmp expect actual
+'
+
test_expect_success 'git config --edit works' '
git config -f tmp test.value no &&
echo test.value=yes >expect &&
@@ -1653,9 +1882,11 @@ test_expect_success '--show-origin with --list' '
file:.git/config user.override=local
file:.git/config include.path=../include/relative.include
file:.git/../include/relative.include user.relative=include
+ command line: user.environ=true
command line: user.cmdline=true
EOF
- git -c user.cmdline=true config --list --show-origin >output &&
+ GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\
+ git -c user.cmdline=true config --list --show-origin >output &&
test_cmp expect output
'
@@ -1761,11 +1992,11 @@ test_expect_success '--show-origin blob' '
test_expect_success '--show-origin blob ref' '
cat >expect <<-\EOF &&
- blob:master:custom.conf user.custom=true
+ blob:main:custom.conf user.custom=true
EOF
git add "$CUSTOM_CONFIG_FILE" &&
git commit -m "new config file" &&
- git config --blob=master:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
+ git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
test_cmp expect output
'