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


Python git.InvalidGitRepositoryError方法代码示例

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


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

示例1: add_git_info

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def add_git_info(run, scriptpath):
    """Add information about the git repository holding the source file to the database"""
    try:
        repo = Repo(scriptpath, search_parent_directories=True)
        run["gitrepo"] = repo.working_dir
        run["gitcommit"] = repo.head.commit.hexsha
        run["gitorigin"] = get_origin(repo)

        if not option_set('ignored metadata', 'diff'):
            whole_diff = ''
            diffs = repo.index.diff(None, create_patch=True)
            for diff in diffs:
                whole_diff += "\n\n\n" + "--- {}\n+++ {}\n".format(
                    diff.a_path, diff.b_path) + diff.diff.decode("utf-8")

            run['diff'] = whole_diff
    except (InvalidGitRepositoryError, ValueError):
        # We can't store git info for some reason, so just skip it
        pass


# The released version of PySvn doesn't do local diffs yet, so we have to do
# it the hard way... 
开发者ID:recipy,项目名称:recipy,代码行数:25,代码来源:version_control.py

示例2: get_repository_status

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def get_repository_status():
        """
        Finds the hashes for every `pyiron` module available.

        Returns:
            pandas.DataFrame: The name of each module and the hash for its current git head.
        """
        module_names = [name for _, name, _ in pkgutil.iter_modules() if name.startswith("pyiron")]

        report = pandas.DataFrame(columns=['Module', 'Git head'], index=range(len(module_names)))
        for i, name in enumerate(module_names):
            try:
                module = importlib.import_module(name)
                repo = Repo(os.path.dirname(os.path.dirname(module.__file__)))
                hash_ = repo.head.reference.commit.hexsha
                report.loc[i] = [name, hash_]
            except InvalidGitRepositoryError:
                report.loc[i] = [name, 'Not a repo']

        return report 
开发者ID:pyiron,项目名称:pyiron,代码行数:22,代码来源:generic.py

示例3: print_git_info

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def print_git_info(dirname):
    if not have_gitpython:
        return
    try:
        repo = Repo(dirname, search_parent_directories=True)
    except InvalidGitRepositoryError:
        print("Couldn't find git info")
        return
    cur_commit = repo.commit()
    cur_branch = repo.active_branch
    print("Git info:")
    print("\tCurrent commit %s from branch %s" % (cur_commit.hexsha, cur_branch.name))
    try:
        # EDG: Git is insane, but this should work 99% of the time
        cur_tb = cur_branch.tracking_branch()
        if cur_tb.is_remote():
            remote_name = cur_tb.remote_name
            remote_url = repo.remotes[remote_name].url
            print("\tChecked out from remote %s: %s" % (remote_name, remote_url))
        else:
            print("Tracking local branch %s" % cur_tb.name)
    except:
        print("Could not resolve tracking branch or remote info!") 
开发者ID:angr,项目名称:angr,代码行数:25,代码来源:bug_report.py

示例4: get_git_version

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def get_git_version():
    '''
    return the current git version
    '''
    
    import git
    wd = os.getcwd()

    while wd != "/":
        try:
            repo = git.Repo(wd)
            commit = repo.commit()
            return get_commit_version(commit)

        except git.InvalidGitRepositoryError:
            wd = os.path.dirname(wd)
            
    raise Exception("Not in a git Tree") 
开发者ID:gilestrolab,项目名称:ethoscope,代码行数:20,代码来源:helpers.py

示例5: version_check_and_info

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def version_check_and_info(module):
    """Return either git info or standard module version if not a git repo.

    Args:
        module (module): python module object to get info for.

    Returns:
        dict: dictionary of info

    """
    srcpath = inspect.getsourcefile(module)
    try:
        repo = git.Repo(srcpath, search_parent_directories=True)
    except git.InvalidGitRepositoryError:
        log.info('module %s not in a git repo, checking package version' %
                 module.__name__)
        info = version_info(module)
    else:
        info = git_info(repo)
    info['source_path'] = srcpath
    return info 
开发者ID:neuroailab,项目名称:tfutils,代码行数:23,代码来源:db_interface.py

示例6: set_working_directory

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def set_working_directory(self, directory):
        """Method to change the current working directory. Will reset the self.repo reference

        Args:
            directory(str): Absolute path to the working dir

        Returns:
            None
        """
        # Make sure you expand a user dir string
        directory = os.path.expanduser(directory)

        # Update the working dir
        self.working_directory = directory

        # Check to see if the working dir is already a repository
        try:
            self.repo = Repo(directory)
        except InvalidGitRepositoryError:
            # Make sure the working dir exists
            if not os.path.exists(directory):
                os.makedirs(directory)

            # Empty Dir
            self.repo = None 
