Merge branch 'jk/config-ignore-duplicates'

Drop duplicate detection from "git-config --get"; this lets it
better match the internal config callbacks, which clears up some
corner cases with includes.

* jk/config-ignore-duplicates:
  builtin/config.c: Fix a sparse warning
  git-config: use git_config_with_options
  git-config: do not complain about duplicate entries
  git-config: collect values instead of immediately printing
  git-config: fix regexp memory leaks on error conditions
  git-config: remove memory leak of key regexp
  t1300: test "git config --get-all" more thoroughly
  t1300: remove redundant test
  t1300: style updates
This commit is contained in:
Junio C Hamano 2012-11-21 13:16:44 -08:00
commit 2739889c98
4 changed files with 233 additions and 197 deletions

View File

@ -15,7 +15,6 @@ static int show_keys;
static int use_key_regexp; static int use_key_regexp;
static int do_all; static int do_all;
static int do_not_match; static int do_not_match;
static int seen;
static char delim = '='; static char delim = '=';
static char key_delim = ' '; static char key_delim = ' ';
static char term = '\n'; static char term = '\n';
@ -95,12 +94,19 @@ static int show_all_config(const char *key_, const char *value_, void *cb)
return 0; return 0;
} }
static int show_config(const char *key_, const char *value_, void *cb) struct strbuf_list {
struct strbuf *items;
int nr;
int alloc;
};
static int collect_config(const char *key_, const char *value_, void *cb)
{ {
struct strbuf_list *values = cb;
struct strbuf *buf;
char value[256]; char value[256];
const char *vptr = value; const char *vptr = value;
int must_free_vptr = 0; int must_free_vptr = 0;
int dup_error = 0;
int must_print_delim = 0; int must_print_delim = 0;
if (!use_key_regexp && strcmp(key_, key)) if (!use_key_regexp && strcmp(key_, key))
@ -111,12 +117,14 @@ static int show_config(const char *key_, const char *value_, void *cb)
(do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0))) (do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0)))
return 0; return 0;
ALLOC_GROW(values->items, values->nr + 1, values->alloc);
buf = &values->items[values->nr++];
strbuf_init(buf, 0);
if (show_keys) { if (show_keys) {
printf("%s", key_); strbuf_addstr(buf, key_);
must_print_delim = 1; must_print_delim = 1;
} }
if (seen && !do_all)
dup_error = 1;
if (types == TYPE_INT) if (types == TYPE_INT)
sprintf(value, "%d", git_config_int(key_, value_?value_:"")); sprintf(value, "%d", git_config_int(key_, value_?value_:""));
else if (types == TYPE_BOOL) else if (types == TYPE_BOOL)
@ -139,16 +147,12 @@ static int show_config(const char *key_, const char *value_, void *cb)
vptr = ""; vptr = "";
must_print_delim = 0; must_print_delim = 0;
} }
seen++;
if (dup_error) { if (must_print_delim)
error("More than one value for the key %s: %s", strbuf_addch(buf, key_delim);
key_, vptr); strbuf_addstr(buf, vptr);
} strbuf_addch(buf, term);
else {
if (must_print_delim)
printf("%c", key_delim);
printf("%s%c", vptr, term);
}
if (must_free_vptr) if (must_free_vptr)
/* If vptr must be freed, it's a pointer to a /* If vptr must be freed, it's a pointer to a
* dynamically allocated buffer, it's safe to cast to * dynamically allocated buffer, it's safe to cast to
@ -162,19 +166,8 @@ static int show_config(const char *key_, const char *value_, void *cb)
static int get_value(const char *key_, const char *regex_) static int get_value(const char *key_, const char *regex_)
{ {
int ret = CONFIG_GENERIC_ERROR; int ret = CONFIG_GENERIC_ERROR;
char *global = NULL, *xdg = NULL, *repo_config = NULL; struct strbuf_list values = {NULL};
const char *system_wide = NULL, *local; int i;
struct config_include_data inc = CONFIG_INCLUDE_INIT;
config_fn_t fn;
void *data;
local = given_config_file;
if (!local) {
local = repo_config = git_pathdup("config");
if (git_config_system())
system_wide = git_etc_gitconfig();
home_config_paths(&global, &xdg, "config");
}
if (use_key_regexp) { if (use_key_regexp) {
char *tl; char *tl;
@ -196,7 +189,8 @@ static int get_value(const char *key_, const char *regex_)
key_regexp = (regex_t*)xmalloc(sizeof(regex_t)); key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
if (regcomp(key_regexp, key, REG_EXTENDED)) { if (regcomp(key_regexp, key, REG_EXTENDED)) {
fprintf(stderr, "Invalid key pattern: %s\n", key_); fprintf(stderr, "Invalid key pattern: %s\n", key_);
free(key); free(key_regexp);
key_regexp = NULL;
ret = CONFIG_INVALID_PATTERN; ret = CONFIG_INVALID_PATTERN;
goto free_strings; goto free_strings;
} }
@ -216,53 +210,37 @@ static int get_value(const char *key_, const char *regex_)
regexp = (regex_t*)xmalloc(sizeof(regex_t)); regexp = (regex_t*)xmalloc(sizeof(regex_t));
if (regcomp(regexp, regex_, REG_EXTENDED)) { if (regcomp(regexp, regex_, REG_EXTENDED)) {
fprintf(stderr, "Invalid pattern: %s\n", regex_); fprintf(stderr, "Invalid pattern: %s\n", regex_);
free(regexp);
regexp = NULL;
ret = CONFIG_INVALID_PATTERN; ret = CONFIG_INVALID_PATTERN;
goto free_strings; goto free_strings;
} }
} }
fn = show_config; git_config_with_options(collect_config, &values,
data = NULL; given_config_file, respect_includes);
if (respect_includes) {
inc.fn = fn; ret = !values.nr;
inc.data = data;
fn = git_config_include; for (i = 0; i < values.nr; i++) {
data = &inc; struct strbuf *buf = values.items + i;
if (do_all || i == values.nr - 1)
fwrite(buf->buf, 1, buf->len, stdout);
strbuf_release(buf);
} }
free(values.items);
if (do_all && system_wide) free_strings:
git_config_from_file(fn, system_wide, data);
if (do_all && xdg)
git_config_from_file(fn, xdg, data);
if (do_all && global)
git_config_from_file(fn, global, data);
if (do_all)
git_config_from_file(fn, local, data);
git_config_from_parameters(fn, data);
if (!do_all && !seen)
git_config_from_file(fn, local, data);
if (!do_all && !seen && global)
git_config_from_file(fn, global, data);
if (!do_all && !seen && xdg)
git_config_from_file(fn, xdg, data);
if (!do_all && !seen && system_wide)
git_config_from_file(fn, system_wide, data);
free(key); free(key);
if (key_regexp) {
regfree(key_regexp);
free(key_regexp);
}
if (regexp) { if (regexp) {
regfree(regexp); regfree(regexp);
free(regexp); free(regexp);
} }
if (do_all)
ret = !seen;
else
ret = (seen == 1) ? 0 : seen > 1 ? 2 : 1;
free_strings:
free(repo_config);
free(global);
free(xdg);
return ret; return ret;
} }

View File

@ -1279,6 +1279,7 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)
out_free_ret_1: out_free_ret_1:
free(*store_key); free(*store_key);
*store_key = NULL;
return -CONFIG_INVALID_KEY; return -CONFIG_INVALID_KEY;
} }

View File

@ -55,11 +55,13 @@ test_expect_success 'uppercase section' '
test_cmp expect .git/config test_cmp expect .git/config
' '
test_expect_success 'replace with non-match' \ test_expect_success 'replace with non-match' '
'git config core.penguin kingpin !blue' git config core.penguin kingpin !blue
'
test_expect_success 'replace with non-match (actually matching)' \ test_expect_success 'replace with non-match (actually matching)' '
'git config core.penguin "very blue" !kingpin' git config core.penguin "very blue" !kingpin
'
cat > expect << EOF cat > expect << EOF
[core] [core]
@ -108,8 +110,9 @@ baz = multiple \
lines lines
EOF EOF
test_expect_success 'unset with cont. lines' \ test_expect_success 'unset with cont. lines' '
'git config --unset beta.baz' git config --unset beta.baz
'
cat > expect <<\EOF cat > expect <<\EOF
[alpha] [alpha]
@ -133,8 +136,9 @@ EOF
cp .git/config .git/config2 cp .git/config .git/config2
test_expect_success 'multiple unset' \ test_expect_success 'multiple unset' '
'git config --unset-all beta.haha' git config --unset-all beta.haha
'
cat > expect << EOF cat > expect << EOF
[beta] ; silly comment # another comment [beta] ; silly comment # another comment
@ -145,7 +149,9 @@ noIndent= sillyValue ; 'nother silly comment
[nextSection] noNewline = ouch [nextSection] noNewline = ouch
EOF EOF
test_expect_success 'multiple unset is correct' 'test_cmp expect .git/config' test_expect_success 'multiple unset is correct' '
test_cmp expect .git/config
'
cp .git/config2 .git/config cp .git/config2 .git/config
@ -156,8 +162,9 @@ test_expect_success '--replace-all missing value' '
rm .git/config2 rm .git/config2
test_expect_success '--replace-all' \ test_expect_success '--replace-all' '
'git config --replace-all beta.haha gamma' git config --replace-all beta.haha gamma
'
cat > expect << EOF cat > expect << EOF
[beta] ; silly comment # another comment [beta] ; silly comment # another comment
@ -169,7 +176,9 @@ noIndent= sillyValue ; 'nother silly comment
[nextSection] noNewline = ouch [nextSection] noNewline = ouch
EOF EOF
test_expect_success 'all replaced' 'test_cmp expect .git/config' test_expect_success 'all replaced' '
test_cmp expect .git/config
'
cat > expect << EOF cat > expect << EOF
[beta] ; silly comment # another comment [beta] ; silly comment # another comment
@ -200,7 +209,11 @@ test_expect_success 'really really mean test' '
test_cmp expect .git/config test_cmp expect .git/config
' '
test_expect_success 'get value' 'test alpha = $(git config beta.haha)' test_expect_success 'get value' '
echo alpha >expect &&
git config beta.haha >actual &&
test_cmp expect actual
'
cat > expect << EOF cat > expect << EOF
[beta] ; silly comment # another comment [beta] ; silly comment # another comment
@ -231,18 +244,30 @@ test_expect_success 'multivar' '
test_cmp expect .git/config test_cmp expect .git/config
' '
test_expect_success 'non-match' \ test_expect_success 'non-match' '
'git config --get nextsection.nonewline !for' git config --get nextsection.nonewline !for
test_expect_success 'non-match value' \
'test wow = $(git config --get nextsection.nonewline !for)'
test_expect_success 'ambiguous get' '
test_must_fail git config --get nextsection.nonewline
' '
test_expect_success 'get multivar' \ test_expect_success 'non-match value' '
'git config --get-all nextsection.nonewline' echo wow >expect &&
git config --get nextsection.nonewline !for >actual &&
test_cmp expect actual
'
test_expect_success 'multi-valued get returns final one' '
echo "wow2 for me" >expect &&
git config --get nextsection.nonewline >actual &&
test_cmp expect actual
'
test_expect_success 'multi-valued get-all returns all' '
cat >expect <<-\EOF &&
wow
wow2 for me
EOF
git config --get-all nextsection.nonewline >actual &&
test_cmp expect actual
'
cat > expect << EOF cat > expect << EOF
[beta] ; silly comment # another comment [beta] ; silly comment # another comment
@ -259,10 +284,6 @@ test_expect_success 'multivar replace' '
test_cmp expect .git/config test_cmp expect .git/config
' '
test_expect_success 'ambiguous value' '
test_must_fail git config nextsection.nonewline
'
test_expect_success 'ambiguous unset' ' test_expect_success 'ambiguous unset' '
test_must_fail git config --unset nextsection.nonewline test_must_fail git config --unset nextsection.nonewline
' '
@ -290,8 +311,9 @@ test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla'
test_expect_success 'correct key' 'git config 123456.a123 987' test_expect_success 'correct key' 'git config 123456.a123 987'
test_expect_success 'hierarchical section' \ test_expect_success 'hierarchical section' '
'git config Version.1.2.3eX.Alpha beta' git config Version.1.2.3eX.Alpha beta
'
cat > expect << EOF cat > expect << EOF
[beta] ; silly comment # another comment [beta] ; silly comment # another comment
@ -307,7 +329,9 @@ noIndent= sillyValue ; 'nother silly comment
Alpha = beta Alpha = beta
EOF EOF
test_expect_success 'hierarchical section value' 'test_cmp expect .git/config' test_expect_success 'hierarchical section value' '
test_cmp expect .git/config
'
cat > expect << EOF cat > expect << EOF
beta.noindent=sillyValue beta.noindent=sillyValue
@ -316,9 +340,10 @@ nextsection.nonewline=wow2 for me
version.1.2.3eX.alpha=beta version.1.2.3eX.alpha=beta
EOF EOF
test_expect_success 'working --list' \ test_expect_success 'working --list' '
'git config --list > output && cmp output expect' git config --list > output &&
test_cmp expect output
'
cat > expect << EOF cat > expect << EOF
EOF EOF
@ -332,8 +357,10 @@ beta.noindent sillyValue
nextsection.nonewline wow2 for me nextsection.nonewline wow2 for me
EOF EOF
test_expect_success '--get-regexp' \ test_expect_success '--get-regexp' '
'git config --get-regexp in > output && cmp output expect' git config --get-regexp in >output &&
test_cmp expect output
'
cat > expect << EOF cat > expect << EOF
wow2 for me wow2 for me
@ -353,41 +380,48 @@ cat > .git/config << EOF
variable = variable =
EOF EOF
test_expect_success 'get variable with no value' \ test_expect_success 'get variable with no value' '
'git config --get novalue.variable ^$' git config --get novalue.variable ^$
'
test_expect_success 'get variable with empty value' \ test_expect_success 'get variable with empty value' '
'git config --get emptyvalue.variable ^$' git config --get emptyvalue.variable ^$
'
echo novalue.variable > expect echo novalue.variable > expect
test_expect_success 'get-regexp variable with no value' \ test_expect_success 'get-regexp variable with no value' '
'git config --get-regexp novalue > output && git config --get-regexp novalue > output &&
cmp output expect' test_cmp expect output
'
echo 'novalue.variable true' > expect echo 'novalue.variable true' > expect
test_expect_success 'get-regexp --bool variable with no value' \ test_expect_success 'get-regexp --bool variable with no value' '
'git config --bool --get-regexp novalue > output && git config --bool --get-regexp novalue > output &&
cmp output expect' test_cmp expect output
'
echo 'emptyvalue.variable ' > expect echo 'emptyvalue.variable ' > expect
test_expect_success 'get-regexp variable with empty value' \ test_expect_success 'get-regexp variable with empty value' '
'git config --get-regexp emptyvalue > output && git config --get-regexp emptyvalue > output &&
cmp output expect' test_cmp expect output
'
echo true > expect echo true > expect
test_expect_success 'get bool variable with no value' \ test_expect_success 'get bool variable with no value' '
'git config --bool novalue.variable > output && git config --bool novalue.variable > output &&
cmp output expect' test_cmp expect output
'
echo false > expect echo false > expect
test_expect_success 'get bool variable with empty value' \ test_expect_success 'get bool variable with empty value' '
'git config --bool emptyvalue.variable > output && git config --bool emptyvalue.variable > output &&
cmp output expect' test_cmp expect output
'
test_expect_success 'no arguments, but no crash' ' test_expect_success 'no arguments, but no crash' '
test_must_fail git config >output 2>&1 && test_must_fail git config >output 2>&1 &&
@ -427,8 +461,9 @@ test_expect_success 'new variable inserts into proper section' '
test_cmp expect .git/config test_cmp expect .git/config
' '
test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \ test_expect_success 'alternative GIT_CONFIG (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
'
cat > other-config << EOF cat > other-config << EOF
[ein] [ein]
@ -444,8 +479,10 @@ test_expect_success 'alternative GIT_CONFIG' '
test_cmp expect output test_cmp expect output
' '
test_expect_success 'alternative GIT_CONFIG (--file)' \ test_expect_success 'alternative GIT_CONFIG (--file)' '
'git config --file other-config -l > output && cmp output expect' git config --file other-config -l > output &&
test_cmp expect output
'
test_expect_success 'refer config from subdirectory' ' test_expect_success 'refer config from subdirectory' '
mkdir x && mkdir x &&
@ -489,8 +526,9 @@ cat > .git/config << EOF
weird weird
EOF EOF
test_expect_success "rename section" \ test_expect_success 'rename section' '
"git config --rename-section branch.eins branch.zwei" git config --rename-section branch.eins branch.zwei
'
cat > expect << EOF cat > expect << EOF
# Hallo # Hallo
@ -503,17 +541,22 @@ cat > expect << EOF
weird weird
EOF EOF
test_expect_success "rename succeeded" "test_cmp expect .git/config" test_expect_success 'rename succeeded' '
test_cmp expect .git/config
'
test_expect_success "rename non-existing section" ' test_expect_success 'rename non-existing section' '
test_must_fail git config --rename-section \ test_must_fail git config --rename-section \
branch."world domination" branch.drei branch."world domination" branch.drei
' '
test_expect_success "rename succeeded" "test_cmp expect .git/config" test_expect_success 'rename succeeded' '
test_cmp expect .git/config
'
test_expect_success "rename another section" \ test_expect_success 'rename another section' '
'git config --rename-section branch."1 234 blabl/a" branch.drei' git config --rename-section branch."1 234 blabl/a" branch.drei
'
cat > expect << EOF cat > expect << EOF
# Hallo # Hallo
@ -526,14 +569,17 @@ cat > expect << EOF
weird weird
EOF EOF
test_expect_success "rename succeeded" "test_cmp expect .git/config" test_expect_success 'rename succeeded' '
test_cmp expect .git/config
'
cat >> .git/config << EOF cat >> .git/config << EOF
[branch "vier"] z = 1 [branch "vier"] z = 1
EOF EOF
test_expect_success "rename a section with a var on the same line" \ test_expect_success 'rename a section with a var on the same line' '
'git config --rename-section branch.vier branch.zwei' git config --rename-section branch.vier branch.zwei
'
cat > expect << EOF cat > expect << EOF
# Hallo # Hallo
@ -548,7 +594,9 @@ weird
z = 1 z = 1
EOF EOF
test_expect_success "rename succeeded" "test_cmp expect .git/config" test_expect_success 'rename succeeded' '
test_cmp expect .git/config
'
test_expect_success 'renaming empty section name is rejected' ' test_expect_success 'renaming empty section name is rejected' '
test_must_fail git config --rename-section branch.zwei "" test_must_fail git config --rename-section branch.zwei ""
@ -562,7 +610,9 @@ cat >> .git/config << EOF
[branch "zwei"] a = 1 [branch "vier"] [branch "zwei"] a = 1 [branch "vier"]
EOF EOF
test_expect_success "remove section" "git config --remove-section branch.zwei" test_expect_success 'remove section' '
git config --remove-section branch.zwei
'
cat > expect << EOF cat > expect << EOF
# Hallo # Hallo
@ -571,8 +621,9 @@ cat > expect << EOF
weird weird
EOF EOF
test_expect_success "section was removed properly" \ test_expect_success 'section was removed properly' '
"test_cmp expect .git/config" test_cmp expect .git/config
'
cat > expect << EOF cat > expect << EOF
[gitcvs] [gitcvs]
@ -583,7 +634,6 @@ cat > expect << EOF
EOF EOF
test_expect_success 'section ending' ' test_expect_success 'section ending' '
rm -f .git/config && rm -f .git/config &&
git config gitcvs.enabled true && git config gitcvs.enabled true &&
git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite && git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
@ -593,30 +643,25 @@ test_expect_success 'section ending' '
' '
test_expect_success numbers ' test_expect_success numbers '
git config kilo.gram 1k && git config kilo.gram 1k &&
git config mega.ton 1m && git config mega.ton 1m &&
k=$(git config --int --get kilo.gram) && echo 1024 >expect &&
test z1024 = "z$k" && echo 1048576 >>expect &&
m=$(git config --int --get mega.ton) && git config --int --get kilo.gram >actual &&
test z1048576 = "z$m" git config --int --get mega.ton >>actual &&
test_cmp expect actual
' '
cat > expect <<EOF
fatal: bad config value for 'aninvalid.unit' in .git/config
EOF
test_expect_success 'invalid unit' ' test_expect_success 'invalid unit' '
git config aninvalid.unit "1auto" && git config aninvalid.unit "1auto" &&
s=$(git config aninvalid.unit) && echo 1auto >expect &&
test "z1auto" = "z$s" && git config aninvalid.unit >actual &&
if git config --int --get aninvalid.unit 2>actual test_cmp expect actual &&
then cat > expect <<-\EOF
echo config should have failed fatal: bad config value for '\''aninvalid.unit'\'' in .git/config
false EOF
fi && test_must_fail git config --int --get aninvalid.unit 2>actual &&
cmp actual expect test_cmp actual expect
' '
cat > expect << EOF cat > expect << EOF
@ -646,7 +691,7 @@ test_expect_success bool '
git config --bool --get bool.true$i >>result git config --bool --get bool.true$i >>result
git config --bool --get bool.false$i >>result git config --bool --get bool.false$i >>result
done && done &&
cmp expect result' test_cmp expect result'
test_expect_success 'invalid bool (--get)' ' test_expect_success 'invalid bool (--get)' '
@ -680,7 +725,7 @@ test_expect_success 'set --bool' '
git config --bool bool.false2 "" && git config --bool bool.false2 "" &&
git config --bool bool.false3 nO && git config --bool bool.false3 nO &&
git config --bool bool.false4 FALSE && git config --bool bool.false4 FALSE &&
cmp expect .git/config' test_cmp expect .git/config'
cat > expect <<\EOF cat > expect <<\EOF
[int] [int]
@ -695,39 +740,37 @@ test_expect_success 'set --int' '
git config --int int.val1 01 && git config --int int.val1 01 &&
git config --int int.val2 -1 && git config --int int.val2 -1 &&
git config --int int.val3 5m && git config --int int.val3 5m &&
cmp expect .git/config' test_cmp expect .git/config
'
cat >expect <<\EOF test_expect_success 'get --bool-or-int' '
[bool] cat >.git/config <<-\EOF &&
true1 = true [bool]
true1
true2 = true true2 = true
false1 = false false = false
false2 = false [int]
[int]
int1 = 0 int1 = 0
int2 = 1 int2 = 1
int3 = -1 int3 = -1
EOF EOF
cat >expect <<-\EOF &&
test_expect_success 'get --bool-or-int' ' true
rm -f .git/config && true
( false
echo "[bool]" 0
echo true1 1
echo true2 = true -1
echo false = false EOF
echo "[int]" {
echo int1 = 0 git config --bool-or-int bool.true1 &&
echo int2 = 1 git config --bool-or-int bool.true2 &&
echo int3 = -1 git config --bool-or-int bool.false &&
) >>.git/config && git config --bool-or-int int.int1 &&
test $(git config --bool-or-int bool.true1) = true && git config --bool-or-int int.int2 &&
test $(git config --bool-or-int bool.true2) = true && git config --bool-or-int int.int3
test $(git config --bool-or-int bool.false) = false && } >actual &&
test $(git config --bool-or-int int.int1) = 0 && test_cmp expect actual
test $(git config --bool-or-int int.int2) = 1 &&
test $(git config --bool-or-int int.int3) = -1
' '
cat >expect <<\EOF cat >expect <<\EOF
@ -849,7 +892,7 @@ EOF
test_expect_success 'value continued on next line' ' test_expect_success 'value continued on next line' '
git config --list > result && git config --list > result &&
cmp result expect test_cmp result expect
' '
cat > .git/config <<\EOF cat > .git/config <<\EOF
@ -885,11 +928,12 @@ test_expect_success '--null --get-regexp' '
test_expect_success 'inner whitespace kept verbatim' ' test_expect_success 'inner whitespace kept verbatim' '
git config section.val "foo bar" && git config section.val "foo bar" &&
test "z$(git config section.val)" = "zfoo bar" echo "foo bar" >expect &&
git config section.val >actual &&
test_cmp expect actual
' '
test_expect_success SYMLINKS 'symlinked configuration' ' test_expect_success SYMLINKS 'symlinked configuration' '
ln -s notyet myconfig && ln -s notyet myconfig &&
GIT_CONFIG=myconfig git config test.frotz nitfol && GIT_CONFIG=myconfig git config test.frotz nitfol &&
test -h myconfig && test -h myconfig &&
@ -898,9 +942,15 @@ test_expect_success SYMLINKS 'symlinked configuration' '
GIT_CONFIG=myconfig git config test.xyzzy rezrov && GIT_CONFIG=myconfig git config test.xyzzy rezrov &&
test -h myconfig && test -h myconfig &&
test -f notyet && test -f notyet &&
test "z$(GIT_CONFIG=notyet git config test.frotz)" = znitfol && cat >expect <<-\EOF &&
test "z$(GIT_CONFIG=notyet git config test.xyzzy)" = zrezrov nitfol
rezrov
EOF
{
GIT_CONFIG=notyet git config test.frotz &&
GIT_CONFIG=notyet git config test.xyzzy
} >actual &&
test_cmp expect actual
' '
test_expect_success 'nonexistent configuration' ' test_expect_success 'nonexistent configuration' '
@ -932,12 +982,20 @@ test_expect_success 'check split_cmdline return' "
git commit -m 'initial commit' && git commit -m 'initial commit' &&
git config branch.master.mergeoptions 'echo \"' && git config branch.master.mergeoptions 'echo \"' &&
test_must_fail git merge master test_must_fail git merge master
" "
test_expect_success 'git -c "key=value" support' ' test_expect_success 'git -c "key=value" support' '
test "z$(git -c core.name=value config core.name)" = zvalue && cat >expect <<-\EOF &&
test "z$(git -c foo.CamelCase=value config foo.camelcase)" = zvalue && value
test "z$(git -c foo.flag config --bool foo.flag)" = ztrue && value
true
EOF
{
git -c core.name=value config core.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 core.name
' '

View File

@ -46,8 +46,7 @@ is($r->get_color("color.test.slot1", "red"), $ansi_green, "get_color");
# Save and restore STDERR; we will probably extract this into a # Save and restore STDERR; we will probably extract this into a
# "dies_ok" method and possibly move the STDERR handling to Git.pm. # "dies_ok" method and possibly move the STDERR handling to Git.pm.
open our $tmpstderr, ">&STDERR" or die "cannot save STDERR"; close STDERR; open our $tmpstderr, ">&STDERR" or die "cannot save STDERR"; close STDERR;
eval { $r->config("test.dupstring") }; is($r->config("test.dupstring"), "value2", "config: multivar");
ok($@, "config: duplicate entry in scalar context fails");
eval { $r->config_bool("test.boolother") }; eval { $r->config_bool("test.boolother") };
ok($@, "config_bool: non-boolean values fail"); ok($@, "config_bool: non-boolean values fail");
open STDERR, ">&", $tmpstderr or die "cannot restore STDERR"; open STDERR, ">&", $tmpstderr or die "cannot restore STDERR";