summaryrefslogtreecommitdiff
path: root/t/t1308-config-set.sh
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-05-26 20:32:23 -0400
committerJunio C Hamano <gitster@pobox.com>2016-05-27 10:44:54 -0700
commit0d44a2dacc84fb7dcb5d684800e976f3b3c76d00 (patch)
tree2e66639973179ad660efd496b83eb328bd3a20de /t/t1308-config-set.sh
parent3258258f51f45efeff5ce0e9f825f347a1404efa (diff)
downloadgit-0d44a2dacc84fb7dcb5d684800e976f3b3c76d00.tar.gz
config: return configset value for current_config_ functions
When 473166b (config: add 'origin_type' to config_source struct, 2016-02-19) added accessor functions for the origin type and name, it taught them only to look at the "cf" struct that is filled in while we are parsing the config. This is sufficient to make it work with git-config, which uses git_config_with_options() under the hood. That function freshly parses the config files and triggers the callback when it parses each key. Most git programs, however, use git_config(). This interface will populate a cache during the actual parse, and then serve values from the cache. Calling current_config_filename() in a callback here will find a NULL cf and produce an error. There are no such callers right now, but let's prepare for adding some by making this work. We already record source information in a struct attached to each value. We just need to make it globally available and then consult it from the accessor functions. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t1308-config-set.sh')
-rwxr-xr-xt/t1308-config-set.sh24
1 files changed, 24 insertions, 0 deletions
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