diff options
Diffstat (limited to 't')
-rw-r--r-- | t/helper/test-config.c | 20 | ||||
-rwxr-xr-x | t/t1308-config-set.sh | 24 |
2 files changed, 44 insertions, 0 deletions
diff --git a/t/helper/test-config.c b/t/helper/test-config.c index 6a77552210..3605ef8ee6 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -25,6 +25,9 @@ * ascending order of priority from a config_set * constructed from files entered as arguments. * + * iterate -> iterate over all values using git_config(), and print some + * data for each + * * Examples: * * To print the value with highest priority for key "foo.bAr Baz.rock": @@ -32,6 +35,20 @@ * */ +static int iterate_cb(const char *var, const char *value, void *data) +{ + static int nr; + + if (nr++) + putchar('\n'); + + printf("key=%s\n", var); + printf("value=%s\n", value ? value : "(null)"); + printf("origin=%s\n", current_config_origin_type()); + printf("name=%s\n", current_config_name()); + + return 0; +} int main(int argc, char **argv) { @@ -134,6 +151,9 @@ int main(int argc, char **argv) printf("Value not found for \"%s\"\n", argv[2]); goto exit1; } + } else if (!strcmp(argv[1], "iterate")) { + git_config(iterate_cb, NULL); + goto exit0; } die("%s: Please check the syntax and the function name", argv[0]); diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh index 005d66dbef..d345a885a3 100755 --- a/t/t1308-config-set.sh +++ b/t/t1308-config-set.sh @@ -229,4 +229,28 @@ test_expect_success 'error on modifying repo config without repo' ' ) ' +cmdline_config="'foo.bar=from-cmdline'" +test_expect_success 'iteration shows correct origins' ' + echo "[foo]bar = from-repo" >.git/config && + echo "[foo]bar = from-home" >.gitconfig && + cat >expect <<-EOF && + key=foo.bar + value=from-home + origin=file + name=$(pwd)/.gitconfig + + key=foo.bar + value=from-repo + origin=file + name=.git/config + + key=foo.bar + value=from-cmdline + origin=command line + name= + EOF + GIT_CONFIG_PARAMETERS=$cmdline_config test-config iterate >actual && + test_cmp expect actual +' + test_done |