本文整理汇总了Python中git.exc.GitCommandError方法的典型用法代码示例。如果您正苦于以下问题:Python exc.GitCommandError方法的具体用法?Python exc.GitCommandError怎么用?Python exc.GitCommandError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.exc
的用法示例。
在下文中一共展示了exc.GitCommandError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_attr
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def find_attr(self, *paths):
"""Return map with path and its attributes."""
from git.exc import GitCommandError
attrs = defaultdict(dict)
try:
data = self.repo.git.check_attr('-z', '-a', '--', *paths)
for file, name, value in zip_longest(
*[iter(data.strip('\0').split('\0'))] * 3
):
if file:
attrs[file][name] = value
except GitCommandError:
pass
return attrs
示例2: save
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def save(self, filename):
self.__asert_is_clean()
file_path = os.path.join(self.store_storage_dir, filename)
file = open(file_path, 'wb')
yield file
file.close()
date = datetime.now()
try:
commits_counter = len(self.repo.git.log())
except GitCommandError:
commits_counter = 0
if self.repo.is_dirty() or commits_counter == 0:
self.repo.index.add([file_path])
commit_datetime_str = date.strftime("%Y-%m-%d %H:%M:%S")
commit_msg = "Store: {}\nDate: {}".format(self.store_name, commit_datetime_str)
self.repo.index.commit(commit_msg)
self.__increment_revision()
self.repo.create_tag("date-{}".format(date.strftime("%Y-%m-%d_%H-%M-%S-%f")))
示例3: get
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def get(self, filename, revision=None):
"""
Returns content of files saved in DataStorageManager
:param filename: name of file, which content should be returned
:param revision: if not provided, last revision will be used, otherwise specified revision
:return: content of the specified filename
"""
self.__asert_is_clean()
try:
revision = revision if revision is not None else self.last_revision_number()
self.repo.git.checkout(self.__revision_tag_name.format(revision))
except (GitCommandError, DataStorageManager.NoRevision):
raise DataStorageManager.NoRevision()
file_path = os.path.join(self.store_storage_dir, filename)
if not os.path.exists(file_path):
raise DataStorageManager.NoFile()
with open(file_path) as f:
content = f.read()
self.repo.git.checkout('master')
return content
示例4: _fetch_git_repo
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def _fetch_git_repo(uri, version, dst_dir):
"""
Clone the git repo at ``uri`` into ``dst_dir``, checking out commit ``version`` (or defaulting
to the head commit of the repository's master branch if version is unspecified).
Assumes authentication parameters are specified by the environment, e.g. by a Git credential
helper.
"""
# We defer importing git until the last moment, because the import requires that the git
# executable is availble on the PATH, so we only want to fail if we actually need it.
import git
repo = git.Repo.init(dst_dir)
origin = repo.create_remote("origin", uri)
origin.fetch()
if version is not None:
try:
repo.git.checkout(version)
except git.exc.GitCommandError as e:
raise ExecutionException("Unable to checkout version '%s' of git repo %s"
"- please ensure that the version exists in the repo. "
"Error: %s" % (version, uri, e))
else:
repo.create_head("master", origin.refs.master)
repo.heads.master.checkout()
repo.submodule_update(init=True, recursive=True)
示例5: test_offline_repo_template
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def test_offline_repo_template(base_command, mock_git):
"If the user is offline the first time a repo template is requested, an error is raised"
base_command.git = mock_git
mock_repo = mock.MagicMock()
mock_remote = mock.MagicMock()
mock_remote_head = mock.MagicMock()
# Git returns a Repo, that repo can return a remote, and it has
# heads that can be accessed. However, calling fetch on the remote
# will cause a git error (error code 128).
base_command.git.Repo.return_value = mock_repo
mock_repo.remote.return_value = mock_remote
mock_remote.refs.__getitem__.return_value = mock_remote_head
mock_remote.fetch.side_effect = git_exceptions.GitCommandError('git', 128)
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 cookiecutter cache location will be interrogated.
base_command.git.Repo.assert_called_once_with(cached_path)
# The origin of the repo was fetched
mock_repo.remote.assert_called_once_with(name='origin')
mock_remote.fetch.assert_called_once_with()
# The right branch was accessed
mock_remote.refs.__getitem__.assert_called_once_with('special')
# The remote head was checked out.
mock_remote_head.checkout.assert_called_once_with()
# The template that will be used is the original URL
assert cached_template == cached_path
示例6: test_cached_template_offline
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def test_cached_template_offline(create_command, myapp, capsys):
"If the user is offline, a cached template won't be updated, but will still work"
mock_repo = mock.MagicMock()
mock_remote = mock.MagicMock()
mock_remote_head = mock.MagicMock()
# Git returns a Repo, that repo can return a remote, and it has
# heads that can be accessed. However, calling fetch on the remote
# will cause a git error (error code 128).
create_command.git.Repo.return_value = mock_repo
mock_repo.remote.return_value = mock_remote
mock_remote.refs.__getitem__.return_value = mock_remote_head
mock_remote.fetch.side_effect = git_exceptions.GitCommandError('git', 128)
# Generate the template.
create_command.generate_app_template(myapp)
# An attempt to fetch the repo origin was made
mock_repo.remote.assert_called_once_with(name='origin')
mock_remote.fetch.assert_called_once_with()
# A warning was raised to the user about the fetch problem
output = capsys.readouterr().out
assert "WARNING: Unable to update template (is your computer offline?)" in output
# The remote head was checked out.
mock_remote_head.checkout.assert_called_once_with()
# App's config template hasn't changed
assert myapp.template == 'https://github.com/beeware/briefcase-tester-dummy-template.git'
# Cookiecutter was invoked with the path to the *cached* template name
create_command.cookiecutter.assert_called_once_with(
str(Path.home() / '.cookiecutters' / 'briefcase-tester-dummy-template'),
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: install
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def install(services_dir: str, package: str, name: str):
"""Install a specific service by cloning a repo"""
from os.path import isdir
from urllib.parse import urlparse
url = '{}/services-{}.git'.format(__github_url__, package)
if urlparse(package).scheme != '':
url = package
path = '{}/{}'.format(services_dir, name)
try:
_check_repo_exists(url)
if isdir(path):
msg = 'Package "{}" is already installed, updating'.format(package)
update_package(path)
return True, msg
Repo.clone_from(url, path)
return True, None
except HTTPError as error:
return False, "Can't add package: {}".format(str(error))
except ImportError:
return False, 'Make sure git is installed'
except exc.GitCommandError as error:
return False, "Couldn't clone {} ({})".format(url, error)
示例8: fetch_benchmarks
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def fetch_benchmarks(path_to_local_dir=path.join('data', 'benchmarks')):
try:
Repo.clone_from('https://github.com/vecto-ai/benchmarks.git', path_to_local_dir)
except GitCommandError:
raise ValueError('Directory exists')
示例9: find_ignored_paths
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def find_ignored_paths(self, *paths):
"""Return ignored paths matching ``.gitignore`` file."""
from git.exc import GitCommandError
try:
return self.repo.git.check_ignore(*paths).split()
except GitCommandError:
pass
示例10: test_existing_tag_fail
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def test_existing_tag_fail(self, mock_initialized):
"""Method to test creating an existing tag, should fail"""
git = mock_initialized[0]
git.create_tag("test_tag_1", "test tag 1")
# Should fail on an existing tag
with pytest.raises(GitCommandError):
git.create_tag("test_tag_1", "test tag 1 should fail!")
示例11: main
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def main():
"""lets start our task"""
# clone the repo
cleanup(LOCAL_WORK_COPY)
try:
r = Repo.clone_from(git_url, LOCAL_WORK_COPY)
except GitCommandError as git_error:
print(git_error)
exit(-1)
d = feedparser.parse(
'https://github.com/mattermost/mattermost-server/releases.atom')
release_version = d.entries[0].title[1:]
# lets read the dockerfile of the current master
dfp = DockerfileParser()
with open('./mattermost-openshift-workdir/Dockerfile') as f:
dfp.content = f.read()
if 'MATTERMOST_VERSION' in dfp.envs:
dockerfile_version = dfp.envs['MATTERMOST_VERSION']
# Lets check if we got a new release
if semver.compare(release_version, dockerfile_version) == 1:
print("Updating from %s to %s" % (dockerfile_version, release_version))
target_branch = 'bots-life/update-to-' + release_version
if not pr_in_progress(target_branch):
patch_and_push(dfp, r, target_branch, release_version)
cleanup(LOCAL_WORK_COPY)
create_pr_to_master(target_branch)
else:
print("There is an open PR for %s, aborting..." %
(target_branch))
else:
print("we are even with Mattermost %s, no need to update" %
release_version)
示例12: remove_file
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def remove_file(self, filename, ignore_fail=False):
try:
self.git.rm('-f', filename)
except GitGotGot as g:
if ignore_fail:
return
fail_msg = 'Failed to remove file {0}'.format(filename)
fail_msg += ' from source control.'
err(fail_msg)
err(' Exception: {0}'.format(g))
示例13: verify
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def verify():
try:
repo.git.diff_index('HEAD', '--', quiet=True)
click.echo('You are compatible with the upstream.')
except GitCommandError:
click.echo('You are {} compatible with the upstream.'.format(click.style('not',
bold=True)))
stash = click.confirm('Do you want to stash your local changes?')
if stash:
repo.git.stash()
示例14: kiibohd_controller_repo
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def kiibohd_controller_repo():
'''
Downloads a cached copy of the kiibohd controller repo
'''
tmp_dir = os.path.join(tempfile.gettempdir(), 'kll_controller_test')
kll_dir = os.path.join(tmp_dir, 'kll')
try:
if not os.path.isdir(tmp_dir):
# Clone if not available
Repo.clone_from('https://github.com/kiibohd/controller.git', tmp_dir)
else:
# Update otherwise
repo = Repo(tmp_dir)
repo.remotes.origin.fetch('+refs/heads/*:refs/remotes/origin/*')
repo.remotes.origin.pull()
except exc.GitCommandError:
# TODO Timeout loop, wait for repo to initialize
repo = Repo(tmp_dir)
pass
try:
# Check for kll compiler as well (not used during testing, but required for controller tests)
if not os.path.isdir(kll_dir):
# Clone if not available
Repo.clone_from('https://github.com/kiibohd/kll.git', kll_dir)
else:
# Update otherwise
repo_kll = Repo(kll_dir)
repo_kll.remotes.origin.pull()
except exc.GitCommandError:
# TODO Timeout loop, wait for repo to initialize
repo = Repo(tmp_dir)
pass
return tmp_dir
示例15: _get_git_repo_url
# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import GitCommandError [as 别名]
def _get_git_repo_url(work_dir):
from git import Repo
from git.exc import GitCommandError, InvalidGitRepositoryError
try:
repo = Repo(work_dir, search_parent_directories=True)
remote_urls = [remote.url for remote in repo.remotes]
if len(remote_urls) == 0:
return None
except GitCommandError:
return None
except InvalidGitRepositoryError:
return None
return remote_urls[0]