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


Python Repository.status方法代码示例

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


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

示例1: git_is_clean

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import status [as 别名]
def git_is_clean(srcdir, project):
    repo = Repository(os.path.join(srcdir, project.workspace_path, ".git"))
    for _, b in iteritems(repo.status()):
        if b != GIT_STATUS_IGNORED and b != GIT_STATUS_CURRENT:
            return False, "has uncommitted changes"
    if repo.head_is_detached:
        return False, "has detached HEAD"
    origin = get_origin(repo, project)
    if not origin:
        return False, "has no upstream remote"
    remote_refs = []
    local_refs = {}
    for refname in repo.listall_references():
        if refname.startswith("refs/remotes/%s/" % origin.name):
            ref = repo.lookup_reference(refname)
            if ref.type == GIT_REF_OID:
                remote_refs.append(ref.target)
        elif not refname.startswith("refs/remotes/"):
            ref = repo.lookup_reference(refname)
            if ref.type == GIT_REF_OID:
                local_refs[ref.peel().id] = refname
    if not remote_refs:
        return False, "has no upstream remote branches"
    if not local_refs:
        return False, "has no local branches"
    if not repo.lookup_branch("%s/%s" % (origin.name, project.master_branch), GIT_BRANCH_REMOTE):
        return False, "has no upstream master branch"
    for remote_ref in remote_refs:
        for commit in repo.walk(remote_ref):
            if commit.id in local_refs:
                del local_refs[commit.id]
    if local_refs:
        return False, "has local commits: %s" % ", ".join(["'%s'" % name for _, name in iteritems(local_refs)])
    return True, ""
开发者ID:fkie,项目名称:rosrepo,代码行数:36,代码来源:cmd_include_exclude.py

示例2: get_deleted_files

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import status [as 别名]
def get_deleted_files(path_to_repository):
    """Utility method for getting the deleted files from a Git repository.

        Args:
            path_to_repository (str): Path to the Git repository

        Returns:
            List(str): List of filenames of all deleted files in the provided repository.
    """
    repo = Repository(path_to_repository)
    status_entries = repo.status()
    return [path for path, st in status_entries.items() if st & _STATI_DELETED]
开发者ID:cqse,项目名称:teamscale-cli,代码行数:14,代码来源:git_utils.py

示例3: get_changed_files

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import status [as 别名]
def get_changed_files(path_to_repository):
    """Utility method for getting the currently changed files from a Git repository.

        Args:
            path_to_repository (str): Path to the Git repository

        Returns:
            List(str): List of filenames of all changed files in the provided repository.
    """
    repo = Repository(path_to_repository)
    status_entries = repo.status()
    return [path for path, st in status_entries.items() if st & _STATI_CONSIDERED_FOR_PRECOMMIT]
开发者ID:cqse,项目名称:teamscale-cli,代码行数:14,代码来源:git_utils.py

示例4: update_repo

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import status [as 别名]
def update_repo(reponame):
    """ For a given path to a repo, pull/rebase the last changes if
    it can, add/remove/commit the new changes and push them to the
    remote repo if any.

    :kwarg reponame, full path to a git repo.
    """
    LOG.info('Processing %s' % reponame)
    if not os.path.exists(reponame):
        raise GitSyncError(
            'The indicated working directory does not exists: %s' %
            reponame)
    try:
        repo = Repository(reponame)
    except Exception as err:
        print(err)
        raise GitSyncError(
            'The indicated working directory is not a valid git '
            'repository: %s' % reponame)

    index = repo.index
    dopush = False
    origin = None

    index = repo.index
    ## Add or remove to staging the files according to their status
    if repo.status:
        status = repo.status()
        for filepath, flag in status.items():
            if flag == GIT_STATUS_WT_DELETED:
                msg = 'Remove file %s' % filepath
                LOG.info(msg)
                index.remove(filepath)
                docommit(repo, index, msg)
                dopush = True
            elif flag == GIT_STATUS_WT_NEW:
                msg = 'Add file %s' % filepath
                LOG.info(msg)
                index.add(filepath)
                docommit(repo, index, msg)
                dopush = True
            elif flag == GIT_STATUS_WT_MODIFIED:
                msg = 'Change file %s' % filepath
                LOG.info(msg)
                index.add(filepath)
                docommit(repo, index, msg)
                dopush = True

    return dopush
