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


Python pygit2.discover_repository函数代码示例

本文整理汇总了Python中pygit2.discover_repository函数的典型用法代码示例。如果您正苦于以下问题:Python discover_repository函数的具体用法?Python discover_repository怎么用?Python discover_repository使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: init_repository

def init_repository(url=None):
  """Creates a new Gitless's repository in the cwd.

  Args:
    url: if given the local repository will be a clone of the remote repository
      given by this url.
  """
  cwd = os.getcwd()
  try:
    pygit2.discover_repository(cwd)
    raise GlError('You are already in a Gitless repository')
  except KeyError:  # Expected
    if not url:
      repo = pygit2.init_repository(cwd)
      # We also create an initial root commit
      git.commit(allow_empty=True, m='Initialize repository')
      return repo

    try:
      git.clone(url, cwd)
    except ErrorReturnCode as e:
      raise GlError(stderr(e))

    # We get all remote branches as well and create local equivalents
    repo = Repository()
    remote = repo.remotes['origin']
    for rb in (remote.lookup_branch(bn) for bn in remote.listall_branches()):
      if rb.branch_name == 'master':
        continue
      new_b = repo.create_branch(rb.branch_name, rb.head)
      new_b.upstream = rb
    return repo
开发者ID:imoapps,项目名称:gitless,代码行数:32,代码来源:core.py

示例2: is_repository

 def is_repository(directory):
     """Checks if the repository is a VCS repository"""
     try:
         pygit2.discover_repository(path_join(directory))
         return True
     except KeyError:
         return False
开发者ID:RIOT-OS,项目名称:riot_job_manager,代码行数:7,代码来源:git.py

示例3: clone

def clone(location):
    """
    Clone a Git repository if it doesn't exist into a temporary directory.

    :param str location: the Git URL to clone
    :rtype: pygit2.Repository
    """
    path = join(config.CLONE_ROOT, _simple_location_name(location))

    log.info('Cloning to path {}'.format(path))

    try:
        log.info('Looking for existing repository')
        repository_path = discover_repository(path)
    except KeyError:
        log.info('No existing repository found, cloning fresh')
        return clone_repository(location, path)
    else:
        log.info('Repository already exists at {}'.format(repository_path))
        repository = Repository(repository_path)

        remote = repository.remotes[0]
        remote.sideband_progress = log.info

        log.info('Fetching to get the latest objects from remote')
        remote.fetch()

        return repository
开发者ID:robmadole,项目名称:lure,代码行数:28,代码来源:git.py

示例4: analyze

def analyze(url, api_token):
    github_url = url.strip().replace("http://www.github.com/", "")
    github_url = github_url.strip().replace("https://www.github.com/", "")
    github_url = github_url.strip().replace("http://github.com/", "")
    github_url = github_url.strip().replace("https://github.com/", "")

    print("Start analyzing: %s" % github_url)
    start_time = time.perf_counter()

    g = Github(api_token)
    repo = g.get_repo(github_url)

    stats = open(os.path.join("github", repo.owner.login + "-" + repo.name), "w")
    stats.write("forks;branches;watchers;stars\n")
    stats.write("%d;%d;%d;%d\n"
                % (repo.forks_count, len(list(repo.get_branches())),
                   repo.watchers_count, repo.stargazers_count))
    stats.flush()
    stats.close()

    repo_path = os.path.join(os.getcwd(), "git", repo.owner.login, repo.name)

    # initialize repo
    if os.path.exists(repo_path):
        cloned_repo = Repository(discover_repository(repo_path))
    else:
        cloned_repo = clone_repository(repo.clone_url, repo_path)

    # run churny
    run("churny " + repo_path, os.path.join("overall", repo.owner.login + "-" + repo.name))
    run("churny -m " + repo_path, os.path.join("monthly", repo.owner.login + "-" + repo.name))

    elapsed_time = time.perf_counter() - start_time
    print("Stop analyzing: %s (%d s)" % (github_url, elapsed_time))
开发者ID:xai,项目名称:churny,代码行数:34,代码来源:churny-wrapper.py

示例5: __init__

    def __init__(self, repo_url, dir_manager, credentials_manager):
        """
        :repo_url: URL of the repository
        :repo_dir: directory where the repository is expected to reside
        """
        self.up2date = False
        self.repo_url = repo_url
        dir_path = dir_manager.get_repo_dir(repo_url)

        my_credentials = credentials_manager.get_credentials(repo_url)

        if not os.path.isfile(dir_path + '/HEAD'):
            try:
                self.repo = pygit2.clone_repository(repo_url, dir_path, bare=True, credentials=my_credentials)
            except pygit2.GitError as e:
                raise GitException("Cloning failed. {}".format(e.message))
        else:
            self.repo = pygit2.Repository(pygit2.discover_repository(dir_path))
            self.up2date = True

            def _remote_credentials(url, username_from_url, allowed_types):
                return credentials_manager.get_credentials(url)

            for remote in self.repo.remotes:
                remote.credentials = _remote_credentials
                transfer_progress = remote.fetch()
                if transfer_progress.received_objects:
                    self.up2date = False
开发者ID:RepoGrams,项目名称:RepoGrams,代码行数:28,代码来源:git_helpers.py

