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


Python git.GitCommandError方法代码示例

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


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

示例1: print_git_commit

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def print_git_commit():
    """
    Print the current git commit of ParlAI and parlai_internal.
    """
    root = os.path.dirname(os.path.dirname(parlai.__file__))
    internal_root = os.path.join(root, 'parlai_internal')
    try:
        git_ = git.Git(root)
        current_commit = git_.rev_parse('HEAD')
        logging.info(f'Current ParlAI commit: {current_commit}')
    except git.GitCommandNotFound:
        pass
    except git.GitCommandError:
        pass

    try:
        git_ = git.Git(internal_root)
        internal_commit = git_.rev_parse('HEAD')
        logging.info(f'Current internal commit: {internal_commit}')
    except git.GitCommandNotFound:
        pass
    except git.GitCommandError:
        pass 
开发者ID:facebookresearch,项目名称:ParlAI,代码行数:25,代码来源:params.py

示例2: file_owner

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def file_owner(self, rev, filename, committer=True):
        """
        Returns the owner (by majority blame) of a given file in a given rev. Returns the committers' name.

        :param rev:
        :param filename:
        :param committer:
        """
        try:
            if committer:
                cm = 'committer'
            else:
                cm = 'author'

            blame = self.repo.blame(rev, os.path.join(self.git_dir, filename))
            blame = DataFrame([[x[0].committer.name, len(x[1])] for x in blame], columns=[cm, 'loc']).groupby(cm).agg(
                {'loc': np.sum})
            if blame.shape[0] > 0:
                return blame['loc'].idxmax()
            else:
                return None
        except (GitCommandError, KeyError):
            if self.verbose:
                print('Couldn\'t Calcualte File Owner for %s' % (rev,))
            return None 
开发者ID:wdm0006,项目名称:git-pandas,代码行数:27,代码来源:repository.py

示例3: __init__

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def __init__(self, folder: str=".",
                 dry_run=False,
                 home='bioconda/bioconda-recipes',
                 fork=None,
                 allow_dirty=True,
                 depth=1) -> None:
        if os.path.exists(folder):
            repo = git.Repo(folder, search_parent_directories=True)
        else:
            try:
                os.mkdir(folder)
                logger.error("cloning %s into %s", home, folder)
                repo = git.Repo.clone_from(home, folder, depth=depth)
            except git.GitCommandError:
                os.rmdir(folder)
                raise
        super().__init__(repo, dry_run, home, fork, allow_dirty)

        #: Branch to restore after running
        self.prev_active_branch = self.repo.active_branch 
开发者ID:bioconda,项目名称:bioconda-utils,代码行数:22,代码来源:githandler.py

示例4: handle_git_except

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def handle_git_except(f):
    """Wrapper which handles `RenkuException`."""
    # noqa
    @wraps(f)
    def decorated_function(*args, **kwargs):
        """Represents decorated function."""
        try:
            return f(*args, **kwargs)
        except GitCommandError as e:

            error_code = GIT_ACCESS_DENIED_ERROR_CODE \
                if 'Access denied' in e.stderr else GIT_UNKNOWN_ERROR_CODE

            return jsonify(
                error={
                    'code': error_code,
                    'reason':
                        'git error: {0}'.
                        format(' '.join(e.stderr.strip().split('\n'))),
                }
            )

    return decorated_function 
开发者ID:SwissDataScienceCenter,项目名称:renku-python,代码行数:25,代码来源:decorators.py

示例5: find_attr

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

示例6: fetch_diff

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def fetch_diff(self):
        SyncGit.logger.info("Fetching diff from remote origin")

        try:
            firehol_repo = git.cmd.Git(self.repo_path)
            firehol_repo.checkout("master")
            firehol_repo.fetch("origin")
            diff_stdout = firehol_repo.execute(["git", "diff", "master", "origin/master"], True).split("\n")

            try:
                udiff = unidiff.PatchSet(diff_stdout)
                firehol_repo.execute(["git", "reset", "--hard", "origin/master"])
                firehol_repo.merge()
                self.logger.info("Successfully fetched diff from remote origin")

                return udiff

            except unidiff.UnidiffParseError:
                self.logger.exception("UnidiffParseError occurred")

        except git.GitCommandError:
            self.logger.exception("GitCommandError occurred") 
