Merge branch 'sg/t6500-no-redirect-of-stdin'
[gitweb.git] / t / t1300-config.sh
index 92aaa53794d20f971d42f109079347c1cbc3da42..03c223708ebb428125dffb4a9ca273629936ff0c 100755 (executable)
@@ -742,7 +742,7 @@ test_expect_success bool '
        do
            git config --bool --get bool.true$i >>result
            git config --bool --get bool.false$i >>result
-        done &&
+       done &&
        test_cmp expect result'
 
 test_expect_success 'invalid bool (--get)' '
@@ -916,7 +916,7 @@ test_expect_success 'get --expiry-date' '
        invalid1 = "abc"
        EOF
        cat >expect <<-EOF &&
-       $(test-date timestamp $rel)
+       $(test-tool date timestamp $rel)
        1275666415
        1510441871
        1510348087
@@ -933,6 +933,36 @@ test_expect_success 'get --expiry-date' '
        test_must_fail git config --expiry-date date.invalid1
 '
 
+test_expect_success 'get --type=color' '
+       rm .git/config &&
+       git config foo.color "red" &&
+       git config --get --type=color foo.color >actual.raw &&
+       test_decode_color <actual.raw >actual &&
+       echo "<RED>" >expect &&
+       test_cmp expect actual
+'
+
+cat >expect << EOF
+[foo]
+       color = red
+EOF
+
+test_expect_success 'set --type=color' '
+       rm .git/config &&
+       git config --type=color foo.color "red" &&
+       test_cmp expect .git/config
+'
+
+test_expect_success 'get --type=color barfs on non-color' '
+       echo "[foo]bar=not-a-color" >.git/config &&
+       test_must_fail git config --get --type=color foo.bar
+'
+
+test_expect_success 'set --type=color barfs on non-color' '
+       test_must_fail git config --type=color foo.color "not-a-color" 2>error &&
+       test_i18ngrep "cannot parse color" error
+'
+
 cat > expect << EOF
 [quote]
        leading = " test"
@@ -1208,6 +1238,29 @@ test_expect_success 'git -c is not confused by empty environment' '
        GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list
 '
 
+sq="'"
+test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' '
+       cat >expect <<-\EOF &&
+       env.one one
+       env.two two
+       EOF
+       GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq} ${sq}env.two=two${sq}" \
+               git config --get-regexp "env.*" >actual &&
+       test_cmp expect actual &&
+
+       cat >expect <<-EOF &&
+       env.one one${sq}
+       env.two two
+       EOF
+       GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq}\\$sq$sq$sq ${sq}env.two=two${sq}" \
+               git config --get-regexp "env.*" >actual &&
+       test_cmp expect actual &&
+
+       test_must_fail env \
+               GIT_CONFIG_PARAMETERS="${sq}env.one=one${sq}\\$sq ${sq}env.two=two${sq}" \
+               git config --get-regexp "env.*"
+'
+
 test_expect_success 'git config --edit works' '
        git config -f tmp test.value no &&
        echo test.value=yes >expect &&
@@ -1483,7 +1536,7 @@ test_expect_success '--unset-all removes section if empty & uncommented' '
        test_line_count = 0 .git/config
 '
 
-test_expect_failure 'adding a key into an empty section reuses header' '
+test_expect_success 'adding a key into an empty section reuses header' '
        cat >.git/config <<-\EOF &&
        [section]
        EOF
@@ -1639,10 +1692,10 @@ test_expect_success '--show-origin stdin with file include' '
 '
 
 test_expect_success !MINGW '--show-origin blob' '
-       cat >expect <<-\EOF &&
-               blob:a9d9f9e555b5c6f07cbe09d3f06fe3df11e09c08   user.custom=true
-       EOF
        blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
+       cat >expect <<-EOF &&
+               blob:$blob      user.custom=true
+       EOF
        git config --blob=$blob --show-origin --list >output &&
        test_cmp expect output
 '
@@ -1663,6 +1716,69 @@ test_expect_success '--local requires a repo' '
        test_expect_code 128 nongit git config --local foo.bar
 '
 
+cat >.git/config <<-\EOF &&
+[core]
+foo = true
+number = 10
+big = 1M
+EOF
+
+test_expect_success 'identical modern --type specifiers are allowed' '
+       git config --type=int --type=int core.big >actual &&
+       echo 1048576 >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'identical legacy --type specifiers are allowed' '
+       git config --int --int core.big >actual &&
+       echo 1048576 >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'identical mixed --type specifiers are allowed' '
+       git config --int --type=int core.big >actual &&
+       echo 1048576 >expect &&
+       test_cmp expect actual
+'
+
+test_expect_success 'non-identical modern --type specifiers are not allowed' '
+       test_must_fail git config --type=int --type=bool core.big 2>error &&
+       test_i18ngrep "only one type at a time" error
+'
+
+test_expect_success 'non-identical legacy --type specifiers are not allowed' '
+       test_must_fail git config --int --bool core.big 2>error &&
+       test_i18ngrep "only one type at a time" error
+'
+
+test_expect_success 'non-identical mixed --type specifiers are not allowed' '
+       test_must_fail git config --type=int --bool core.big 2>error &&
+       test_i18ngrep "only one type at a time" error
+'
+
+test_expect_success '--type allows valid type specifiers' '
+       echo "true" >expect &&
+       git config --type=bool core.foo >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '--no-type unsets type specifiers' '
+       echo "10" >expect &&
+       git config --type=bool --no-type core.number >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'unset type specifiers may be reset to conflicting ones' '
+       echo 1048576 >expect &&
+       git config --type=bool --no-type --type=int core.big >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '--type rejects unknown specifiers' '
+       test_must_fail git config --type=nonsense core.foo 2>error &&
+       test_i18ngrep "unrecognized --type argument" error
+'
+
 test_expect_success '--replace-all does not invent newlines' '
        q_to_tab >.git/config <<-\EOF &&
        [abc]key