]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'tb/config-type'
authorJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2018 06:59:26 +0000 (15:59 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 May 2018 06:59:26 +0000 (15:59 +0900)
The "git config" command uses separate options e.g. "--int",
"--bool", etc. to specify what type the caller wants the value to
be interpreted as.  A new "--type=<typename>" option has been
introduced, which would make it cleaner to define new types.

* tb/config-type:
  builtin/config.c: support `--type=<type>` as preferred alias for `--<type>`
  builtin/config.c: treat type specifiers singularly

1  2 
t/t1300-config.sh

index 5acf12f7fb0fe819e6d02af0c5d37b44d0cce38e,e06af3d337ac037d799f878025d175bd1271a524..e7e6d07b3a85ce08e351da3d54077d94e779beea
@@@ -742,7 -740,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)' '
@@@ -1686,25 -1611,67 +1686,88 @@@ test_expect_success '--local requires 
        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
 +      QkeepSection
 +      [xyz]
 +      Qkey = 1
 +      [abc]
 +      Qkey = a
 +      EOF
 +      q_to_tab >expect <<-\EOF &&
 +      [abc]
 +      QkeepSection
 +      [xyz]
 +      Qkey = 1
 +      [abc]
 +      Qkey = b
 +      EOF
 +      git config --replace-all abc.key b &&
 +      test_cmp .git/config expect
 +'
 +
  test_done