Skip to content

Read conditional include #1054

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add missing rules to match hierarchy path
  • Loading branch information
buddly27 committed Sep 3, 2020
commit c3fc83f2333eaee5fbcbef6df9f4ed9eb320fd11
28 changes: 16 additions & 12 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,20 +467,24 @@ def _included_paths(self):
keyword = match.group(1)
value = match.group(2).strip()

if keyword == "gitdir":
value = osp.expanduser(value)
if fnmatch.fnmatchcase(self._repo.git_dir, value):
paths += self.items(section)

elif keyword == "gitdir/i":
if keyword in ["gitdir", "gitdir/i"]:
value = osp.expanduser(value)

# Ensure that glob is always case insensitive.
value = re.sub(
r"[a-zA-Z]",
lambda m: f"[{m.group().lower()}{m.group().upper()}]",
value
)
if not any(value.startswith(s) for s in ["./", "/"]):
value = "**/" + value
if value.endswith("/"):
value += "**"

# Ensure that glob is always case insensitive if required.
if keyword.endswith("/i"):
value = re.sub(
r"[a-zA-Z]",
lambda m: "[{}{}]".format(
m.group().lower(),
m.group().upper()
),
value
)

if fnmatch.fnmatchcase(self._repo.git_dir, value):
paths += self.items(section)
Expand Down
8 changes: 8 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ def test_conditional_includes_from_git_dir(self, rw_dir):
assert not config._has_includes()
assert config._included_paths() == []

# Ensure that config is included if path in hierarchy.
with open(path1, "w") as stream:
stream.write(template.format("gitdir", "target1/", path2))

with GitConfigParser(path1, repo=repo) as config:
assert config._has_includes()
assert config._included_paths() == [("path", path2)]

@with_rw_directory
def test_conditional_includes_from_branch_name(self, rw_dir):
# Initiate mocked branch
Expand Down