Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5b88532

Browse files
committed
Ensure that detached HEAD does not raise when comparing branch name.
1 parent3787f62 commit5b88532

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

‎git/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,13 @@ def _included_paths(self):
493493
paths+=self.items(section)
494494

495495
elifkeyword=="onbranch":
496-
iffnmatch.fnmatchcase(self._repo.active_branch.name,value):
496+
try:
497+
branch_name=self._repo.active_branch.name
498+
exceptTypeError:
499+
# Ignore section if active branch cannot be retrieved.
500+
continue
501+
502+
iffnmatch.fnmatchcase(branch_name,value):
497503
paths+=self.items(section)
498504

499505
returnpaths

‎test/test_config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,23 @@ def test_conditional_includes_from_branch_name(self, rw_dir):
345345
assertconfig._has_includes()
346346
assertconfig._included_paths()== [("path",path2)]
347347

348+
@with_rw_directory
349+
deftest_conditional_includes_from_branch_name_error(self,rw_dir):
350+
# Initiate mocked repository to raise an error if HEAD is detached.
351+
repo=mock.Mock()
352+
type(repo).active_branch=mock.PropertyMock(side_effect=TypeError)
353+
354+
# Initiate config file.
355+
path1=osp.join(rw_dir,"config1")
356+
357+
# Ensure that config is ignored when active branch cannot be found.
358+
withopen(path1,"w")asstream:
359+
stream.write("[includeIf\"onbranch:foo\"]\n path=/path\n")
360+
361+
withGitConfigParser(path1,repo=repo)asconfig:
362+
assertnotconfig._has_includes()
363+
assertconfig._included_paths()== []
364+
348365
deftest_rename(self):
349366
file_obj=self._to_memcache(fixture_path('git_config'))
350367
withGitConfigParser(file_obj,read_only=False,merge_includes=False)ascw:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp