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
Prev Previous commit
Next Next commit
Reformat code to remove unnecessary indentation
  • Loading branch information
buddly27 committed Sep 3, 2020
commit 3787f622e59c2fecfa47efc114c409f51a27bbe7
60 changes: 31 additions & 29 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,35 +464,37 @@ def _included_paths(self):
paths += self.items(section)

match = CONDITIONAL_INCLUDE_REGEXP.search(section)
if match is not None and self._repo is not None:
keyword = match.group(1)
value = match.group(2).strip()

if keyword in ["gitdir", "gitdir/i"]:
value = osp.expanduser(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)

elif keyword == "onbranch":
if fnmatch.fnmatchcase(self._repo.active_branch.name, value):
paths += self.items(section)
if match is None or self._repo is None:
continue

keyword = match.group(1)
value = match.group(2).strip()

if keyword in ["gitdir", "gitdir/i"]:
value = osp.expanduser(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)

elif keyword == "onbranch":
if fnmatch.fnmatchcase(self._repo.active_branch.name, value):
paths += self.items(section)

return paths

Expand Down