开发者ID:spacepatcher,项目名称:FireHOL-IP-Aggregator,代码行数:24,代码来源:sync.py

示例7: print_git_commit

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def print_git_commit():
    """Print the current git commit of ParlAI and parlai_internal."""
    root = os.path.dirname(os.path.dirname(parlai.__file__))
    internal_root = os.path.join(root, 'parlai_internal')
    try:
        git_ = git.Git(root)
        current_commit = git_.rev_parse('HEAD')
        print(f'[ Current ParlAI commit: {current_commit} ]')
    except git.GitCommandNotFound:
        pass
    except git.GitCommandError:
        pass

    try:
        git_ = git.Git(internal_root)
        internal_commit = git_.rev_parse('HEAD')
        print(f'[ Current internal commit: {internal_commit} ]')
    except git.GitCommandNotFound:
        pass 
开发者ID:natashamjaques,项目名称:neural_chat,代码行数:21,代码来源:params.py

示例8: update_all_visible_branches

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def update_all_visible_branches(self):
        """
        Update all visible branches (for normal users, this will be master and dev).
        For developers, new branches can be discovered (see ``discover_branches``).
        :return:
        """
        branches = self._working_repo.branches
        out = {}

        one_success = False
        for b in branches:

            try:
                key = str(b)
                out[key]=False
                self.update_branch(b)
                out[key]=True
                one_success = True
            except GitCommandError as e:
                logging.error(traceback.format_exc())

        if not one_success:
            raise Exception("Could not update any branch. Are you connected to internet?")
        return out 
开发者ID:gilestrolab,项目名称:ethoscope,代码行数:26,代码来源:updater.py

示例9: link_github_repo

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def link_github_repo(self, get_repo_name: Callable = None) -> Optional[Repository]:
        if 'origin' not in Git(self.path).remote().split('\n'):
            if ask_yes_no(
                    'Would you like to link an existing GitHub repo to it? (Y/n)',
                    True):
                repo_name = (get_repo_name and get_repo_name()) or (
                        self.name + '-skill')
                repo = self.user.get_repo(repo_name)
                self.git.remote('add', 'origin', repo.html_url)
                self.git.fetch()
                try:
                    self.git.pull('origin', 'master')
                except GitCommandError as e:
                    if e.status == 128:
                        raise UnrelatedGithubHistory(repo_name) from e
                    raise
                self.git.push('origin', 'master', set_upstream=True)
                print('Linked and pushed to GitHub repo:', repo.html_url)
                return repo 
开发者ID:MycroftAI,项目名称:mycroft-skills-kit,代码行数:21,代码来源:create.py

示例10: create_or_update

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def create_or_update(self, git_url, repo_dir):
        for i in range(1, RETRY + 1):
            try:
                if os.path.isdir(repo_dir):
                     # pull
                     g = git.cmd.Git(repo_dir)
                     g.pull()
                else:
                     # clone
                     Repo.clone_from(git_url, repo_dir)
            except git.GitCommandError as ex:
                logging.info("error:{0}: retry:{1}/{2}".format(ex, i, RETRY))
                time.sleep(10 * i)
                logging.info("retrying")
            else:
                return True
        logging.exception("max retry count reached")
        raise 
开发者ID:tbmihailov,项目名称:overleaf-backup-tool,代码行数:20,代码来源:GitStorage.py

示例11: _refresh_master

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def _refresh_master(self):
        """Update local git repo and origin.

        As origin is disjoint from upstream, it needs to be updated by this script.
        """
        if not self.push_branch:
            return

        print('Syncing local, origin and upstream...')
        self.repo.git.fetch('--all')
        self.repo.git.checkout('master')
        self.repo.git.reset('--hard')
        self.repo.git.clean('-fdx')
        if 'upstream' not in self.repo.remotes:
            self.repo.create_remote('upstream', url=LLVM_GITHUB_URL)
            self.repo.remotes.upstream.fetch()
        self.repo.git.pull('origin', 'master')
        self.repo.git.pull('upstream', 'master')
        try:
            self.repo.git.push('origin', 'master')
            print('refresh of master branch completed')
        except GitCommandError as e:
            print('Info: Could not push to origin master.') 
