]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ps/config-env-option-with-separate-value'
authorJunio C Hamano <gitster@pobox.com>
Fri, 7 May 2021 03:47:37 +0000 (12:47 +0900)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 May 2021 03:47:37 +0000 (12:47 +0900)
"git --config-env var=val cmd" weren't accepted (only
--config-env=var=val was).

* ps/config-env-option-with-separate-value:
  git: support separate arg for `--config-env`'s value
  git.txt: fix synopsis of `--config-env` missing the equals sign

1  2 
Documentation/git.txt
git.c
t/t1300-config.sh

diff --combined Documentation/git.txt
index 3a9c44987f998c6a767c4dc19755e4e0c10d9411,4ac36a4742e290de74d31547bf9c1116f57754a1..ba5c8e9d98e389e840e10890a24e1380d50e905f
@@@ -13,7 -13,7 +13,7 @@@ SYNOPSI
      [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
      [-p|--paginate|-P|--no-pager] [--no-replace-objects] [--bare]
      [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
-     [--super-prefix=<path>] [--config-env <name>=<envvar>]
+     [--super-prefix=<path>] [--config-env=<name>=<envvar>]
      <command> [<args>]
  
  DESCRIPTION
@@@ -88,7 -88,7 +88,7 @@@ foo.bar= ...`) sets `foo.bar` to the em
        empty string, instead the environment variable itself must be
        set to the empty string.  It is an error if the `<envvar>` does not exist
        in the environment. `<envvar>` may not contain an equals sign
 -      to avoid ambiguity with `<name>`s which contain one.
 +      to avoid ambiguity with `<name>` containing one.
  +
  This is useful for cases where you want to pass transitory
  configuration options to git, but are doing so on OS's where
@@@ -631,8 -631,8 +631,8 @@@ othe
  `GIT_SEQUENCE_EDITOR`::
        This environment variable overrides the configured Git editor
        when editing the todo list of an interactive rebase. See also
 -      linkit::git-rebase[1] and the `sequence.editor` option in
 -      linkit::git-config[1].
 +      linkgit:git-rebase[1] and the `sequence.editor` option in
 +      linkgit:git-config[1].
  
  `GIT_SSH`::
  `GIT_SSH_COMMAND`::
diff --combined git.c
index 06d681cd593989df91b906ec06896cd6f2daf544,dd8c6ca51a1493a2c965aaa243afbd37d8cc41a0..18bed9a99647aa310ad37d4cd8dc683c66084b41
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -255,6 -255,14 +255,14 @@@ static int handle_options(const char **
                        git_config_push_parameter((*argv)[1]);
                        (*argv)++;
                        (*argc)--;
+               } else if (!strcmp(cmd, "--config-env")) {
+                       if (*argc < 2) {
+                               fprintf(stderr, _("no config key given for --config-env\n" ));
+                               usage(git_usage_string);
+                       }
+                       git_config_push_env((*argv)[1]);
+                       (*argv)++;
+                       (*argc)--;
                } else if (skip_prefix(cmd, "--config-env=", &cmd)) {
                        git_config_push_env(cmd);
                } else if (!strcmp(cmd, "--literal-pathspecs")) {
@@@ -423,7 -431,7 +431,7 @@@ static int run_builtin(struct cmd_struc
                        int nongit_ok;
                        prefix = setup_git_directory_gently(&nongit_ok);
                }
 -
 +              precompose_argv_prefix(argc, argv, NULL);
                if (use_pager == -1 && p->option & (RUN_SETUP | RUN_SETUP_GENTLY) &&
                    !(p->option & DELAY_PAGER_CONFIG))
                        use_pager = check_pager_config(p->cmd);
@@@ -490,8 -498,6 +498,8 @@@ static struct cmd_struct commands[] = 
        { "check-mailmap", cmd_check_mailmap, RUN_SETUP },
        { "check-ref-format", cmd_check_ref_format, NO_PARSEOPT  },
        { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },
 +      { "checkout--worker", cmd_checkout__worker,
 +              RUN_SETUP | NEED_WORK_TREE | SUPPORT_SUPER_PREFIX },
        { "checkout-index", cmd_checkout_index,
                RUN_SETUP | NEED_WORK_TREE},
        { "cherry", cmd_cherry, RUN_SETUP },
        { "ls-tree", cmd_ls_tree, RUN_SETUP },
        { "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY | NO_PARSEOPT },
        { "mailsplit", cmd_mailsplit, NO_PARSEOPT },
 -      { "maintenance", cmd_maintenance, RUN_SETUP_GENTLY | NO_PARSEOPT },
 +      { "maintenance", cmd_maintenance, RUN_SETUP | NO_PARSEOPT },
        { "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE },
        { "merge-base", cmd_merge_base, RUN_SETUP },
        { "merge-file", cmd_merge_file, RUN_SETUP_GENTLY },
diff --combined t/t1300-config.sh
index e0dd5d65cedadbab2a5d4aa9c0697b346374612b,ca3fec8cfafb43fae46a5c58a2e4eae33f9e9e42..ad4e6d0cfcacd0f1afdb30f831db30d1434afb99
@@@ -5,9 -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' '
  '
  
  cat > expect << EOF
 -[core]
 +[section]
        penguin = little blue
  EOF
  test_expect_success 'initial' '
 -      git config core.penguin "little blue" &&
 +      git config section.penguin "little blue" &&
        test_cmp expect .git/config
  '
  
  cat > expect << EOF
 -[core]
 +[section]
        penguin = little blue
        Movie = BadPhysics
  EOF
  test_expect_success 'mixed case' '
 -      git config Core.Movie BadPhysics &&
 +      git config Section.Movie BadPhysics &&
        test_cmp expect .git/config
  '
  
  cat > expect << EOF
 -[core]
 +[section]
        penguin = little blue
        Movie = BadPhysics
 -[Cores]
 +[Sections]
        WhatEver = Second
  EOF
  test_expect_success 'similar section' '
 -      git config Cores.WhatEver Second &&
 +      git config Sections.WhatEver Second &&
        test_cmp expect .git/config
  '
  
  cat > expect << EOF
 -[core]
 +[section]
        penguin = little blue
        Movie = BadPhysics
        UPPERCASE = true
 -[Cores]
 +[Sections]
        WhatEver = Second
  EOF
  test_expect_success 'uppercase section' '
 -      git config CORE.UPPERCASE true &&
 +      git config SECTION.UPPERCASE true &&
        test_cmp expect .git/config
  '
  
  test_expect_success 'replace with non-match' '
 -      git config core.penguin kingpin !blue
 +      git config section.penguin kingpin !blue
  '
  
  test_expect_success 'replace with non-match (actually matching)' '
 -      git config core.penguin "very blue" !kingpin
 +      git config section.penguin "very blue" !kingpin
  '
  
  cat > expect << EOF
 -[core]
 +[section]
        penguin = very blue
        Movie = BadPhysics
        UPPERCASE = true
        penguin = kingpin
 -[Cores]
 +[Sections]
        WhatEver = Second
  EOF
  
  test_expect_success 'non-match result' 'test_cmp expect .git/config'
  
  test_expect_success 'find mixed-case key by canonical name' '
 -      test_cmp_config Second cores.whatever
 +      test_cmp_config Second sections.whatever
  '
  
  test_expect_success 'find mixed-case key by non-canonical name' '
 -      test_cmp_config Second CoReS.WhAtEvEr
 +      test_cmp_config Second SeCtIoNs.WhAtEvEr
  '
  
  test_expect_success 'subsections are not canonicalized by git-config' '
@@@ -472,8 -469,7 +472,8 @@@ test_expect_success 'new variable inser
  '
  
  test_expect_success 'alternative --file (non-existing file should fail)' '
 -      test_must_fail git config --file non-existing-config -l
 +      test_must_fail git config --file non-existing-config -l &&
 +      test_must_fail git config --file non-existing-config test.xyzzy
  '
  
  cat > other-config << EOF
@@@ -510,6 -506,10 +510,6 @@@ test_expect_success 'editing stdin is a
  
  test_expect_success 'refer config from subdirectory' '
        mkdir x &&
 -      test_cmp_config -C x strasse --get --file ../other-config ein.bahn
 -'
 -
 -test_expect_success 'refer config from subdirectory via --file' '
        test_cmp_config -C x strasse --file=../other-config --get ein.bahn
  '
  
@@@ -675,13 -675,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 &&
@@@ -1043,6 -1036,11 +1043,6 @@@ test_expect_success SYMLINKS 'symlinke
        test_cmp expect actual
  '
  
 -test_expect_success 'nonexistent configuration' '
 -      test_must_fail git config --file=doesnotexist --list &&
 -      test_must_fail git config --file=doesnotexist test.xyzzy
 -'
 -
  test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
        ln -s doesnotexist linktonada &&
        ln -s linktonada linktolinktonada &&
@@@ -1056,8 -1054,8 +1056,8 @@@ test_expect_success 'check split_cmdlin
        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' '
        true
        EOF
        {
 -              git -c core.name=value config core.name &&
 +              git -c section.name=value config section.name &&
                git -c foo.CamelCase=value config foo.camelcase &&
                git -c foo.flag config --bool foo.flag
        } >actual &&
        test_cmp expect actual &&
 -      test_must_fail git -c name=value config core.name
 +      test_must_fail git -c name=value config section.name
  '
  
  # We just need a type-specifier here that cares about the
@@@ -1117,7 -1115,7 +1117,7 @@@ test_expect_success 'aliases can be Cam
  
  test_expect_success 'git -c does not split values on equals' '
        echo "value with = in it" >expect &&
 -      git -c core.foo="value with = in it" config core.foo >actual &&
 +      git -c section.foo="value with = in it" config section.foo >actual &&
        test_cmp expect actual
  '
  
@@@ -1374,16 -1372,29 +1374,29 @@@ test_expect_success 'git --config-env=k
        cat >expect <<-\EOF &&
        value
        value
+       value
+       value
+       false
        false
        EOF
        {
                ENVVAR=value git --config-env=core.name=ENVVAR config core.name &&
+               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
+               ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase &&
+               ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag &&
+               ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag
        } >actual &&
        test_cmp expect actual
  '
  
+ test_expect_success 'git --config-env with missing value' '
+       test_must_fail env ENVVAR=value git --config-env 2>error &&
+       grep "no config key given for --config-env" error &&
+       test_must_fail env ENVVAR=value git --config-env config core.name 2>error &&
+       grep "invalid config format: config" error
+ '
  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 &&
@@@ -1992,11 -2003,11 +2005,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
  '
  
  done
  
  cat >.git/config <<-\EOF &&
 -[core]
 +[section]
  foo = true
  number = 10
  big = 1M
  EOF
  
  test_expect_success 'identical modern --type specifiers are allowed' '
 -      test_cmp_config 1048576 --type=int --type=int core.big
 +      test_cmp_config 1048576 --type=int --type=int section.big
  '
  
  test_expect_success 'identical legacy --type specifiers are allowed' '
 -      test_cmp_config 1048576 --int --int core.big
 +      test_cmp_config 1048576 --int --int section.big
  '
  
  test_expect_success 'identical mixed --type specifiers are allowed' '
 -      test_cmp_config 1048576 --int --type=int core.big
 +      test_cmp_config 1048576 --int --type=int section.big
  '
  
  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_must_fail git config --type=int --type=bool section.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_must_fail git config --int --bool section.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_must_fail git config --type=int --bool section.big 2>error &&
        test_i18ngrep "only one type at a time" error
  '
  
  test_expect_success '--type allows valid type specifiers' '
 -      test_cmp_config true  --type=bool core.foo
 +      test_cmp_config true  --type=bool section.foo
  '
  
  test_expect_success '--no-type unsets type specifiers' '
 -      test_cmp_config 10 --type=bool --no-type core.number
 +      test_cmp_config 10 --type=bool --no-type section.number
  '
  
  test_expect_success 'unset type specifiers may be reset to conflicting ones' '
 -      test_cmp_config 1048576 --type=bool --no-type --type=int core.big
 +      test_cmp_config 1048576 --type=bool --no-type --type=int section.big
  '
  
  test_expect_success '--type rejects unknown specifiers' '
 -      test_must_fail git config --type=nonsense core.foo 2>error &&
 +      test_must_fail git config --type=nonsense section.foo 2>error &&
        test_i18ngrep "unrecognized --type argument" error
  '
  
@@@ -2140,153 -2151,4 +2153,153 @@@ test_expect_success '--replace-all doe
        test_cmp expect .git/config
  '
  
 +test_expect_success 'set all config with value-pattern' '
 +      test_when_finished rm -f config initial &&
 +      git config --file=initial abc.key one &&
 +
 +      # no match => add new entry
 +      cp initial config &&
 +      git config --file=config abc.key two a+ &&
 +      git config --file=config --list >actual &&
 +      cat >expect <<-\EOF &&
 +      abc.key=one
 +      abc.key=two
 +      EOF
 +      test_cmp expect actual &&
 +
 +      # multiple matches => failure
 +      test_must_fail git config --file=config abc.key three o+ 2>err &&
 +      test_i18ngrep "has multiple values" err &&
 +
 +      # multiple values, no match => add
 +      git config --file=config abc.key three a+ &&
 +      git config --file=config --list >actual &&
 +      cat >expect <<-\EOF &&
 +      abc.key=one
 +      abc.key=two
 +      abc.key=three
 +      EOF
 +      test_cmp expect actual &&
 +
 +      # single match => replace
 +      git config --file=config abc.key four h+ &&
 +      git config --file=config --list >actual &&
 +      cat >expect <<-\EOF &&
 +      abc.key=one
 +      abc.key=two
 +      abc.key=four
 +      EOF
 +      test_cmp expect actual
 +'
 +
 +test_expect_success '--replace-all and value-pattern' '
 +      test_when_finished rm -f config &&
 +      git config --file=config --add abc.key one &&
 +      git config --file=config --add abc.key two &&
 +      git config --file=config --add abc.key three &&
 +      git config --file=config --replace-all abc.key four "o+" &&
 +      git config --file=config --list >actual &&
 +      cat >expect <<-\EOF &&
 +      abc.key=four
 +      abc.key=three
 +      EOF
 +      test_cmp expect actual
 +'
 +
 +test_expect_success 'refuse --fixed-value for incompatible actions' '
 +      test_when_finished rm -f config &&
 +      git config --file=config dev.null bogus &&
 +
 +      # These modes do not allow --fixed-value at all
 +      test_must_fail git config --file=config --fixed-value --add dev.null bogus &&
 +      test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
 +      test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
 +      test_must_fail git config --file=config --fixed-value --rename-section dev null &&
 +      test_must_fail git config --file=config --fixed-value --remove-section dev &&
 +      test_must_fail git config --file=config --fixed-value --list &&
 +      test_must_fail git config --file=config --fixed-value --get-color dev.null &&
 +      test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&
 +
 +      # These modes complain when --fixed-value has no value-pattern
 +      test_must_fail git config --file=config --fixed-value dev.null bogus &&
 +      test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus &&
 +      test_must_fail git config --file=config --fixed-value --get dev.null &&
 +      test_must_fail git config --file=config --fixed-value --get-all dev.null &&
 +      test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" &&
 +      test_must_fail git config --file=config --fixed-value --unset dev.null &&
 +      test_must_fail git config --file=config --fixed-value --unset-all dev.null
 +'
 +
 +test_expect_success '--fixed-value uses exact string matching' '
 +      test_when_finished rm -f config initial &&
 +      META="a+b*c?d[e]f.g" &&
 +      git config --file=initial fixed.test "$META" &&
 +
 +      cp initial config &&
 +      git config --file=config fixed.test bogus "$META" &&
 +      git config --file=config --list >actual &&
 +      cat >expect <<-EOF &&
 +      fixed.test=$META
 +      fixed.test=bogus
 +      EOF
 +      test_cmp expect actual &&
 +
 +      cp initial config &&
 +      git config --file=config --fixed-value fixed.test bogus "$META" &&
 +      git config --file=config --list >actual &&
 +      cat >expect <<-\EOF &&
 +      fixed.test=bogus
 +      EOF
 +      test_cmp expect actual &&
 +
 +      cp initial config &&
 +      test_must_fail git config --file=config --unset fixed.test "$META" &&
 +      git config --file=config --fixed-value --unset fixed.test "$META" &&
 +      test_must_fail git config --file=config fixed.test &&
 +
 +      cp initial config &&
 +      test_must_fail git config --file=config --unset-all fixed.test "$META" &&
 +      git config --file=config --fixed-value --unset-all fixed.test "$META" &&
 +      test_must_fail git config --file=config fixed.test &&
 +
 +      cp initial config &&
 +      git config --file=config --replace-all fixed.test bogus "$META" &&
 +      git config --file=config --list >actual &&
 +      cat >expect <<-EOF &&
 +      fixed.test=$META
 +      fixed.test=bogus
 +      EOF
 +      test_cmp expect actual &&
 +
 +      git config --file=config --fixed-value --replace-all fixed.test bogus "$META" &&
 +      git config --file=config --list >actual &&
 +      cat >expect <<-EOF &&
 +      fixed.test=bogus
 +      fixed.test=bogus
 +      EOF
 +      test_cmp expect actual
 +'
 +
 +test_expect_success '--get and --get-all with --fixed-value' '
 +      test_when_finished rm -f config &&
 +      META="a+b*c?d[e]f.g" &&
 +      git config --file=config fixed.test bogus &&
 +      git config --file=config --add fixed.test "$META" &&
 +
 +      git config --file=config --get fixed.test bogus &&
 +      test_must_fail git config --file=config --get fixed.test "$META" &&
 +      git config --file=config --get --fixed-value fixed.test "$META" &&
 +      test_must_fail git config --file=config --get --fixed-value fixed.test non-existent &&
 +
 +      git config --file=config --get-all fixed.test bogus &&
 +      test_must_fail git config --file=config --get-all fixed.test "$META" &&
 +      git config --file=config --get-all --fixed-value fixed.test "$META" &&
 +      test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent &&
 +
 +      git config --file=config --get-regexp fixed+ bogus &&
 +      test_must_fail git config --file=config --get-regexp fixed+ "$META" &&
 +      git config --file=config --get-regexp --fixed-value fixed+ "$META" &&
 +      test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent
 +'
 +
  test_done