本文整理汇总了Python中git.exc.NoSuchPathError方法的典型用法代码示例。如果您正苦于以下问题:Python exc.NoSuchPathError方法的具体用法?Python exc.NoSuchPathError怎么用?Python exc.NoSuchPathError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.exc
的用法示例。
在下文中一共展示了exc.NoSuchPathError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_explicit_new_repo_template
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import NoSuchPathError [as 别名]
def test_explicit_new_repo_template(base_command, mock_git):
"If a previously unknown URL template is specified it is used"
base_command.git = mock_git
# There won't be a cookiecutter cache, so there won't be
# a repo path (yet).
base_command.git.Repo.side_effect = git_exceptions.NoSuchPathError
cached_path = cookiecutter_cache_path('https://example.com/magic/special-template.git')
# Update the cache
cached_template = base_command.update_cookiecutter_cache(
template='https://example.com/magic/special-template.git',
branch='special',
)
# The template that will be used is the original URL
assert cached_template == 'https://example.com/magic/special-template.git'
# The cookiecutter cache location will be interrogated.
base_command.git.Repo.assert_called_once_with(cached_path)
示例2: test_default_template
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import NoSuchPathError [as 别名]
def test_default_template(create_command, myapp):
"Absent of other information, the default template is used"
# There won't be a cookiecutter cache, so there won't be
# a cache path (yet).
create_command.git.Repo.side_effect = git_exceptions.NoSuchPathError
# Generate the template.
create_command.generate_app_template(myapp)
# App's template has been set
assert myapp.template == 'https://github.com/beeware/briefcase-tester-dummy-template.git'
# Cookiecutter was invoked with the expected template name and context.
create_command.cookiecutter.assert_called_once_with(
'https://github.com/beeware/briefcase-tester-dummy-template.git',
no_input=True,
checkout=create_command.python_version_tag,
output_dir=str(create_command.platform_path),
extra_context=full_context({
'template': 'https://github.com/beeware/briefcase-tester-dummy-template.git',
})
)
示例3: test_platform_exists
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import NoSuchPathError [as 别名]
def test_platform_exists(create_command, myapp):
"If the platform directory already exists, it's ok"
# There won't be a cookiecutter cache, so there won't be
# a cache path (yet).
create_command.git.Repo.side_effect = git_exceptions.NoSuchPathError
# Create the platform directory
create_command.platform_path.mkdir(parents=True)
# Generate the template.
create_command.generate_app_template(myapp)
# App's template has been set
assert myapp.template == 'https://github.com/beeware/briefcase-tester-dummy-template.git'
# Cookiecutter was invoked with the expected template name and context.
create_command.cookiecutter.assert_called_once_with(
'https://github.com/beeware/briefcase-tester-dummy-template.git',
no_input=True,
checkout=create_command.python_version_tag,
output_dir=str(create_command.platform_path),
extra_context=full_context({
'template': 'https://github.com/beeware/briefcase-tester-dummy-template.git',
})
)
示例4: test_explicit_repo_template
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import NoSuchPathError [as 别名]
def test_explicit_repo_template(create_command, myapp):
"If a template is specified in the app config, it is used"
myapp.template = 'https://example.com/magic/special-template.git'
# There won't be a cookiecutter cache, so there won't be
# a repo path (yet).
create_command.git.Repo.side_effect = git_exceptions.NoSuchPathError
# Generate the template.
create_command.generate_app_template(myapp)
# App's template hasn't been changed
assert myapp.template == 'https://example.com/magic/special-template.git'
# Cookiecutter was invoked with the expected template name and context.
create_command.cookiecutter.assert_called_once_with(
'https://example.com/magic/special-template.git',
no_input=True,
checkout=create_command.python_version_tag,
output_dir=str(create_command.platform_path),
extra_context=full_context({
'template': 'https://example.com/magic/special-template.git',
})
)
示例5: _set_alternates
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import NoSuchPathError [as 别名]
def _set_alternates(self, alts):
"""Sets the alternates
:param alts:
is the array of string paths representing the alternates at which
git should look for objects, i.e. /home/user/repo/.git/objects
:raise NoSuchPathError:
:note:
The method does not check for the existence of the paths in alts
as the caller is responsible."""
alternates_path = osp.join(self.common_dir, 'objects', 'info', 'alternates')
if not alts:
if osp.isfile(alternates_path):
os.remove(alternates_path)
else:
with open(alternates_path, 'wb') as f:
f.write("\n".join(alts).encode(defenc))
示例6: test_offline_repo_template
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import NoSuchPathError [as 别名]
def test_offline_repo_template(create_command, myapp):
"If the user is offline the first time a repo template is requested, an error is raised"
# There won't be a cookiecutter cache, so there won't be
# a repo path (yet).
create_command.git.Repo.side_effect = git_exceptions.NoSuchPathError
# Calling cookiecutter on a repository while offline causes a CalledProcessError
create_command.cookiecutter.side_effect = subprocess.CalledProcessError(
cmd=['git', 'clone', 'https://github.com/beeware/briefcase-tester-dummy-template.git'],
returncode=128
)
# Generating the template under these conditions raises an error
with pytest.raises(NetworkFailure):
create_command.generate_app_template(myapp)
# App's template has been set
assert myapp.template == 'https://github.com/beeware/briefcase-tester-dummy-template.git'
# Cookiecutter was invoked with the expected template name and context.
create_command.cookiecutter.assert_called_once_with(
'https://github.com/beeware/briefcase-tester-dummy-template.git',
no_input=True,
checkout=create_command.python_version_tag,
output_dir=str(create_command.platform_path),
extra_context=full_context({
'template': 'https://github.com/beeware/briefcase-tester-dummy-template.git',
})
)
示例7: test_missing_branch_template
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import NoSuchPathError [as 别名]
def test_missing_branch_template(create_command, myapp):
"If the repo at the provided template URL doesn't have a branch for this Python version, an error is raised"
myapp.template = 'https://example.com/somewhere/missing-branch.git'
# There won't be a cookiecutter cache, so there won't be
# a repo path (yet).
create_command.git.Repo.side_effect = git_exceptions.NoSuchPathError
# Calling cookiecutter on a URL that doesn't have the requested branch
# causes an error
create_command.cookiecutter.side_effect = cookiecutter_exceptions.RepositoryCloneFailed
# Generating the template under there conditions raises an error
with pytest.raises(TemplateUnsupportedVersion):
create_command.generate_app_template(myapp)
# App's template is unchanged
assert myapp.template == 'https://example.com/somewhere/missing-branch.git'
# Cookiecutter was invoked with the expected template name and context.
create_command.cookiecutter.assert_called_once_with(
'https://example.com/somewhere/missing-branch.git',
no_input=True,
checkout=create_command.python_version_tag,
output_dir=str(create_command.platform_path),
extra_context=full_context({
'template': 'https://example.com/somewhere/missing-branch.git',
})
)
示例8: get_diff
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import NoSuchPathError [as 别名]
def get_diff(repository, sha_commit, filepath):
repo_path = repository.get_local_repo_path()
Frontend.set_auth(repository)
repo = None
commit = None
parent = None
diff = None
try:
repo = Repo(repo_path)
except NoSuchPathError:
repository.conn_ok = False
repository.save()
return ""
try:
commit = repo.commit(sha_commit)
except BadName:
return ""
if not commit.parents:
# first commit, use EMPTY_TREE_SHA
parent = EMPTY_TREE_SHA
# TODO BUG this is broken!!
return ""
else:
# use first parent
parent = commit.parents[0]
# find diff object matching filepath
try:
diff = next(d for d in parent.diff(commit, create_patch=True) if d.b_path == filepath)
except StopIteration:
# element not found
return ""
return diff.diff.decode()
示例9: diff_branches
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import NoSuchPathError [as 别名]
def diff_branches(repo, target, source):
""" Returns a list of files that have changed in a given repo
between two branches. """
try:
import git # pylint: disable=unused-import,unused-variable
import git.exc as git_exc
import gitdb
except ImportError as ex:
raise CLIError(ex)
from git import Repo
try:
git_repo = Repo(repo)
except (git_exc.NoSuchPathError, git_exc.InvalidGitRepositoryError):
raise CLIError('invalid git repo: {}'.format(repo))
def get_commit(branch):
try:
return git_repo.commit(branch)
except gitdb.exc.BadName:
raise CLIError('usage error, invalid branch: {}'.format(branch))
if source:
source_commit = get_commit(source)
else:
source_commit = git_repo.head.commit
target_commit = get_commit(target)
logger.info('Filtering down to modules which have changed based on:')
logger.info('cd %s', repo)
logger.info('git --no-pager diff %s..%s --name-only -- .\n', target_commit, source_commit)
diff_index = target_commit.diff(source_commit)
return [diff.b_path for diff in diff_index]
示例10: _repository
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import NoSuchPathError [as 别名]
def _repository(self):
if self.__repository is None:
try:
self.__repository = git.Repo(self.url)
except (InvalidGitRepositoryError, NoSuchPathError) as err:
raise VersionControlError("Cannot access Git repository at %s: %s" % (self.url, err))
return self.__repository