示例6: init

    def init(self):
        if pygit2 is None:
            self.text = glyphs.BRANCH + ' ' + glyphs.WRITE_ONLY
            self.bg = colors.background(colors.RED)
            self.fg = colors.foreground(colors.WHITE)
            return

        try:
            repo_path = pygit2.discover_repository(os.getcwd())
            self.repo = pygit2.Repository(repo_path)
        except Exception:
            self.active = False
            return

        branch_name = self.get_branch_name()

        if not branch_name:
            self.active = False
            return

        git_colors = self.get_working_dir_status_decorations()
        self.bg = colors.background(git_colors[0])
        self.fg = colors.foreground(git_colors[1])

        current_commit_text = self.get_current_commit_decoration_text()
        self.text = (glyphs.BRANCH + ' ' + branch_name + ' ' + current_commit_text).strip()
开发者ID:jsjohnst,项目名称:prompt.bash,代码行数:26,代码来源:segments.py

示例7: dendrifier_for_path

def dendrifier_for_path(dirname, _ceiling_dir_for_testing='', report_to_stdout=False):
    try:
        repo = git.discover_repository(dirname, False, _ceiling_dir_for_testing)
    except KeyError:
        raise ValueError('could not find git repo starting from {}'.format(dirname))
    kwargs = {'report': dendrify.ReportToStdout()} if report_to_stdout else {}
    return dendrify.Dendrifier(repo, **kwargs)
开发者ID:bennorth,项目名称:git-dendrify,代码行数:7,代码来源:cli.py

示例8: GitableDir

    def GitableDir(path):

        """

        A directory in which you can do Git things -- i.e. a git
        repository or a subdirectory of a checked_out repository.

        Parameters:
          path (string): A path name.  \"~\"-expansion will be performed.

        Returns:
          Tuple (supplied path name, absolute path name) upon success

        Raises:
          argparse.ArgumentTypeError if no Git repository is found
        
        """
        
        realpath=os.path.abspath(os.path.expanduser(path))
        if not os.path.isdir(realpath):
            err_str = "'{}' does not exist or is not a directory".format(path)
            raise argparse.ArgumentTypeError(err_str)
        try:
            repo_path=pygit2.discover_repository(realpath)
            return(path,repo_path)
        except KeyError, e:
            err_str = "No Git repo found in {} or its parent dirs".format(e.args[0])
            raise argparse.ArgumentTypeError(err_str)
开发者ID:ewa,项目名称:git-tree-viz,代码行数:28,代码来源:gitree.py

示例9: from_cwd

 def from_cwd(cls):
     """Get the Repository object implied by the current directory."""
     try:
         repo_path = pygit2.discover_repository(os.getcwd())
     except KeyError:
         raise NotARepository("current directory not part of a repository")
     return cls(repo_path)
开发者ID:malea,项目名称:twit.py,代码行数:7,代码来源:twit.py

示例10: __init__

    def __init__(self):
        try:
            self.repo_dir = git.discover_repository('.')
        except KeyError:
            raise NotInRepoError()

        self.repo = git.Repository(self.repo_dir)
        self.commit = self.repo.head.target.hex
        self.basedir = self.repo.workdir
开发者ID:paulgb,项目名称:crumb,代码行数:9,代码来源:repo.py

示例11: _discover_repository

def _discover_repository(where, *, follow_links=False):
    try:
        repo_path = pygit2.discover_repository(str(where), follow_links)
    except KeyError:
        # KeyError is GIT_ENOTFOUND, which in this case means this doesn't
        # appear to be a repository
        raise NoSuchRepository
    else:
        return Path(repo_path)
开发者ID:eevee,项目名称:tcup,代码行数:9,代码来源:repo.py

示例12: get_repo

def get_repo(path):
    path = os.path.abspath(path)
    os.chdir(path)
    try:
        repo_path = pygit2.discover_repository(path)
        return pygit2.Repository(repo_path)
    except KeyError:
        print("Cannot find a repository in '{}'.".format(path))
        exit(1)
开发者ID:barracudanetworks,项目名称:gitutils,代码行数:9,代码来源:__init__.py

示例13: _vcs_root

 def _vcs_root(self, path):
     """Find the root of the deepest repository containing path."""
     # Assume that nothing funny is going on; in particular, that we aren't
     # dealing with a bare repo.
     gitdir = _pygit2.discover_repository(path)
     self._pygit_repository = _pygit2.Repository(gitdir)
     dirname,tip = os.path.split(gitdir)
     if tip == '':  # split('x/y/z/.git/') == ('x/y/z/.git', '')
         dirname,tip = os.path.split(dirname)
     assert tip == '.git', tip
     return dirname
开发者ID:gitmob,项目名称:yabbe,代码行数:11,代码来源:git.py

示例14: __init__

    def __init__(self, context, repo_path=None):
        self.context = context
        rp = IStorageInfo(context).path

        try:
            self.repo = Repository(discover_repository(rp))
        except KeyError:
            # discover_repository may have failed.
            raise PathNotFoundError('repository does not exist at path')

        self.checkout()  # defaults to HEAD.
开发者ID:repodono,项目名称:repodono.backend_git,代码行数:11,代码来源:utility.py

示例15: set_repository

def set_repository(value):
    from pygit2 import discover_repository, Repository
    global _repository
    if value is None:
        _repository = None
        return
    try:
        path = discover_repository(value)
    except KeyError:
        raise GitError('no repository found in "{}"'.format(value))
    _repository = Repository(path)
开发者ID:systemsoverload,项目名称:python-git-orm,代码行数:11,代码来源:__init__.py


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