Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork960
feat: Add support for hasconfig git rule.#2075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -66,7 +66,7 @@ | ||
CONFIG_LEVELS: ConfigLevels_Tup = ("system", "user", "global", "repository") | ||
"""The configuration level of a configuration file.""" | ||
CONDITIONAL_INCLUDE_REGEXP = re.compile(r"(?<=includeIf )\"(gitdir|gitdir/i|onbranch|hasconfig:remote\.\*\.url):(.+)\"") | ||
"""Section pattern to detect conditional includes. | ||
See: https://git-scm.com/docs/git-config#_conditional_includes | ||
@@ -590,7 +590,11 @@ def _included_paths(self) -> List[Tuple[str, str]]: | ||
if fnmatch.fnmatchcase(branch_name, value): | ||
paths += self.items(section) | ||
elif keyword == "hasconfig:remote.*.url": | ||
for remote in self._repo.remotes: | ||
if fnmatch.fnmatchcase(remote.url, value): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Using a case-sensitive search is correct here, Git does the same. | ||
paths += self.items(section) | ||
break | ||
return paths | ||
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): | ||
assert not config._has_includes() | ||
assert config._included_paths() == [] | ||
@with_rw_directory | ||
def test_conditional_includes_remote_url(self, rw_dir): | ||
# Initiate mocked repository. | ||
repo = mock.Mock() | ||
repo.remotes = [mock.Mock(url="https://github.com/foo/repo")] | ||
# Initiate config files. | ||
path1 = osp.join(rw_dir, "config1") | ||
path2 = osp.join(rw_dir, "config2") | ||
template = '[includeIf "hasconfig:remote.*.url:{}"]\n path={}\n' | ||
# Ensure that config with hasconfig and full url is correct. | ||
with open(path1, "w") as stream: | ||
stream.write(template.format("https://github.com/foo/repo", path2)) | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert config._has_includes() | ||
assert config._included_paths() == [("path", path2)] | ||
# Ensure that config with hasconfig and incorrect url is incorrect. | ||
with open(path1, "w") as stream: | ||
stream.write(template.format("incorrect", path2)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think that "incorrect" fails to communicate that this is a URL that simply doesn't match. | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert not config._has_includes() | ||
assert config._included_paths() == [] | ||
# Ensure that config with hasconfig and url using glob pattern is correct. | ||
with open(path1, "w") as stream: | ||
stream.write(template.format("**/**github.com*/**", path2)) | ||
with GitConfigParser(path1, repo=repo) as config: | ||
assert config._has_includes() | ||
assert config._included_paths() == [("path", path2)] | ||
def test_rename(self): | ||
file_obj = self._to_memcache(fixture_path("git_config")) | ||
with GitConfigParser(file_obj, read_only=False, merge_includes=False) as cw: | ||
Uh oh!
There was an error while loading.Please reload this page.