From 2076dba281a0e9b16dc670d59a87c62c97b90a74 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Wed, 25 Nov 2020 22:12:51 +0000 Subject: [PATCH] t1300: test "set all" mode with value-pattern Without additional modifiers, 'git config ' attempts to set a single value in the .git/config file. When the value-pattern parameter is supplied, this command behaves in a non-trivial manner. Consider 'git config '. The expected behavior is as follows: 1. If there are multiple existing values that match 'value-pattern', then the command fails. Users should use --replace-all instead. 2. If there is no existing values match 'value-pattern', then the 'key=value' pair is appended, making this 'key' a multi-valued config setting. 3. If there is one existing value that matches 'value-pattern', then the new config has one entry where 'key=value'. Add a test that demonstrates these options. Break from the existing pattern in t1300-config.sh to use 'git config --file=' instead of modifying .git/config directly to prevent possibly incompatible repo states. Also use 'git config --file= --list' for config state comparison instead of the config file format. This makes the tests more readable. Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- t/t1300-config.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 825d9a184f..a74bcb4c85 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1917,4 +1917,43 @@ test_expect_success '--replace-all does not invent newlines' ' 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_done