开发者ID:pypingou,项目名称:gitsync,代码行数:51,代码来源:gitsync.py

示例5: changed_includes

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import status [as 别名]
def changed_includes(conf):
    from pygit2 import Repository, GIT_STATUS_CURRENT, GIT_STATUS_IGNORED

    repo_path = conf.paths.projectroot

    r = Repository(repo_path)

    changed = []
    for path, flag in r.status().items():
        if flag not in [GIT_STATUS_CURRENT, GIT_STATUS_IGNORED]:
            if path.startswith('source/'):
                if path.endswith('.txt') or path.endswith('.rst'):
                    changed.append(path[6:])

    changed_report = []

    for fn in include_files(conf):
        if fn in changed:
            changed_report.append(fn)

    return changed_report
开发者ID:fviolette,项目名称:docs-tools,代码行数:23,代码来源:includes.py

示例6: changed_includes

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import status [as 别名]
def changed_includes(conf=None):
    from pygit2 import Repository, GIT_STATUS_CURRENT, GIT_STATUS_IGNORED
    conf = lazy_conf(conf)

    repo_path = conf.paths.projectroot

    r = Repository(repo_path)

    changed = []
    for path, flag in r.status().items():
        if flag not in [ GIT_STATUS_CURRENT, GIT_STATUS_IGNORED ]:
            if path.startswith('source/'):
                if path.endswith('.txt'):
                    changed.append(path[6:])

    source_path = os.path.join(conf.paths.source, conf.paths.output, conf.git.branches.current, 'json')
    changed_report = []

    for report in _generate_report(None):
        if report['source'][len(source_path):] in changed:
            changed_report.append(report)

    return changed_report
开发者ID:RandomStuffs22,项目名称:docs-tools,代码行数:25,代码来源:includes.py

示例7: changed

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import status [as 别名]
def changed(output='print'):
    try:
        from pygit2 import Repository, GIT_STATUS_CURRENT, GIT_STATUS_IGNORED
    except ImportError:
        puts('[stats]: cannot detect changed files. Please install pygit2')

    conf = get_conf()

    repo_path = conf.paths.projectroot

    r = Repository(repo_path)

    changed = []
    for path, flag in r.status().items():
        if flag not in [GIT_STATUS_CURRENT, GIT_STATUS_IGNORED]:
            if path.startswith(conf.paths.source):
                if path.endswith('.txt'):
                    changed.append(path[6:])

    source_path = os.path.join(
        conf.paths.source, conf.paths.output, conf.git.branches.current, 'json')
    changed_report = []

    for report in generate_report(None):
        if report['source'][len(source_path):] in changed:
            changed_report.append(report)

    if not len(changed_report) == 0:
        changed_report.append(multi(data=changed_report, output_file=None))

    if output is None:
        return changed_report
    elif output == 'print':
        puts(json.dumps(changed_report, indent=2))
    else:
        json.dump(changed_report, output)
开发者ID:cyborginstitute,项目名称:institute-tools,代码行数:38,代码来源:stats.py

示例8: RepositoryInfo

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import status [as 别名]
class RepositoryInfo(object):
    """ wraps an pygit2.Repository object
    """

    def __init__(self, repo_path):
        self._repo = Repository(repo_path)
        self.count_unmodified = 0
        self.count_wt_modified = 0
        self.count_wt_new = 0
        self.count_wt_deleted = 0
        self.count_index_modified = 0
        self.count_index_new = 0
        self.count_index_deleted = 0
        self._count()

    @property
    def path(self):
        sep = '/'
        splitted = self._repo.path.split(sep)[0:-2]
        return sep.join(splitted)

    @property
    def has_workingtree_changes(self):
        return self.count_wt_deleted > 0 or self.count_wt_modified > 0 or self.count_wt_new > 0

    @property
    def has_index_changes(self):
        return self.count_index_deleted > 0 or self.count_index_modified > 0 or self.count_index_new > 0

    def _count(self):
        _status = self._repo.status()
        for file_path, flags in _status.items():
            if flags == GIT_STATUS_CURRENT:
                self.count_unmodified += 1
            elif flags == GIT_STATUS_WT_MODIFIED:
                self.count_wt_modified += 1
            elif flags == GIT_STATUS_WT_NEW:
                self.count_wt_new += 1
            elif flags == GIT_STATUS_INDEX_NEW:
                self.count_index_new += 1
            elif flags == GIT_STATUS_INDEX_MODIFIED:
                self.count_index_modified += 1
            elif flags == GIT_STATUS_INDEX_DELETED:
                self.count_index_deleted += 1
            elif flags == GIT_STATUS_WT_DELETED:
                self.count_wt_deleted += 1

    @property
    def current_branch_name(self):
        # ToDo: Why does self._repo.head.shorthand not work?
        head = self._repo.head
        head_name = head.name.split('/')[-1:]
        return head_name[0]

    @property
    def is_head_upstream_branch(self):
        """ determines if current head is the same commit as the remote commit
        """
        if self._repo.head_is_detached:
            return False
        current_branch_name = self.current_branch_name
        head = self._repo.head
        remote_branch = self._repo.lookup_branch(current_branch_name).upstream
        if remote_branch:
            return remote_branch.target.hex == head.target.hex
        return False

    @property
    def is_head_detached(self):
        return self._repo.head_is_detached
开发者ID:krissik,项目名称:whatsupgit,代码行数:72,代码来源:repositoryinfo.py

示例9: show_status

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import status [as 别名]
def show_status(srcdir, packages, projects, other_git, ws_state, show_up_to_date=True, cache=None):
    def create_upstream_status(repo, head_branch, master_branch, master_remote_branch, tracking_branch):
        status = []
        if not repo.head_is_detached and not has_pending_merge(repo):
            if tracking_branch is not None:
                if master_remote_branch is not None:
                    if tracking_branch.remote_name != master_remote_branch.remote_name:
                        status.append("@[email protected]{rf}remote '%s'" % tracking_branch.remote_name)
                if need_push(repo, head_branch):
                    status.append("@[email protected]{yf}needs push")
                elif need_pull(repo, head_branch):
                    status.append("@[email protected]{cf}needs pull")
                elif not is_up_to_date(repo, head_branch):
                    status.append("@[email protected]{yf}needs pull -M")
            else:
                if head_branch:
                    status.append("@!on branch '%s'" % repo.head.shorthand)
                else:
                    status.append("empty branch")
                if master_remote_branch is None:
                    status.append("@[email protected]{rf}no remote")
                elif master_branch is None:
                    status.append("@[email protected]{rf}untracked remote")
                if is_up_to_date(repo, master_branch) or need_push(repo, master_branch):
                    if need_pull(repo, head_branch, master_branch):
                        status.append("@[email protected]{cf}needs pull -L")
                    else:
                        if not is_ancestor(repo, master_branch, head_branch):
                            status.append("@[email protected]{yf}needs merge --from-master")
                        if not is_up_to_date(repo, head_branch, master_branch):
                            status.append("@[email protected]{yf}needs merge --to-master")
            if master_branch is not None and master_remote_branch is not None and (tracking_branch is None or tracking_branch.name != master_remote_branch.name):
                if need_push(repo, master_branch):
                    status.append("@[email protected]{yf}%s needs push" % master_branch.shorthand)
                elif need_pull(repo, master_branch):
                    status.append("@[email protected]{cf}%s needs pull" % master_branch.shorthand)
                elif not is_up_to_date(repo, master_branch):
                    status.append("@[email protected]{yf}%s needs merge" % master_branch.shorthand)
        return status

    def create_local_status(repo, upstream_status, is_dirty):
        status = []
        if repo.head_is_detached:
            status.append("@[email protected]{rf}detached HEAD")
            return status
        if has_pending_merge(repo):
            if repo.index.conflicts:
                status.append("@[email protected]{rf}merge conflicts")
            else:
                status.append("@[email protected]{yf}merged, needs commit")
            return status
        if is_dirty:
            status.append("@[email protected]{yf}needs commit")
        status += upstream_status
        if not status:
            if not show_up_to_date:
                return None
            status.append("@[email protected]{gf}up-to-date")
        return status

    table = TableView("Package", "Path", "Status")

    found_packages = set()
    for project in projects:
        repo = Repository(os.path.join(srcdir, project.workspace_path, ".git"))
        dirty_files = [a for a, b in iteritems(repo.status()) if b != GIT_STATUS_IGNORED and b != GIT_STATUS_CURRENT]
        head_branch = get_head_branch(repo)
        tracking_branch = head_branch.upstream if head_branch else None
        master_remote = get_origin(repo, project)
        if master_remote is not None:
            master_remote_branch = repo.lookup_branch("%s/%s" % (master_remote.name, project.master_branch), GIT_BRANCH_REMOTE)
            master_branch = None
            if master_remote_branch is not None:
                for name in repo.listall_branches(GIT_BRANCH_LOCAL):
                    b = repo.lookup_branch(name, GIT_BRANCH_LOCAL)
                    if b.upstream and b.upstream.branch_name == master_remote_branch.branch_name:
                        master_branch = b
                        break
        else:
            master_remote_branch = None
            master_branch = None
        ws_packages = find_catkin_packages(srcdir, project.workspace_path, cache=cache)
        found_packages |= set(ws_packages.keys())
        upstream_status = create_upstream_status(repo, head_branch, master_branch, master_remote_branch, tracking_branch)
        for name, pkg_list in iteritems(ws_packages):
            if name not in packages:
                continue
            for pkg in pkg_list:
                is_dirty = False
                local_path = os.path.relpath(pkg.workspace_path, project.workspace_path)
                if dirty_files and local_path == ".":
                    is_dirty = True
                else:
                    for fpath in dirty_files:
                        if path_has_prefix(fpath, local_path):
                            is_dirty = True
                            break
                status = create_local_status(repo, upstream_status, is_dirty)
                if status is not None:
                    head, tail = os.path.split(pkg.workspace_path)