开发者ID:google,项目名称:llvm-premerge-checks,代码行数:25,代码来源:apply_patch2.py

示例12: _rollback

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def _rollback(release_metadata):
  if release_metadata.dry_run:
    return
  
  try:
    release_metadata.repo.git.tag("-d", release_metadata.new_version)
  except git.GitCommandError:
    pass
  
  if os.path.isdir(INSTALLERS_OUTPUT_DIRPATH):
    shutil.rmtree(INSTALLERS_OUTPUT_DIRPATH)
  
  release_metadata.repo.git.reset(
    "--hard", release_metadata.last_commit_id_before_release)
  release_metadata.gh_pages_repo.git.reset(
    "--hard", release_metadata.last_gh_pages_commit_id_before_release) 
开发者ID:khalim19,项目名称:gimp-plugin-export-layers,代码行数:18,代码来源:make_release.py

示例13: get_commits_modified_file

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def get_commits_modified_file(self, filepath: str) -> List[str]:
        """
        Given a filepath, returns all the commits that modified this file
        (following renames).

        :param str filepath: path to the file
        :return: the list of commits' hash
        """
        path = str(Path(filepath))

        commits = []
        try:
            commits = self.git.log("--follow", "--format=%H", path).split('\n')
        except GitCommandError:
            logger.debug("Could not find information of file %s", path)

        return commits 
开发者ID:ishepard,项目名称:pydriller,代码行数:19,代码来源:git_repository.py

示例14: coverage

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def coverage(self):
        """
        Will return a DataFrame with coverage information (if available) for each repo in the project).

        If there is a .coverage file available, this will attempt to form a DataFrame with that information in it, which
        will contain the columns:

         * repository
         * filename
         * lines_covered
         * total_lines
         * coverage

        If it can't be found or parsed, an empty DataFrame of that form will be returned.

        :return: DataFrame
        """

        df = pd.DataFrame(columns=['filename', 'lines_covered', 'total_lines', 'coverage', 'repository'])

        for repo in self.repos:
            try:
                cov = repo.coverage()
                cov['repository'] = repo.repo_name
                df = df.append(cov)
            except GitCommandError:
                print('Warning! Repo: %s seems to not have coverage' % (repo, ))

        df.reset_index()

        return df 
开发者ID:wdm0006,项目名称:git-pandas,代码行数:33,代码来源:project.py

示例15: file_change_rates

# 需要导入模块: import git [as 别名]
# 或者: from git import GitCommandError [as 别名]
def file_change_rates(self, branch='master', limit=None, coverage=False, days=None, ignore_globs=None, include_globs=None):
        """
        This function will return a DataFrame containing some basic aggregations of the file change history data, and
        optionally test coverage data from a coverage_data.py .coverage file.  The aim here is to identify files in the
        project which have abnormal edit rates, or the rate of changes without growing the files size.  If a file has
        a high change rate and poor test coverage, then it is a great candidate for writing more tests.

        :param branch: (optional, default=master) the branch to return commits for
        :param limit: (optional, default=None) a maximum number of commits to return, None for no limit
        :param coverage: (optional, default=False) a bool for whether or not to attempt to join in coverage data.
        :param days: (optional, default=None) number of days to return if limit is None
        :param ignore_globs: (optional, default=None) a list of globs to ignore, default none excludes nothing
        :param include_globs: (optinal, default=None) a list of globs to include, default of None includes everything.
        :return: DataFrame
        """

        columns = ['unique_committers', 'abs_rate_of_change', 'net_rate_of_change', 'net_change', 'abs_change', 'edit_rate', 'repository']
        if coverage:
            columns += ['lines_covered', 'total_lines', 'coverage']
        df = pd.DataFrame(columns=columns)

        for repo in self.repos:
            try:
                fcr = repo.file_change_rates(
                    branch=branch,
                    limit=limit,
                    coverage=coverage,
                    days=days,
                    ignore_globs=ignore_globs,
                    include_globs=include_globs
                )
                fcr['repository'] = repo.repo_name
                df = df.append(fcr)
            except GitCommandError:
                print('Warning! Repo: %s seems to not have the branch: %s' % (repo, branch))

        df.reset_index()

        return df 
开发者ID:wdm0006,项目名称:git-pandas,代码行数:41,代码来源:project.py


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