當前位置: 首頁>>代碼示例>>Python>>正文


Python exc.GitCommandError方法代碼示例

本文整理匯總了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 
開發者ID:SwissDataScienceCenter,項目名稱:renku-python,代碼行數:18,代碼來源:git.py

示例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"))) 
開發者ID:SpisTresci,項目名稱:scrooge,代碼行數:26,代碼來源:datastoragemanager.py

示例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 
開發者ID:SpisTresci,項目名稱:scrooge,代碼行數:27,代碼來源:datastoragemanager.py

示例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) 
開發者ID:mlflow,項目名稱:mlflow,代碼行數:26,代碼來源:utils.py

示例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 
開發者ID:beeware,項目名稱:briefcase,代碼行數:41,代碼來源:test_update_cookiecutter_cache.py

示例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',
        })
    ) 
開發者ID:beeware,項目名稱:briefcase,代碼行數:43,代碼來源:test_generate_app_template.py

示例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) 
開發者ID:stakkr-org,項目名稱:stakkr,代碼行數:29,代碼來源:services.py

示例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') 
開發者ID:vecto-ai,項目名稱:vecto,代碼行數:7,代碼來源:fetch_benchmarks.py

示例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 
開發者ID:SwissDataScienceCenter,項目名稱:renku-python,代碼行數:10,代碼來源:git.py

示例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!") 
開發者ID:gigantum,項目名稱:gigantum-client,代碼行數:11,代碼來源:git_interface_mixin.py

示例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) 
開發者ID:goern,項目名稱:mattermost-openshift,代碼行數:43,代碼來源:pr_from_new_release.py

示例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)) 
開發者ID:ros-infrastructure,項目名稱:superflore,代碼行數:12,代碼來源:repo_instance.py

示例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() 
開發者ID:indietyp,項目名稱:hawthorne,代碼行數:13,代碼來源:helper.py

示例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 
開發者ID:kiibohd,項目名稱:kll,代碼行數:38,代碼來源:klltest.py

示例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] 
開發者ID:mlflow,項目名稱:mlflow,代碼行數:15,代碼來源:utils.py


注:本文中的git.exc.GitCommandError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。