#.........这里部分代码省略.........
开发者ID:fkie,项目名称:rosrepo,代码行数:103,代码来源:cmd_git.py

示例10: GitStorage

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import status [as 别名]
class GitStorage(Storage):
    """ Git file storage backend. """

    def __init__(self, path):
        """
            Initialize repository.

            :param path: Absolute path to the existing Git repository.
            :type path: str
        """

        super(GitStorage, self).__init__()

        self.repo = Repository(path)
        self.index = self.repo.index
        self.index.read()

    @classmethod
    def create_storage(cls, path):
        """
            Create repository, and return GitStorage object on it

            :param path: Absolute path to the Git repository to create.
            :type path: str
            :returns: GitStorage
        """

        init_repository(path, False)

        return cls(path)

    def commit(self, user, message):
        """
            Save previous changes in a new commit.

            :param user: The commit author/committer.
            :type user: django.contrib.auth.models.User
            :param message: The commit message.
            :type message: unicode
            :returns: pygit2.Commit
        """

        # Refresh index before committing
        index = self.repo.index
        index.read()

        # Check the status of the repository
        status = self.repo.status()

        for filename, flags in status.items():
            # the file was deleted
            if flags in (GIT_STATUS_INDEX_DELETED, GIT_STATUS_WT_DELETED):
                # remove it from the tree
                del index[filename]

            # or the file was modified/added
            elif flags in (GIT_STATUS_INDEX_MODIFIED, GIT_STATUS_INDEX_NEW,
                           GIT_STATUS_WT_MODIFIED, GIT_STATUS_WT_NEW):
                # add it to the tree
                index.add(filename)

        treeid = index.write_tree()

        # Now make the commit

        author = Signature(u'{0} {1}'.format(
            user.first_name,
            user.last_name).encode('utf-8'),
            user.email.encode('utf-8')
        )
        committer = author

        try:
            parents = [self.repo.head.oid]

        except GitError:
            parents = []

        commit = self.repo.create_commit(
            'refs/heads/master',
            author, committer, message,
            treeid,
            parents
        )

        # Write changes to disk
        index.write()
        # and refresh index.
        self.index.read()

        # Return commit object
        return self.repo[commit]

    def log(self, name=None, limit=10):
        """
            Get history of the repository, or of a file if name is not None.

            :param name: File name within the repository.
            :type name: unicode or None
            :param limit: Maximal number of commits to get (default: 10), use a negative number to get all.
#.........这里部分代码省略.........
开发者ID:9h37,项目名称:django-gitstorage,代码行数:103,代码来源:StorageBackend.py


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