本文整理汇总了Python中git.NoSuchPathError方法的典型用法代码示例。如果您正苦于以下问题:Python git.NoSuchPathError方法的具体用法?Python git.NoSuchPathError怎么用?Python git.NoSuchPathError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git
的用法示例。
在下文中一共展示了git.NoSuchPathError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_git_commit
# 需要导入模块: import git [as 别名]
# 或者: from git import NoSuchPathError [as 别名]
def _get_git_commit(path):
try:
import git
except ImportError as e:
_logger.warning(
"Failed to import Git (the Git executable is probably not on your PATH),"
" so Git SHA is not available. Error: %s", e)
return None
try:
if os.path.isfile(path):
path = os.path.dirname(path)
repo = git.Repo(path, search_parent_directories=True)
commit = repo.head.commit.hexsha
return commit
except (git.InvalidGitRepositoryError, git.GitCommandNotFound, ValueError, git.NoSuchPathError):
return None
示例2: git_version
# 需要导入模块: import git [as 别名]
# 或者: from git import NoSuchPathError [as 别名]
def git_version(version_: str) -> str:
"""
Return a version to identify the state of the underlying git repo. The version will
indicate whether the head of the current git-backed working directory is tied to a
release tag or not : it will indicate the former with a 'release:{version}' prefix
and the latter with a 'dev0' prefix. Following the prefix will be a sha of the current
branch head. Finally, a "dirty" suffix is appended to indicate that uncommitted
changes are present.
:param str version_: Semver version
:return: Found Airflow version in Git repo
:rtype: str
"""
try:
import git
try:
repo = git.Repo(os.path.join(*[my_dir, '.git']))
except git.NoSuchPathError:
logger.warning('.git directory not found: Cannot compute the git version')
return ''
except git.InvalidGitRepositoryError:
logger.warning('Invalid .git directory not found: Cannot compute the git version')
return ''
except ImportError:
logger.warning('gitpython not found: Cannot compute the git version.')
return ''
if repo:
sha = repo.head.commit.hexsha
if repo.is_dirty():
return '.dev0+{sha}.dirty'.format(sha=sha)
# commit is clean
return '.release:{version}+{sha}'.format(version=version_, sha=sha)
else:
return 'no_git_version'
示例3: setup_repo
# 需要导入模块: import git [as 别名]
# 或者: from git import NoSuchPathError [as 别名]
def setup_repo(repo_path, upstream_repo):
"""
Ensure that the repo is present or clone it from upstream otherwise.
"""
repo_path = os.path.expanduser(repo_path)
try:
git.Repo(repo_path, search_parent_directories=True)
except git.NoSuchPathError:
logger.warning(
"Repo '%s' not found. Cloning from upstream '%s'", repo_path, upstream_repo
)
git.Repo.clone_from(upstream_repo, repo_path)
示例4: _get_git_url_if_present
# 需要导入模块: import git [as 别名]
# 或者: from git import NoSuchPathError [as 别名]
def _get_git_url_if_present(uri):
"""
Return the path git_uri#sub_directory if the URI passed is a local path that's part of
a Git repo, or returns the original URI otherwise.
:param uri: The expanded uri
:return: The git_uri#sub_directory if the uri is part of a Git repo,
otherwise return the original uri
"""
if '#' in uri:
# Already a URI in git repo format
return uri
try:
from git import Repo, InvalidGitRepositoryError, GitCommandNotFound, NoSuchPathError
except ImportError as e:
print("Notice: failed to import Git (the git executable is probably not on your PATH),"
" so Git SHA is not available. Error: %s" % e, file=sys.stderr)
return uri
try:
# Check whether this is part of a git repo
repo = Repo(uri, search_parent_directories=True)
# Repo url
repo_url = "file://%s" % repo.working_tree_dir
# Sub directory
rlpath = uri.replace(repo.working_tree_dir, '')
if (rlpath == ''):
git_path = repo_url
elif (rlpath[0] == '/'):
git_path = repo_url + '#' + rlpath[1:]
else:
git_path = repo_url + '#' + rlpath
return git_path
except (InvalidGitRepositoryError, GitCommandNotFound, ValueError, NoSuchPathError):
return uri
示例5: _get_or_create_repo
# 需要导入模块: import git [as 别名]
# 或者: from git import NoSuchPathError [as 别名]
def _get_or_create_repo(self, env: ENV_VARS_TYPE) -> git.Repo:
try:
repo = self.get_repo()
branch = self.target_branch
with raise_context():
repo.git.checkout(branch)
is_not_detached = not repo.head.is_detached
if branch and is_not_detached and repo.active_branch.name != branch:
self.delete()
raise git.NoSuchPathError
except git.NoSuchPathError:
repo = self.make_clone(env)[0]
return repo
示例6: check_preconditions
# 需要导入模块: import git [as 别名]
# 或者: from git import NoSuchPathError [as 别名]
def check_preconditions(self):
from . import settings # avoiding circular imports
try:
self.repo = git.Repo(environ["CI_PROJECT_DIR"])
except git.NoSuchPathError:
click.secho(
f"You are not running crane in a Git repository. "
"crane is running in limited mode, all hooks have been disabled. "
"It is highly recommended you use Git references for your deployments.",
err=True,
fg="red",
)
self.is_limited = True
return
try:
self.new_commit
except (gitdb.exc.BadName, ValueError):
click.secho(
f"The new version you specified, {self.new_version}, is not a valid git reference! "
"crane is running in limited mode, all hooks have been disabled. "
"It is highly recommended you use Git references for your deployments.",
err=True,
fg="red",
)
self.is_limited = True
return
for service in self.services:
if (
self.old_version not in service.json()["launchConfig"]["imageUuid"]
and not settings["new_image"]
):
click.secho(
"All selected services must have the same commit SHA. "
"Please manually change their versions so they are all the same, and then retry the upgrade.",
err=True,
fg="red",
)
raise UpgradeFailed()