Skip to content

Commit 03126bf

Browse files
authored
Merge pull request #700 from yarikoptic/bf-includes
BF: process included files before the rest
2 parents d571046 + 0a6cb4a commit 03126bf

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

git/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ def read(self):
424424
if include_path in seen or not os.access(include_path, os.R_OK):
425425
continue
426426
seen.add(include_path)
427-
files_to_read.append(include_path)
427+
# insert included file to the top to be considered first
428+
files_to_read.insert(0, include_path)
428429
num_read_include_files += 1
429430
# each include path in configuration file
430431
# end handle includes

git/test/fixtures/git_config

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,25 @@
2222
url = git://gitorious.org/~martin.marcher/git-python/serverhorror.git
2323
fetch = +refs/heads/*:refs/remotes/MartinMarcher/*
2424
# can handle comments - the section name is supposed to be stripped
25+
# causes stock git-config puke
2526
[ gui ]
2627
geometry = 1316x820+219+243 207 192
2728
[branch "mainline_performance"]
2829
remote = mainline
2930
merge = refs/heads/master
31+
# section with value defined before include to be overriden
32+
[sec]
33+
var0 = value0_main
3034
[include]
31-
path = doesntexist.cfg
32-
abspath = /usr/bin/foodoesntexist.bar
35+
path = doesntexist.cfg
36+
# field should be 'path' so abspath should be ignored
37+
abspath = /usr/bin/foodoesntexist.bar
38+
path = /usr/bin/foodoesntexist.bar
39+
# should be relative to the path of this config file
40+
path = ./git_config-inc.cfg
41+
# and defined after include. According to the documentation
42+
# and behavior of git config, this should be the value since
43+
# inclusions should be processed immediately
44+
[sec]
45+
var1 = value1_main
46+

git/test/fixtures/git_config-inc.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[sec]
2+
var0 = value0_included
3+
var1 = value1_included
4+
[diff]
5+
tool = diff_included

git/test/lib/helper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import unittest
3030

3131
TestCase = unittest.TestCase
32+
SkipTest = unittest.SkipTest
33+
skipIf = unittest.skipIf
3234

3335
ospd = osp.dirname
3436

@@ -37,7 +39,9 @@
3739

3840
__all__ = (
3941
'fixture_path', 'fixture', 'StringProcessAdapter',
40-
'with_rw_directory', 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase',
42+
'with_rw_directory', 'with_rw_repo', 'with_rw_and_rw_remote_repo',
43+
'TestBase', 'TestCase',
44+
'SkipTest', 'skipIf',
4145
'GIT_REPO', 'GIT_DAEMON_PORT'
4246
)
4347

git/test/test_config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from git.test.lib import (
1616
TestCase,
1717
fixture_path,
18+
SkipTest,
1819
)
1920
from git.test.lib import with_rw_directory
2021

@@ -88,6 +89,21 @@ def test_read_write(self):
8889
assert r_config.get(sname, oname) == val
8990
# END for each filename
9091

92+
def test_includes_order(self):
93+
with GitConfigParser(list(map(fixture_path, ("git_config", "git_config_global")))) as r_config:
94+
r_config.read() # enforce reading
95+
# Simple inclusions, again checking them taking precedence
96+
assert r_config.get_value('sec', 'var0') == "value0_included"
97+
# This one should take the git_config_global value since included
98+
# values must be considered as soon as they get them
99+
assert r_config.get_value('diff', 'tool') == "meld"
100+
try:
101+
assert r_config.get_value('sec', 'var1') == "value1_main"
102+
except AssertionError:
103+
raise SkipTest(
104+
'Known failure -- included values are not in effect right away'
105+
)
106+
91107
@with_rw_directory
92108
def test_lock_reentry(self, rw_dir):
93109
fpl = osp.join(rw_dir, 'l')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy