当前位置: 首页>>代码示例>>Python>>正文


Python exc.InvalidGitRepositoryError方法代码示例

本文整理汇总了Python中git.exc.InvalidGitRepositoryError方法的典型用法代码示例。如果您正苦于以下问题:Python exc.InvalidGitRepositoryError方法的具体用法?Python exc.InvalidGitRepositoryError怎么用?Python exc.InvalidGitRepositoryError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git.exc的用法示例。


在下文中一共展示了exc.InvalidGitRepositoryError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_package

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [as 别名]
def update_package(path: str):
    """Update a single service withgit pull"""
    try:
        repo = Repo(path)
        if repo.remotes.origin.url.endswith('.git'):
            repo.remotes.origin.pull()
    except exc.InvalidGitRepositoryError:
        pass 
开发者ID:stakkr-org,项目名称:stakkr,代码行数:10,代码来源:services.py

示例2: get_repository

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [as 别名]
def get_repository(file_path):
    """
    Get repository object for repository within which given file
    is located.

    :param file_path: File path
    :type file_path: str or unicode
    :return: repository or None if no repository can be found
    :rtype: git.Repo
    :raises git.exc.NoSuchPathError: if the path does not exist
    """
    path = os.path.realpath(file_path)
    repository = None
    try:
        repository = Repo(path, search_parent_directories=True)
    except InvalidGitRepositoryError:
        pass
    return repository 
开发者ID:recipy,项目名称:recipy,代码行数:20,代码来源:version_control.py

示例3: source_cleanup

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [as 别名]
def source_cleanup(git_path):
    '''Clean up the git repository that was created by ``git_clone`` above.

    Removes the ``git_path`` repository and all associated files if they
    exist.

    :param str git_path: The git repository to delete.
    '''
    if os.path.exists(git_path):
        try:
            # Internally validates whether the path points to an actual repo.
            Repo(git_path)
        except git_exc.InvalidGitRepositoryError as e:
            LOG.warning('%s is not a valid git repository. Details: %s',
                        git_path, e)
        else:
            try:
                shutil.rmtree(git_path)
            except OSError as e:
                LOG.warning('Could not delete the path %s. Details: %s',
                            git_path, e)
    else:
        LOG.warning('Could not delete the path %s. Is it a git repository?',
                    git_path) 
开发者ID:att-comdev,项目名称:armada,代码行数:26,代码来源:source.py

示例4: get_repo

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [as 别名]
def get_repo():
    """Helper to get the repo, making it if not found"""
    try:
        repo = Repo(os.path.dirname(utils.get_base_dir()))
    except InvalidGitRepositoryError:
        repo = Repo.init(os.path.dirname(utils.get_base_dir()))
        origin = repo.create_remote("origin", "https://gitlab.com/friendly-telegram/friendly-telegram")
        origin.fetch()
        repo.create_head("master", origin.refs.master)
        repo.heads.master.set_tracking_branch(origin.refs.master)
        repo.heads.master.checkout(True)
    return repo 
开发者ID:friendly-telegram,项目名称:friendly-telegram,代码行数:14,代码来源:heroku.py

示例5: pytest_sessionstart

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [as 别名]
def pytest_sessionstart(session):
    global _TEST_SERVICE
    trace_context_path = join(dirname(abspath(__file__)), "trace-context")

    try:
        mkdir(trace_context_path)

    except FileExistsError:
        pass

    try:
        trace_context_repo = Repo(trace_context_path)

    except InvalidGitRepositoryError:
        trace_context_repo = Repo.clone_from(
            "git@github.com:w3c/trace-context.git",
            trace_context_path
        )

    trace_context_repo.heads.master.checkout()
    trace_context_repo.head.reset(
        "98f210efd89c63593dce90e2bae0a1bdcb986f51"
    )

    environ["SERVICE_ENDPOINT"] = "http://127.0.0.1:5000/test"

    _TEST_SERVICE = Popen(
        split(
            "python3 {}".format(
                join(
                    dirname(abspath(__file__)),
                    "trace_context_test_service.py"
                )
            )
        )
    )
    # This seems to be necessary, if not the first few test cases will fail
    # since they won't find the test service running.
    sleep(1) 
开发者ID:lightstep,项目名称:lightstep-tracer-python,代码行数:41,代码来源:conftest.py

示例6: get_submodules

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [as 别名]
def get_submodules(root: str) -> set:
    """Return recursively all submodule of a dataset.
    
    Parameters
    ----------
    root : str
        Absolute path of the submodule root.
    
    Returns
    -------
    set
        All submodules path of a dataset.
    """
    try:
        submodules: Union[Set[str], None] = {
            submodule.path for submodule in git.Repo(root).submodules
        }
    except InvalidGitRepositoryError as e:
        submodules = None

    if submodules:
        rv = reduce(
            lambda x, y: x.union(y),
            map(
                lambda submodule: get_submodules(os.path.join(root, submodule)),
                submodules,
            ),
        )
        return rv | submodules
    else:
        return set() 
开发者ID:CONP-PCNO,项目名称:conp-dataset,代码行数:33,代码来源:functions.py

示例7: check_repo_ok

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [as 别名]
def check_repo_ok(self):
        """
        Make sure that the ns-3 repository's HEAD commit is the same as the one
        saved in the campaign database, and that the ns-3 repository is clean
        (i.e., no untracked or modified files exist).
        """
        from git import Repo, exc
        # Check that git is at the expected commit and that the repo is not
        # dirty
        if self.runner is not None:
            path = self.runner.path
            try:
                repo = Repo(path)
            except(exc.InvalidGitRepositoryError):
                raise Exception("No git repository detected.\nIn order to "
                                "use SEM and its reproducibility enforcing "
                                "features, please create a git repository at "
                                "the root of your ns-3 project.")
            current_commit = repo.head.commit.hexsha
            campaign_commit = self.db.get_commit()

            if repo.is_dirty(untracked_files=True):
                raise Exception("ns-3 repository is not clean")

            if current_commit != campaign_commit:
                raise Exception("ns-3 repository is on a different commit "
                                "from the one specified in the campaign") 
开发者ID:signetlabdei,项目名称:sem,代码行数:29,代码来源:manager.py

示例8: load_rev_number

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [as 别名]
def load_rev_number():
    # This function uses a lot of language "power features" that could be considered bad form:
    # 1) does a conditional import to get version
    # 2) uses __file__ to try and extract and git repo version during execution
    # We will let this fly anyway because:
    # 1) The results of this are only used for logging anyway
    # 2) This is a command parsing module of the code and inherently very non-pure and doing IO etc
    # 3) Unclear if there is a cleaner way to do this

    # Get rev from version file (if running inside the pip-installable wheel without the git repo)
    try:
        from bayesmark import version

        rev_file = version.VERSION
    except ImportError:
        rev_file = None
    else:
        rev_file = rev_file.strip()
        rev = rev_file

    # Get rev from git API if inside git repo (and not built wheel from pip install ...)
    wdir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
    try:
        repo = git.Repo(path=wdir, search_parent_directories=False)
    except InvalidGitRepositoryError:
        rev_repo = None
    else:
        rev_repo = repo.head.commit.hexsha
        rev_repo = rev_repo.strip()
        rev = rev_repo

    # Check coherence of what we found
    if (rev_repo is None) and (rev_file is None):
        raise RuntimeError("Must specify version.py if not inside a git repo.")
    if (rev_repo is not None) and (rev_file is not None):
        assert rev_repo == rev_file, "Rev file %s does not match rev git %s" % (rev_file, rev_repo)

    assert rev == rev.strip()
    # We could first enforce is_lower_hex if we want to enforce that
    rev = rev[:7]
    return rev 
开发者ID:uber,项目名称:bayesmark,代码行数:43,代码来源:cmd_parse.py

