allow customizing /etc/gitconfig location with an environment
v2 cover allow customizing /etc/gitconfig location with an environment
This ended up growing quite a bit, and I mostly hate it.
- Patch 1 introduces GIT_CONFIG_SYSTEM_PATH environment variable that lets you point at a file other than /etc/gitconfig to pretend that your file is the system-wide configuration.
- Patch 2 is a small bugfix.
- Patches 3-7 are updates to 1300 and 1308, i.e. tests for "git config", to make them more robust, in preparation for using GIT_CONFIG_SYSTEM_PATH mechanism to point at a file during the test. It protects them a bit more than necessary in that the variables some of the tests they use when they try to see the output from "git config --get" are unlikely to appear in the fake system-wide configuration during the test (hence disabling the fake system-wide configuration has no practical effect), but nevertheless the calls are protected by explicitly telling them to read only from --local configuration file to future-proof them.
- Patch 8 is queued elsewhere already.
- Patch 9 raises the default core.abbrev to 12 and countermands it by setting it to 7 in a fake system-wide configuration file during our test. The unconditional widening of the default abbreviation size in this patch will have to be discarded, preferring the approach Linus is taking to auto-size it based on the number of objects in the repository, but the part that updates the test script may still be necessary.
Jeff King (1):
t1300: check also system-wide configuration file in --show-origin
tests
Junio C Hamano (8):
config: allow customizing /etc/gitconfig location with an environment
t1300: always compare expect to actual
t1308: ignore system-wide config in the iteration test
t1300: disable system-wide config for tests that wants to read from -c
t1300: take contents of system-wide configuration into account in
"--list" test
t1300: be explicit in local configuration tests
worktree: honor configuration variables core.abbrev: raise the default abbreviation to 12 hexdigits
builtin/worktree.c | 2 + cache.h | 1 + config.c | 2 + environment.c | 2 +- t/gitconfig-for-test | 9 ++++ t/t1300-repo-config.sh | 120 ++++++++++++++++++++++++++++++------------------- t/t1308-config-set.sh | 1 + t/test-lib.sh | 4 +- 8 files changed, 93 insertions(+), 48 deletions(-) create mode 100644 t/gitconfig-for-test
Signature · 1 line
2.10.0-589-g5adf4e1
PATCH v2 1/9 config: allow customizing /etc/gitconfig location with an environment
We introduced GIT_CONFIG_NOSYSTEM environment variable at ab88c363 ("allow suppressing of global and system config", 2008-02-06), primarily to protect our tests from random set of configuration variables the system administrators would put in /etc/gitconfig file.
Introduce a new environment variable GIT_CONFIG_SYSTEM_PATH, and allow the users to specify a file that is used instead of /etc/gitconfig to read (and write) the system-wide configuration. By doing so, we can force our tests to honor certain configuration settings by default by pointing GIT_CONFIG_SYSTEM_PATH at our own, in addition to the existing GIT_CONFIG_NOSYSTEM mechanism.
--- cache.h | 1 + config.c | 2 ++ t/gitconfig-for-test | 6 ++++++ t/t1300-repo-config.sh | 15 +++++++++++++++ t/test-lib.sh | 4 ++-- 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 t/gitconfig-for-test
cache.h +1 -0
@@ -408,6 +408,7 @@ static inline enum object_type object_type(unsigned int mode)#define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE"#define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"#define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX" +#define GIT_CONFIG_SYSTEM_PATH_ENVIRONMENT "GIT_CONFIG_SYSTEM_PATH"#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
config.c +2 -0
@@ -1253,6 +1253,8 @@ const char *git_etc_gitconfig(void) {static const char *system_wide;if (!system_wide) + system_wide =getenv (GIT_CONFIG_SYSTEM_PATH_ENVIRONMENT ); +if (!system_wide) system_wide =system_path (ETC_GITCONFIG );return system_wide; }
t/gitconfig-for-test new file +6 -0
@@ -0,0 +1,6 @@ +;; This file is used as if it were /etc/gitconfig while running the +;; test scripts in this directory. +;; +;; [user] +;; name = A U Thor +;; email = [email protected]
t/t1300-repo-config.sh +15 -0
@@ -1372,4 +1372,19 @@ test_expect_success !MINGW '--show-origin blob ref' ' test_cmp expect output ' +test_expect_success 'system-wide configuration' ' + system="$TRASH_DIRECTORY/system-wide" && + >"$system" && + git config -f "$system" --add frotz.nitfol xyzzy && + + git config -f "$system" frotz.nitfol >expect && + GIT_CONFIG_SYSTEM_PATH="$system" \ + git config --system frotz.nitfol >actual && + + GIT_CONFIG_SYSTEM_PATH="$system" \ + git config --system --replace-all frotz.nitfol blorb && + echo blorb >expect && + GIT_CONFIG_SYSTEM_PATH="$system" git config --system frotz.nitfol >actual +' + test_done
t/test-lib.sh +2 -2
@@ -851,9 +851,9 @@ else # normal case, use ../bin-wrappers only unless $with_dashes: fi fi GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt -GIT_CONFIG_NOSYSTEM=1 +GIT_CONFIG_SYSTEM_PATH="$GIT_BUILD_DIR/t/gitconfig-for-test" GIT_ATTR_NOSYSTEM=1 -export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM +export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_SYSTEM_PATH GIT_ATTR_NOSYSTEM if test -z "$GIT_TEST_CMP" then
Signature · 1 line
2.10.0-589-g5adf4e1
PATCH v2 2/9 t1300: always compare expect to actual
In reply to Junio C HamanoThe two arguments to the test_cmp helper should always have the expected output first and then the actual one, so that an unmet expectation would appear as
-what we wanted to see
+what we actually saw
in its output.
--- t/t1300-repo-config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t1300-repo-config.sh +1 -1
@@ -936,7 +936,7 @@ EOF test_expect_success 'value continued on next line' ' git config --list > result && - test_cmp result expect + test_cmp expect result ' cat > .git/config <<\EOF
Signature · 1 line
2.10.0-589-g5adf4e1
PATCH v2 3/9 t1308: ignore system-wide config in the iteration test
In reply to Junio C HamanoWe do not want to keep track of the exact contents of the fake system-wide t/gitconfig-for-test configuration file. Keep ignoring it as we used to.
--- t/t1308-config-set.sh | 1 + 1 file changed, 1 insertion(+)
t/t1308-config-set.sh +1 -0
@@ -260,6 +260,7 @@ test_expect_success 'iteration shows correct origins' ' name= scope=cmdline EOF + GIT_CONFIG_NOSYSTEM=1 \ GIT_CONFIG_PARAMETERS=$cmdline_config test-config iterate >actual && test_cmp expect actual '
Signature · 1 line
2.10.0-589-g5adf4e1
PATCH v2 4/9 t1300: check also system-wide configuration file in --show-origin tests
In reply to Junio C HamanoFrom: Jeff King <[email protected]>
Because we used to run our tests with GIT_CONFIG_NOSYSTEM, these did not test that the system-wide configuration file is also read and shown as one of the origins. Create a custom/fake system-wide configuration file and make sure it appears in the output, using the newly introduced GIT_CONFIG_SYSTEM_PATH mechanism.
--- t/t1300-repo-config.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
t/t1300-repo-config.sh +14 -1
@@ -1236,6 +1236,11 @@ test_expect_success 'set up --show-origin tests' ' [user] relative = include EOF + cat >"$HOME"/etc-gitconfig <<-\EOF && + [user] + system = true + override = system + EOF cat >"$HOME"/.gitconfig <<-EOF && [user] global = true
@@ -1254,6 +1259,8 @@ test_expect_success 'set up --show-origin tests' ' test_expect_success '--show-origin with --list' ' cat >expect <<-EOF && + file:$HOME/etc-gitconfig user.system=true + file:$HOME/etc-gitconfig user.override=system file:$HOME/.gitconfig user.global=true file:$HOME/.gitconfig user.override=global file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
@@ -1264,13 +1271,16 @@ test_expect_success '--show-origin with --list' ' file:.git/../include/relative.include user.relative=include command line: user.cmdline=true EOF + GIT_CONFIG_SYSTEM_PATH=$HOME/etc-gitconfig \ git -c user.cmdline=true config --list --show-origin >output && test_cmp expect output ' test_expect_success '--show-origin with --list --null' ' cat >expect <<-EOF && - file:$HOME/.gitconfigQuser.global + file:$HOME/etc-gitconfigQuser.system + trueQfile:$HOME/etc-gitconfigQuser.override + systemQfile:$HOME/.gitconfigQuser.global trueQfile:$HOME/.gitconfigQuser.override globalQfile:$HOME/.gitconfigQinclude.path $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
@@ -1281,6 +1291,7 @@ test_expect_success '--show-origin with --list --null' ' includeQcommand line:Quser.cmdline trueQ EOF + GIT_CONFIG_SYSTEM_PATH=$HOME/etc-gitconfig \ git -c user.cmdline=true config --null --list --show-origin >output.raw && nul_to_q <output.raw >output && # The here-doc above adds a newline that the --null output would not
@@ -1304,6 +1315,7 @@ test_expect_success '--show-origin with --get-regexp' ' file:$HOME/.gitconfig user.global true file:.git/config user.local true EOF + GIT_CONFIG_SYSTEM_PATH=$HOME/etc-gitconfig \ git config --show-origin --get-regexp "user\.[g|l].*" >output && test_cmp expect output '
@@ -1312,6 +1324,7 @@ test_expect_success '--show-origin getting a single key' ' cat >expect <<-\EOF && file:.git/config local EOF + GIT_CONFIG_SYSTEM_PATH=$HOME/etc-gitconfig \ git config --show-origin user.override >output && test_cmp expect output '
Signature · 1 line
2.10.0-589-g5adf4e1
PATCH v2 5/9 t1300: disable system-wide config for tests that wants to read from -c
In reply to Junio C HamanoThis test wants to do
git -c x.two=2 config --get-regexp ^x\.*
and see x.two that came from the one-shot configuration in its output. This form cannot be limited with "--local", as it limits the input to the local configuration file and makes these one-shot settings ignored. At this point, the test knows that there is no variable that match x.* in its local configuration, and it also was OK to assume that there is nothing in the system-wide config or global one.
Make sure that assumption holds by using the GIT_CONFIG_NOSYSTEM environment, as we may add anything to t/gitconfig-for-test later.
--- t/t1300-repo-config.sh | 1 + 1 file changed, 1 insertion(+)
t/t1300-repo-config.sh +1 -0
@@ -1093,6 +1093,7 @@ test_expect_success 'multiple git -c appends config' ' x.one 1 x.two 2 EOF + GIT_CONFIG_NOSYSTEM=1 \ git -c x.one=1 x >actual && test_cmp expect actual '
Signature · 1 line
2.10.0-589-g5adf4e1
PATCH v2 6/9 t1300: take contents of system-wide configuration into account in "--list" test
In reply to Junio C HamanoOne of the "git config" test tries to see that the command run without a valid repository still shows non-repository specific configuration. As we are planning to later make the system-wide file non-empty, prepare for the change by expecting to see the contents from it.
--- t/t1300-repo-config.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
t/t1300-repo-config.sh +4 -3
@@ -344,10 +344,11 @@ test_expect_success 'working --list' ' git config --list > output && test_cmp expect output ' -cat > expect << EOF -EOF -test_expect_success '--list without repo produces empty output' ' +test_expect_success '--list without repo shows only system-wide and global' ' + # The global one aka $HOME/.gitconfig is missing, + # so we do not have to worry about it. + git config --system --list >expect && git --git-dir=nonexistent config --list >output && test_cmp expect output '
Signature · 1 line
2.10.0-589-g5adf4e1
PATCH v2 7/9 t1300: be explicit in local configuration tests
In reply to Junio C HamanoMany tests in this script prepare variable settings in the repository local configuration and expects "--list" to report only the ones from the repository local configuration.
This happened to work while we were running out tests under GIT_CONFIG_NOSYSTEM and/or with an empty system-wide configuration file, but as we will soon make our fake system-wide configuration non-empty, prepare for that change by explicitly telling the command to look only at "--local" configuration.
--- t/t1300-repo-config.sh | 80 +++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 40 deletions(-)
t/t1300-repo-config.sh +40 -40
@@ -245,18 +245,18 @@ test_expect_success 'multivar' ' ' test_expect_success 'non-match' ' - git config --get nextsection.nonewline !for + git config --local --get nextsection.nonewline !for ' test_expect_success 'non-match value' ' echo wow >expect && - git config --get nextsection.nonewline !for >actual && + git config --local --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 && + git config --local --get nextsection.nonewline >actual && test_cmp expect actual '
@@ -265,7 +265,7 @@ test_expect_success 'multi-valued get-all returns all' ' wow wow2 for me EOF - git config --get-all nextsection.nonewline >actual && + git config --local --get-all nextsection.nonewline >actual && test_cmp expect actual '
@@ -341,7 +341,7 @@ version.1.2.3eX.alpha=beta EOF test_expect_success 'working --list' ' - git config --list > output && + git config --local --list > output && test_cmp expect output '
@@ -361,7 +361,7 @@ version.1.2.3eX.alpha EOF test_expect_success '--name-only --list' ' - git config --name-only --list >output && + git config --local --name-only --list >output && test_cmp expect output '
@@ -371,7 +371,7 @@ nextsection.nonewline wow2 for me EOF test_expect_success '--get-regexp' ' - git config --get-regexp in >output && + git config --local --get-regexp in >output && test_cmp expect output '
@@ -381,7 +381,7 @@ nextsection.nonewline EOF test_expect_success '--name-only --get-regexp' ' - git config --name-only --get-regexp in >output && + git config --local --name-only --get-regexp in >output && test_cmp expect output '
@@ -392,7 +392,7 @@ EOF test_expect_success '--add' ' git config --add nextsection.nonewline "wow4 for you" && - git config --get-all nextsection.nonewline > output && + git config --local --get-all nextsection.nonewline > output && test_cmp expect output '
@@ -404,45 +404,45 @@ cat > .git/config << EOF EOF test_expect_success 'get variable with no value' ' - git config --get novalue.variable ^$ + git config --local --get novalue.variable ^$ ' test_expect_success 'get variable with empty value' ' - git config --get emptyvalue.variable ^$ + git config --local --get emptyvalue.variable ^$ ' echo novalue.variable > expect test_expect_success 'get-regexp variable with no value' ' - git config --get-regexp novalue > output && + git config --local --get-regexp novalue > output && test_cmp expect output ' echo 'novalue.variable true' > expect test_expect_success 'get-regexp --bool variable with no value' ' - git config --bool --get-regexp novalue > output && + git config --local --bool --get-regexp novalue > output && test_cmp expect output ' echo 'emptyvalue.variable ' > expect test_expect_success 'get-regexp variable with empty value' ' - git config --get-regexp emptyvalue > output && + git config --local --get-regexp emptyvalue > output && test_cmp expect output ' echo true > expect test_expect_success 'get bool variable with no value' ' - git config --bool novalue.variable > output && + git config --local --bool novalue.variable > output && test_cmp expect output ' echo false > expect test_expect_success 'get bool variable with empty value' ' - git config --bool emptyvalue.variable > output && + git config --local --bool emptyvalue.variable > output && test_cmp expect output '
@@ -683,15 +683,15 @@ test_expect_success numbers ' git config mega.ton 1m && echo 1024 >expect && echo 1048576 >>expect && - git config --int --get kilo.gram >actual && - git config --int --get mega.ton >>actual && + git config --local --int --get kilo.gram >actual && + git config --local --int --get mega.ton >>actual && test_cmp expect actual ' test_expect_success '--int is at least 64 bits' ' git config giga.watts 121g && echo 129922760704 >expect && - git config --int --get giga.watts >actual && + git config --local --int --get giga.watts >actual && test_cmp expect actual '
@@ -700,7 +700,7 @@ test_expect_success 'invalid unit' ' echo 1auto >expect && git config aninvalid.unit >actual && test_cmp expect actual && - test_must_fail git config --int --get aninvalid.unit 2>actual && + test_must_fail git config --local --int --get aninvalid.unit 2>actual && test_i18ngrep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual '
@@ -733,15 +733,15 @@ test_expect_success bool ' rm -f result && for i in 1 2 3 4 do - git config --bool --get bool.true$i >>result - git config --bool --get bool.false$i >>result + git config --local --bool --get bool.true$i >>result + git config --local --bool --get bool.false$i >>result done && test_cmp expect result' test_expect_success 'invalid bool (--get)' ' git config bool.nobool foobar && - test_must_fail git config --bool --get bool.nobool' + test_must_fail git config --local --bool --get bool.nobool' test_expect_success 'invalid bool (set)' '
@@ -808,12 +808,12 @@ test_expect_success 'get --bool-or-int' ' -1 EOF { - git config --bool-or-int bool.true1 && - git config --bool-or-int bool.true2 && - git config --bool-or-int bool.false && - git config --bool-or-int int.int1 && - git config --bool-or-int int.int2 && - git config --bool-or-int int.int3 + git config --local --bool-or-int bool.true1 && + git config --local --bool-or-int bool.true2 && + git config --local --bool-or-int bool.false && + git config --local --bool-or-int int.int1 && + git config --local --bool-or-int int.int2 && + git config --local --bool-or-int int.int3 } >actual && test_cmp expect actual '
@@ -868,9 +868,9 @@ foo~ EOF test_expect_success HOMEVAR 'get --path' ' - git config --get --path path.home > result && - git config --get --path path.normal >> result && - git config --get --path path.trailingtilde >> result && + git config --local --get --path path.home > result && + git config --local --get --path path.normal >> result && + git config --local --get --path path.trailingtilde >> result && test_cmp expect result '
@@ -882,10 +882,10 @@ EOF test_expect_success !MINGW 'get --path copes with unset $HOME' ' ( unset HOME; - test_must_fail git config --get --path path.home \ + test_must_fail git config --local --get --path path.home \ >result 2>msg && - git config --get --path path.normal >>result && - git config --get --path path.trailingtilde >>result + git config --local --get --path path.normal >>result && + git config --local --get --path path.trailingtilde >>result ) && test_i18ngrep "[Ff]ailed to expand.*~/" msg && test_cmp expect result
@@ -893,7 +893,7 @@ test_expect_success !MINGW 'get --path copes with unset $HOME' ' test_expect_success 'get --path barfs on boolean variable' ' echo "[path]bool" >.git/config && - test_must_fail git config --get --path path.bool + test_must_fail git config --local --get --path path.bool ' cat > expect << EOF
@@ -936,7 +936,7 @@ section.quotecont=cont;inued EOF test_expect_success 'value continued on next line' ' - git config --list > result && + git config --local --list > result && test_cmp expect result '
@@ -960,14 +960,14 @@ Qsection.sub=section.val4 Qsection.sub=section.val5Q EOF test_expect_success '--null --list' ' - git config --null --list >result.raw && + git config --local --null --list >result.raw && nul_to_q <result.raw >result && echo >>result && test_cmp expect result ' test_expect_success '--null --get-regexp' ' - git config --null --get-regexp "val[0-9]" >result.raw && + git config --local --null --get-regexp "val[0-9]" >result.raw && nul_to_q <result.raw >result && echo >>result && test_cmp expect result
@@ -1127,7 +1127,7 @@ test_expect_success 'barf on syntax error' ' [section] key garbage EOF - test_must_fail git config --get section.key >actual 2>error && + test_must_fail git config --local --get section.key >actual 2>error && test_i18ngrep " line 3 " error '
Signature · 1 line
2.10.0-589-g5adf4e1
PATCH v2 8/9 worktree: honor configuration variables
In reply to Junio C HamanoThe command accesses default_abbrev (defined in environment.c and is updated via core.abbrev configuration), but never makes any call to git_config(). The output from "worktree list" ignores the abbrev setting for this reason.
Make a call to git_config() to read the default set of configuration variables at the beginning of the command.
--- builtin/worktree.c | 2 ++ 1 file changed, 2 insertions(+)
builtin/worktree.c +2 -0
@@ -528,6 +528,8 @@ int cmd_worktree(int ac, const char **av, const char *prefix) OPT_END() }; +git_config (git_default_config,NULL ); +if (ac <2 )usage_with_options (worktree_usage, options);if (!prefix)
Signature · 1 line
2.10.0-589-g5adf4e1
PATCH v2 9/9 core.abbrev: raise the default abbreviation to 12 hexdigits
In reply to Junio C HamanoAs Peff said, responding in a thread started by Linus's suggestion to raise the default abbreviation to 12 hexdigits:
I actually think "12" might be sane for a long time. That's 48 bits of sha1, so we'd expect a 50% chance of a single collision at 2^24, or 16 million. The biggest repository I know about (in number of objects) is the one holding all of the objects for all of the forks of torvalds/linux on GitHub. It's at about 15 million objects.
Which seems close, but remember that's the size where we expect to see a single collision. They don't become common until much later (I didn't compute an exact number, but Linus's 16x sounds about right). I know that the growth of the kernel isn't really linear, but I think the need to bump to "13" might not just be decades, but possibly a century or more.
So 12 seems reasonable, and the only downside for it (or for "13", for that matter) is a few extra bytes. I dunno, maybe people will really hate that, but I have a feeling these are mostly cut-and-pasted anyway.
And this does exactly that.
Keep the tests working by explicitly asking for the old 7 hexdigits setting in the fake system-wide configuration file used for tests.
--- environment.c | 2 +- t/gitconfig-for-test | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
environment.c +1 -1
@@ -16,7 +16,7 @@ int trust_executable_bit = 1;int trust_ctime =1 ;int check_stat =1 ;int has_symlinks =1 ; -int minimum_abbrev =4 , default_abbrev =7 ; +int minimum_abbrev =4 , default_abbrev =12 ;int ignore_case;int assume_unchanged;int prefer_symlink_refs;
t/gitconfig-for-test +3 -0
@@ -4,3 +4,6 @@ ;; [user] ;; name = A U Thor ;; email = [email protected] + +[core] + abbrev = 7
Signature · 1 line
2.10.0-589-g5adf4e1