| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,7 +66,7 @@ | |||
| 66 | 66 | CONFIG_LEVELS: ConfigLevels_Tup = ("system", "user", "global", "repository") | |
| 67 | 67 | """The configuration level of a configuration file.""" | |
| 68 | 68 | ||
| 69 | - CONDITIONAL_INCLUDE_REGEXP = re.compile(r"(?<=includeIf )\"(gitdir|gitdir/i|onbranch):(.+)\"") | ||
| 69 | + CONDITIONAL_INCLUDE_REGEXP = re.compile(r"(?<=includeIf )\"(gitdir|gitdir/i|onbranch|hasconfig:remote\.\*\.url):(.+)\"") | ||
| 70 | 70 | """Section pattern to detect conditional includes. | |
| 71 | 71 | ||
| 72 | 72 | See: https://git-scm.com/docs/git-config#_conditional_includes | |
@@ -590,7 +590,11 @@ def _included_paths(self) -> List[Tuple[str, str]]: | |||
| 590 | 590 | ||
| 591 | 591 | if fnmatch.fnmatchcase(branch_name, value): | |
| 592 | 592 | paths += self.items(section) | |
| 593 | - | ||
| 593 | + elif keyword == "hasconfig:remote.*.url": | ||
| 594 | + for remote in self._repo.remotes: | ||
| 595 | + if fnmatch.fnmatchcase(remote.url, value): | ||
| 596 | + paths += self.items(section) | ||
| 597 | + break | ||
| 594 | 598 | return paths | |
| 595 | 599 | ||
| 596 | 600 | def read(self) -> None: # type: ignore[override] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -373,6 +373,41 @@ def test_conditional_includes_from_branch_name_error(self, rw_dir): | |||
| 373 | 373 | assert not config._has_includes() | |
| 374 | 374 | assert config._included_paths() == [] | |
| 375 | 375 | ||
| 376 | + @with_rw_directory | ||
| 377 | + def test_conditional_includes_remote_url(self, rw_dir): | ||
| 378 | + # Initiate mocked repository. | ||
| 379 | + repo = mock.Mock() | ||
| 380 | + repo.remotes = [mock.Mock(url="https://github.com/foo/repo")] | ||
| 381 | + | ||
| 382 | + # Initiate config files. | ||
| 383 | + path1 = osp.join(rw_dir, "config1") | ||
| 384 | + path2 = osp.join(rw_dir, "config2") | ||
| 385 | + template = '[includeIf "hasconfig:remote.*.url:{}"]\n path={}\n' | ||
| 386 | + | ||
| 387 | + # Ensure that config with hasconfig and full url is correct. | ||
| 388 | + with open(path1, "w") as stream: | ||
| 389 | + stream.write(template.format("https://github.com/foo/repo", path2)) | ||
| 390 | + | ||
| 391 | + with GitConfigParser(path1, repo=repo) as config: | ||
| 392 | + assert config._has_includes() | ||
| 393 | + assert config._included_paths() == [("path", path2)] | ||
| 394 | + | ||
| 395 | + # Ensure that config with hasconfig and incorrect url is incorrect. | ||
| 396 | + with open(path1, "w") as stream: | ||
| 397 | + stream.write(template.format("incorrect", path2)) | ||
| 398 | + | ||
| 399 | + with GitConfigParser(path1, repo=repo) as config: | ||
| 400 | + assert not config._has_includes() | ||
| 401 | + assert config._included_paths() == [] | ||
| 402 | + | ||
| 403 | + # Ensure that config with hasconfig and url using glob pattern is correct. | ||
| 404 | + with open(path1, "w") as stream: | ||
| 405 | + stream.write(template.format("**/**github.com*/**", path2)) | ||
| 406 | + | ||
| 407 | + with GitConfigParser(path1, repo=repo) as config: | ||
| 408 | + assert config._has_includes() | ||
| 409 | + assert config._included_paths() == [("path", path2)] | ||
| 410 | + | ||
| 376 | 411 | def test_rename(self): | |
| 377 | 412 | file_obj = self._to_memcache(fixture_path("git_config")) | |
| 378 | 413 | with GitConfigParser(file_obj, read_only=False, merge_includes=False) as cw: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments