本文整理汇总了Python中datalad.support.gitrepo.GitRepo.get_gitattributes方法的典型用法代码示例。如果您正苦于以下问题:Python GitRepo.get_gitattributes方法的具体用法?Python GitRepo.get_gitattributes怎么用?Python GitRepo.get_gitattributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datalad.support.gitrepo.GitRepo
的用法示例。
在下文中一共展示了GitRepo.get_gitattributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_GitRepo_gitignore
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import get_gitattributes [as 别名]
def test_GitRepo_gitignore(path):
gr = GitRepo(path, create=True)
sub = GitRepo(op.join(path, 'ignore-sub.me'))
# we need to commit something, otherwise add_submodule
# will already refuse the submodule for having no commit
sub.add('a_file.txt')
sub.commit()
from ..exceptions import GitIgnoreError
with open(op.join(path, '.gitignore'), "w") as f:
f.write("*.me")
with assert_raises(GitIgnoreError) as cme:
gr.add('ignore.me')
eq_(cme.exception.paths, ['ignore.me'])
with assert_raises(GitIgnoreError) as cme:
gr.add_submodule(path='ignore-sub.me')
eq_(cme.exception.paths, ['ignore-sub.me'])
with assert_raises(GitIgnoreError) as cme:
gr.add(['ignore.me', 'dontigno.re', op.join('ignore-sub.me', 'a_file.txt')])
eq_(set(cme.exception.paths), {'ignore.me', 'ignore-sub.me'})
eq_(gr.get_gitattributes('.')['.'], {}) # nothing is recorded within .gitattributes
示例2: test_gitattributes
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import get_gitattributes [as 别名]
def test_gitattributes(path):
gr = GitRepo(path, create=True)
# starts without any attributes file
ok_(not op.exists(op.join(gr.path, '.gitattributes')))
eq_(gr.get_gitattributes('.')['.'], {})
# bool is a tag or unsets, anything else is key/value
gr.set_gitattributes([('*', {'tag': True}), ('*', {'sec.key': 'val'})])
ok_(op.exists(op.join(gr.path, '.gitattributes')))
eq_(gr.get_gitattributes('.')['.'], {'tag': True, 'sec.key': 'val'})
# unset by amending the record, but does not remove notion of the
# tag entirely
gr.set_gitattributes([('*', {'tag': False})])
eq_(gr.get_gitattributes('.')['.'], {'tag': False, 'sec.key': 'val'})
# attributes file is not added or commited, we can ignore such
# attributes
eq_(gr.get_gitattributes('.', index_only=True)['.'], {})
# we can send absolute path patterns and write to any file, and
# the patterns will be translated relative to the target file
gr.set_gitattributes([
(op.join(gr.path, 'relative', 'ikethemike/**'), {'bang': True})],
attrfile=op.join('relative', '.gitattributes'))
# directory and file get created
ok_(op.exists(op.join(gr.path, 'relative', '.gitattributes')))
eq_(gr.get_gitattributes(
op.join(gr.path, 'relative', 'ikethemike', 'probe')),
# always comes out relative to the repo root, even if abs goes in
{op.join('relative', 'ikethemike', 'probe'):
{'tag': False, 'sec.key': 'val', 'bang': True}})
if get_encoding_info()['default'] != 'ascii':
# do not perform this on obscure systems without anything like UTF
# it is not relevant whether a path actually exists, and paths
# with spaces and other funky stuff are just fine
funky = u'{} {}'.format(
get_most_obscure_supported_name(),
get_most_obscure_supported_name())
gr.set_gitattributes([(funky, {'this': 'that'})])
eq_(gr.get_gitattributes(funky)[funky], {
'this': 'that',
'tag': False,
'sec.key': 'val',
})
# mode='w' should replace the entire file:
gr.set_gitattributes([('**', {'some': 'nonsense'})], mode='w')
eq_(gr.get_gitattributes('.')['.'], {'some': 'nonsense'})