|
7 | 7 | import io |
8 | 8 | import os |
9 | 9 | import os.path as osp |
10 | | -import sys |
11 | 10 | from unittest import mock |
12 | 11 |
|
13 | 12 | import pytest |
14 | 13 |
|
15 | 14 | from git import GitConfigParser |
16 | 15 | from git.config import _OMD, cp |
17 | | -from git.util import rmfile |
| 16 | +from git.util import cwd, rmfile |
18 | 17 |
|
19 | 18 | from test.lib import SkipTest, TestCase, fixture_path, with_rw_directory |
20 | 19 |
|
@@ -374,6 +373,22 @@ def test_config_relative_path_include(self, rw_dir): |
374 | 373 | with GitConfigParser(relative_config_path, read_only=True) as cr: |
375 | 374 | assert cr.get_value("included", "value") == "included" |
376 | 375 |
|
| 376 | + @pytest.mark.skipif(os.name != "nt", reason="Specifically for Windows drive-rooted paths.") |
| 377 | + @with_rw_directory |
| 378 | + def test_config_drive_rooted_path_include(self, rw_dir): |
| 379 | + with cwd(rw_dir): |
| 380 | + included_path = osp.join(rw_dir, "included") |
| 381 | + with GitConfigParser(included_path, read_only=False) as cw: |
| 382 | + cw.set_value("included", "value", "included") |
| 383 | + |
| 384 | + _drive, rooted_included_path = osp.splitdrive(included_path) |
| 385 | + config_path = osp.join(rw_dir, "config") |
| 386 | + with GitConfigParser(config_path, read_only=False) as cw: |
| 387 | + cw.set_value("include", "path", rooted_included_path) |
| 388 | + |
| 389 | + with GitConfigParser(config_path, read_only=True) as cr: |
| 390 | + assert cr.get_value("included", "value") == "included" |
| 391 | + |
377 | 392 | @with_rw_directory |
378 | 393 | def test_multiple_include_paths_with_same_key(self, rw_dir): |
379 | 394 | """Test that multiple 'path' entries under [include] are all respected. |
@@ -411,11 +426,6 @@ def test_multiple_include_paths_with_same_key(self, rw_dir): |
411 | 426 | assert cr.get_value("user", "name") == "from-inc1" |
412 | 427 | assert cr.get_value("core", "bar") == "from-inc2" |
413 | 428 |
|
414 | | - @pytest.mark.xfail( |
415 | | - sys.platform == "win32", |
416 | | - reason='Second config._has_includes() assertion fails (for "config is included if path is matching git_dir")', |
417 | | - raises=AssertionError, |
418 | | - ) |
419 | 429 | @with_rw_directory |
420 | 430 | def test_conditional_includes_from_git_dir(self, rw_dir): |
421 | 431 | # Initiate repository path. |
@@ -443,6 +453,14 @@ def test_conditional_includes_from_git_dir(self, rw_dir): |
443 | 453 | assert config._has_includes() |
444 | 454 | assert config._included_paths() == [("path", path2)] |
445 | 455 |
|
| 456 | + # Ensure that Git's forward-slash syntax matches native Windows paths. |
| 457 | + with open(path1, "w") as stream: |
| 458 | + stream.write(template.format("gitdir", git_dir.replace("\\", "/"), path2)) |
| 459 | + |
| 460 | + with GitConfigParser(path1, repo=repo) as config: |
| 461 | + assert config._has_includes() |
| 462 | + assert config._included_paths() == [("path", path2)] |
| 463 | + |
446 | 464 | # Ensure that config is ignored if case is incorrect. |
447 | 465 | with open(path1, "w") as stream: |
448 | 466 | stream.write(template.format("gitdir", git_dir.upper(), path2)) |
|
0 commit comments