开发者ID:gigantum,项目名称:gigantum-client,代码行数:27,代码来源:git_fs.py

示例7: _get_git_commit

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

示例8: get_git_hash

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def get_git_hash(directory, length=10):
    '''
    This function will check the state of the git repository.

    * If there is no repo, an InvalidGitRepositoryError is raised.
    * If the repo is dirty, a DirtyRepositoryException is raised.
    * If none of the above applies, the hash of the HEAD commit is returned.

    Parameters
    ----------
    directory: str
        The path to the directory to check.
    length: int
        The number of characters of the hash to return (default 10).
    '''

    # Check the state of the github repository
    repo = Repo(directory, search_parent_directories=True)
    if repo.is_dirty():
        raise DirtyGitRepositoryError('The git repo has uncommited modifications. Aborting simulation.')
    else:
        return repo.head.commit.hexsha[:length] 
开发者ID:onolab-tmu,项目名称:overiva,代码行数:24,代码来源:tools.py

示例9: __init__

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def __init__(self, path, directories_to_skip=None):
        if not os.path.isdir(path):
            raise FileNotFoundError('Path "{}" not found or is not a directory.'.format(path))
        self.path = path
        self._parsed_py_files = self._get_parsed_py_files(directories_to_skip)
        try:
            self.repo = LocalRepository(path)
        except git.InvalidGitRepositoryError:
            self.repo = None 
开发者ID:devmanorg,项目名称:fiasko_bro,代码行数:11,代码来源:repository_info.py

示例10: get

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def get():
  try:
    return git.Repo(path.dirname(path.dirname(vj4.__file__))).git.describe(always=True, tags=True, dirty=True)
  except (git.InvalidGitRepositoryError, git.GitCommandError) as e:
    _logger.error('Failed to get repository: %s', repr(e))
    return 'unknown' 
开发者ID:vijos,项目名称:vj4,代码行数:8,代码来源:version.py

示例11: test_get_git_repository_remote_url_returns_none_if_no_repository_present

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def test_get_git_repository_remote_url_returns_none_if_no_repository_present(self, repo_mock):
        repo_mock.side_effect = InvalidGitRepositoryError
        self.assertEqual(None, util.get_git_repository_remote_url(tempfile.mkdtemp())) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:5,代码来源:util_tests.py

示例12: test_get_git_repository_remote_url_returns_repo_url_from_parent_dir

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def test_get_git_repository_remote_url_returns_repo_url_from_parent_dir(self, repo_mock):
        url = "http://config.repo.git"
        repo_object_mock = Mock()
        repo_object_mock.remotes.origin.url = url
        repo_mock.side_effect = [InvalidGitRepositoryError, repo_object_mock]

        self.assertEqual(url, util.get_git_repository_remote_url(tempfile.mkdtemp())) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:9,代码来源:util_tests.py

示例13: get_git_repository_remote_url

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def get_git_repository_remote_url(working_dir):
    if not working_dir:
        return None

    try:
        repo = Repo(working_dir)
        return repo.remotes.origin.url
    except InvalidGitRepositoryError:
        (head, tail) = os.path.split(working_dir)
        if tail:
            return get_git_repository_remote_url(head)
        else:
            return None 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:15,代码来源:util.py

示例14: git_version

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [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' 
开发者ID:apache,项目名称:airflow,代码行数:36,代码来源:setup.py

示例15: gather_metadata

# 需要导入模块: import git [as 别名]
# 或者: from git import InvalidGitRepositoryError [as 别名]
def gather_metadata() -> Dict:
    date_start = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
    # Gathering git metadata.
    try:
        import git

        try:
            repo = git.Repo(search_parent_directories=True)
            git_sha = repo.commit().hexsha
            git_data = dict(
                commit=git_sha,
                branch=None if repo.head.is_detached else repo.active_branch.name,
                is_dirty=repo.is_dirty(),
                path=repo.git_dir,
            )
        except git.InvalidGitRepositoryError:
            git_data = None
    except ImportError:
        git_data = None
    # Gathering slurm metadata.
    if "SLURM_JOB_ID" in os.environ:
        slurm_env_keys = [k for k in os.environ if k.startswith("SLURM")]
        slurm_data = {}
        for k in slurm_env_keys:
            d_key = k.replace("SLURM_", "").replace("SLURMD_", "").lower()
            slurm_data[d_key] = os.environ[k]
    else:
        slurm_data = None
    return dict(
        date_start=date_start,
        date_end=None,
        successful=False,
        git=git_data,
        slurm=slurm_data,
        env=os.environ.copy(),
    ) 
开发者ID:facebookresearch,项目名称:torchbeast,代码行数:38,代码来源:file_writer.py


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