示例9: record_commit

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [as 别名]
def record_commit(self, src_dir):
        try:
            repo = Repo(src_dir)

            if 'dirty_repo' in self.metadata or 'commit' in self.metadata:
                raise RuntimeError('A commit has already been recorded.')

            self.metadata['dirty_repo'] = repo.is_dirty()
            self.metadata['commit'] = repo.head.object.hexsha.encode('utf-8')
        except git_exc.InvalidGitRepositoryError as e:
            # Maybe not a git repo e.g., running on CodaLab
            self.metadata['dirty_repo'] = False
            self.metadata['commit'] = 'NONE' 
开发者ID:kelvinguu,项目名称:lang2program,代码行数:15,代码来源:experiment.py

示例10: diff_branches

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [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] 
开发者ID:Azure,项目名称:azure-cli-dev-tools,代码行数:37,代码来源:git_util.py

示例11: _get_git_repo_url

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [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

示例12: find_first_remote_branch

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [as 别名]
def find_first_remote_branch(remotes, branch_name):
    """Find the remote branch matching the name of the given branch or raise InvalidGitRepositoryError"""
    for remote in remotes:
        try:
            return remote.refs[branch_name]
        except IndexError:
            continue
        # END exception handling
    # END for remote
    raise InvalidGitRepositoryError("Didn't find remote branch '%r' in any of the given remotes" % branch_name)

#} END utilities


#{ Classes 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:17,代码来源:util.py

示例13: findrepo

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [as 别名]
def findrepo(path):
    check_version()
    try:
        repo = git.Repo(path, search_parent_directories=True)
    except InvalidGitRepositoryError:
        return
    else:
        return os.path.dirname(repo.git_dir) 
开发者ID:open-research,项目名称:sumatra,代码行数:10,代码来源:_git.py

示例14: _repository

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [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 
开发者ID:open-research,项目名称:sumatra,代码行数:9,代码来源:_git.py

示例15: run

# 需要导入模块: from git import exc [as 别名]
# 或者: from git.exc import InvalidGitRepositoryError [as 别名]
def run(self, pack):
        """
        :param pack: Installed Pack Name to get info about
        :type pack: ``str``
        """
        packs_base_paths = get_packs_base_paths()

        pack_path = None
        metadata_file = None
        for packs_base_path in packs_base_paths:
            pack_path = os.path.join(packs_base_path, pack)
            pack_yaml_path = os.path.join(pack_path, MANIFEST_FILE_NAME)

            if os.path.isfile(pack_yaml_path):
                metadata_file = pack_yaml_path
                break

        # Pack doesn't exist, finish execution normally with empty metadata
        if not os.path.isdir(pack_path):
            return {
                'pack': None,
                'git_status': None
            }

        if not metadata_file:
            error = ('Pack "%s" doesn\'t contain pack.yaml file.' % (pack))
            raise Exception(error)

        try:
            details = self._parse_yaml_file(metadata_file)
        except Exception as e:
            error = ('Pack "%s" doesn\'t contain a valid pack.yaml file: %s' % (pack,
                                                                                six.text_type(e)))
            raise Exception(error)

        try:
            repo = Repo(pack_path)
            git_status = "Status:\n%s\n\nRemotes:\n%s" % (
                repo.git.status().split('\n')[0],
                "\n".join([remote.url for remote in repo.remotes])
            )

            ahead_behind = repo.git.rev_list(
                '--left-right', '--count', 'HEAD...origin/master'
            ).split()
            # Dear god.
            if ahead_behind != [u'0', u'0']:
                git_status += "\n\n"
                git_status += "%s commits ahead " if ahead_behind[0] != u'0' else ""
                git_status += "and " if u'0' not in ahead_behind else ""
                git_status += "%s commits behind " if ahead_behind[1] != u'0' else ""
                git_status += "origin/master."
        except InvalidGitRepositoryError:
            git_status = None

        return {
            'pack': details,
            'git_status': git_status
        } 
开发者ID:StackStorm,项目名称:st2,代码行数:61,代码来源:get_installed.py


注:本文中的git.exc.InvalidGitRepositoryError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。