From 5b88532a5346a9a7e8f0e45fec14632a9bfe2c89 Mon Sep 17 00:00:00 2001 From: Jeremy Retailleau Date: Thu, 3 Sep 2020 11:24:10 -0700 Subject: Ensure that detached HEAD does not raise when comparing branch name. --- git/config.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'git/config.py') diff --git a/git/config.py b/git/config.py index b49f0790..9f09efe2 100644 --- a/git/config.py +++ b/git/config.py @@ -493,7 +493,13 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje paths += self.items(section) elif keyword == "onbranch": - if fnmatch.fnmatchcase(self._repo.active_branch.name, value): + try: + branch_name = self._repo.active_branch.name + except TypeError: + # Ignore section if active branch cannot be retrieved. + continue + + if fnmatch.fnmatchcase(branch_name, value): paths += self.items(section) return paths -- cgit v1.2.1