From cd6e82cfa3bdc3b5d75317431d58cc6efb710b1d Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Mon, 27 Nov 2017 17:12:14 -0500 Subject: BF: process included files before the rest --- git/config.py | 3 ++- git/test/fixtures/git_config | 18 ++++++++++++++++-- git/test/fixtures/git_config-inc.cfg | 5 +++++ git/test/lib/helper.py | 6 +++++- git/test/test_config.py | 16 ++++++++++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 git/test/fixtures/git_config-inc.cfg diff --git a/git/config.py b/git/config.py index 7d962276..3310db89 100644 --- a/git/config.py +++ b/git/config.py @@ -424,7 +424,8 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje if include_path in seen or not os.access(include_path, os.R_OK): continue seen.add(include_path) - files_to_read.append(include_path) + # insert included file to the top to be considered first + files_to_read.insert(0, include_path) num_read_include_files += 1 # each include path in configuration file # end handle includes diff --git a/git/test/fixtures/git_config b/git/test/fixtures/git_config index c9945cd5..b8c178e3 100644 --- a/git/test/fixtures/git_config +++ b/git/test/fixtures/git_config @@ -22,11 +22,25 @@ url = git://gitorious.org/~martin.marcher/git-python/serverhorror.git fetch = +refs/heads/*:refs/remotes/MartinMarcher/* # can handle comments - the section name is supposed to be stripped +# causes stock git-config puke [ gui ] geometry = 1316x820+219+243 207 192 [branch "mainline_performance"] remote = mainline merge = refs/heads/master +# section with value defined before include to be overriden +[sec] + var0 = value0_main [include] - path = doesntexist.cfg - abspath = /usr/bin/foodoesntexist.bar \ No newline at end of file + path = doesntexist.cfg + # field should be 'path' so abspath should be ignored + abspath = /usr/bin/foodoesntexist.bar + path = /usr/bin/foodoesntexist.bar + # should be relative to the path of this config file + path = ./git_config-inc.cfg +# and defined after include. According to the documentation +# and behavior of git config, this should be the value since +# inclusions should be processed immediately +[sec] + var1 = value1_main + diff --git a/git/test/fixtures/git_config-inc.cfg b/git/test/fixtures/git_config-inc.cfg new file mode 100644 index 00000000..2368ec20 --- /dev/null +++ b/git/test/fixtures/git_config-inc.cfg @@ -0,0 +1,5 @@ +[sec] + var0 = value0_included + var1 = value1_included +[diff] + tool = diff_included diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index 729c76a4..8ecfbf09 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -29,6 +29,8 @@ else: import unittest TestCase = unittest.TestCase +SkipTest = unittest.SkipTest +skipIf = unittest.skipIf ospd = osp.dirname @@ -37,7 +39,9 @@ GIT_DAEMON_PORT = os.environ.get("GIT_PYTHON_TEST_GIT_DAEMON_PORT", "19418") __all__ = ( 'fixture_path', 'fixture', 'StringProcessAdapter', - 'with_rw_directory', 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', + 'with_rw_directory', 'with_rw_repo', 'with_rw_and_rw_remote_repo', + 'TestBase', 'TestCase', + 'SkipTest', 'skipIf', 'GIT_REPO', 'GIT_DAEMON_PORT' ) diff --git a/git/test/test_config.py b/git/test/test_config.py index 7cf9d317..c2bac0cb 100644 --- a/git/test/test_config.py +++ b/git/test/test_config.py @@ -15,6 +15,7 @@ from git.config import cp from git.test.lib import ( TestCase, fixture_path, + SkipTest, ) from git.test.lib import with_rw_directory @@ -88,6 +89,21 @@ class TestBase(TestCase): assert r_config.get(sname, oname) == val # END for each filename + def test_includes_order(self): + with GitConfigParser(map(fixture_path, ("git_config", "git_config_global"))) as r_config: + r_config.read() # enforce reading + # Simple inclusions, again checking them taking precedence + assert r_config.get_value('sec', 'var0') == "value0_included" + # This one should take the git_config_global value since included + # values must be considered as soon as they get them + assert r_config.get_value('diff', 'tool') == "meld" + try: + assert r_config.get_value('sec', 'var1') == "value1_main" + except AssertionError: + raise SkipTest( + 'Known failure -- included values are not in effect right away' + ) + @with_rw_directory def test_lock_reentry(self, rw_dir): fpl = osp.join(rw_dir, 'l') -- cgit v1.2.1