Skip to content

Commit 2076dba

Browse files
derrickstoleegitster
authored andcommitted
t1300: test "set all" mode with value-pattern
Without additional modifiers, 'git config <key> <value>' 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 <key> <value> <value-pattern>'. 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=<file>' instead of modifying .git/config directly to prevent possibly incompatible repo states. Also use 'git config --file=<file> --list' for config state comparison instead of the config file format. This makes the tests more readable. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 247e2f8 commit 2076dba

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

t/t1300-config.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,4 +1917,43 @@ test_expect_success '--replace-all does not invent newlines' '
19171917
test_cmp expect .git/config
19181918
'
19191919

1920+
test_expect_success 'set all config with value-pattern' '
1921+
test_when_finished rm -f config initial &&
1922+
git config --file=initial abc.key one &&
1923+
1924+
# no match => add new entry
1925+
cp initial config &&
1926+
git config --file=config abc.key two a+ &&
1927+
git config --file=config --list >actual &&
1928+
cat >expect <<-\EOF &&
1929+
abc.key=one
1930+
abc.key=two
1931+
EOF
1932+
test_cmp expect actual &&
1933+
1934+
# multiple matches => failure
1935+
test_must_fail git config --file=config abc.key three o+ 2>err &&
1936+
test_i18ngrep "has multiple values" err &&
1937+
1938+
# multiple values, no match => add
1939+
git config --file=config abc.key three a+ &&
1940+
git config --file=config --list >actual &&
1941+
cat >expect <<-\EOF &&
1942+
abc.key=one
1943+
abc.key=two
1944+
abc.key=three
1945+
EOF
1946+
test_cmp expect actual &&
1947+
1948+
# single match => replace
1949+
git config --file=config abc.key four h+ &&
1950+
git config --file=config --list >actual &&
1951+
cat >expect <<-\EOF &&
1952+
abc.key=one
1953+
abc.key=two
1954+
abc.key=four
1955+
EOF
1956+
test_cmp expect actual
1957+
'
1958+
19201959
test_done

0 commit comments

Comments
 (0)