How to use the pygit2.GIT_OBJ_COMMIT function in pygit2

To help you get started, we’ve selected a few pygit2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libgit2 / pygit2 / test / test_repository.py View on Github external
def test_lookup_commit(self):
        commit_sha = '5fe808e8953c12735680c257f56600cb0de44b10'
        commit = self.repo[commit_sha]
        assert commit_sha == commit.hex
        assert GIT_OBJ_COMMIT == commit.type
        assert commit.message == ('Second test data commit.\n\n'
                                  'This commit has some additional text.\n')
github libgit2 / pygit2 / test / test_tag.py View on Github external
def test_read_tag(self):
        repo = self.repo
        tag = repo[TAG_SHA]
        target = repo[tag.target]
        assert isinstance(tag, pygit2.Tag)
        assert pygit2.GIT_OBJ_TAG == tag.type
        assert pygit2.GIT_OBJ_COMMIT == target.type
        assert 'root' == tag.name
        assert 'Tagged root commit.\n' == tag.message
        assert 'Initial test data commit.\n' == target.message
        assert tag.tagger == pygit2.Signature('Dave Borowitz', 'dborowitz@google.com', 1288724692, -420)
github Pagure / pagure / tests / test_pagure_lib_git_get_tags_objects.py View on Github external
def add_repo_tag(git_dir, repo, tags, repo_name):
    """ Use a list to create multiple tags on a git repo """
    for tag in reversed(tags):
        time.sleep(1)
        tests.add_commit_git_repo(
            os.path.join(git_dir, "repos", repo_name), ncommits=1
        )
        first_commit = repo.revparse_single("HEAD")
        tagger = pygit2.Signature("Alice Doe", "adoe@example.com", 12347, 0)
        repo.create_tag(
            tag,
            first_commit.oid.hex,
            pygit2.GIT_OBJ_COMMIT,
            tagger,
            "Release " + tag,
        )
github sdg-mit / gitless / gitless / core.py View on Github external
def create_tag(self, name, commit):
    tagger = self.git_repo.default_signature
    try:
      self.git_repo.create_tag(
          name, commit.id, pygit2.GIT_OBJ_COMMIT, tagger, "")
      return Tag(name, commit)
    except ValueError as e:
      raise ValueError(
          str(e).replace('refs/tags/', '').replace('reference', 'tag'))
github douban / ellen / ellen / git / diff.py View on Github external
def get_commit_by_sha(repository, sha):
    try:
        commit = repository[sha]
    except (ValueError, KeyError, TypeError):
        raise JagareError("Commit '%s' is invalid." % sha)

    if commit and commit.type == GIT_OBJ_COMMIT:
        return commit
github seveas / goblet / goblet / views.py View on Github external
def lookup_ref(self, repo, ref):
        if not ref:
            return repo.head.target
        try:
            ref = repo.lookup_reference('refs/heads/' + ref).target.hex
        except (KeyError, ValueError):
            pass
        try:
            ref = repo.lookup_reference('refs/tags/' + ref).target.hex
        except (KeyError, ValueError):
            pass
        try:
            obj = repo[ref]
            if obj.type == pygit2.GIT_OBJ_TAG:
                obj = repo[obj.target]
            if obj.type != pygit2.GIT_OBJ_COMMIT:
                raise NotFound("No such commit/ref")
            return obj
        except (KeyError, ValueError):
            raise NotFound("No such commit/ref")
github douban / ellen / ellen / git / tag.py View on Github external
def create_tag(repository, name, ref, author_name, author_email, message):
    obj = repository.revparse_single(ref)
    if obj.type == GIT_OBJ_COMMIT:
        signature = Signature(author_name, author_email)
        oid = repository.create_tag(name, str(obj.id), GIT_OBJ_COMMIT,
                                    signature, message)
        return oid and str(oid)
    else:
        return None
github sdg-mit / gitless / gitless / core.py View on Github external
def checkout_file(self, path, commit):
    """Checkouts the given path at the given commit."""
    _check_path_is_repo_relative(path)

    git_path = _get_git_path(path)
    o = self.gl_repo.git_repo[commit.tree[git_path].id]
    assert o.type != pygit2.GIT_OBJ_COMMIT
    assert o.type != pygit2.GIT_OBJ_TAG

    if o.type == pygit2.GIT_OBJ_BLOB:
      full_path = os.path.join(self.gl_repo.root, path)
      dirname = os.path.dirname(full_path)
      if not os.path.exists(dirname):
        try:
          os.makedirs(dirname)
        except OSError as exc: # guard against race condition
          if exc.errno != errno.EEXIST:
            raise
      with io.open(full_path, mode='wb') as dst:
        dst.write(o.data)

      # So as to not get confused with the status of the file we also add it.
      # This prevents getting into a situation in which the staged version is
github douban / ellen / ellen / git / tree.py View on Github external
try:
        obj = repository.revparse_single(ref)
    except (ValueError, KeyError):
        raise JagareError("Reference not found.")

    commit_obj = None

    if obj.type == GIT_OBJ_TREE:
        tree_obj = obj
    elif obj.type == GIT_OBJ_TAG:
        commit_obj = repository.revparse_single(obj.target.hex)
        tree_obj = commit_obj.tree
    elif obj.type == GIT_OBJ_BLOB:
        raise JagareError("Object is blob, doesn't contain any tree")
    elif obj.type == GIT_OBJ_COMMIT:
        commit_obj = obj
        tree_obj = obj.tree

    if req_path:
        tree_entry = tree_obj[req_path]
        tree_obj = repository[tree_entry.id]
        walker = _walk_tree(tree_obj, req_path)
    else:
        walker = _walk_tree(tree_obj)

    ret_tree = {}
    submodule_obj = None
    submodule = None
    try:
        submodule_obj = repository.revparse_single("%s:.gitmodules" % ref)
        submodule = _parse_submodule(repository, submodule_obj)
github bendavis78 / python-gitmodel / gitmodel / workspace.py View on Github external
def create_branch(self, name, start_point=None):
        """
        Creates a head reference with the given name. The start_point argument
        is the head to which the new branch will point -- it may be a branch
        name, commit id, or tag name (defaults to current branch).
        """
        if not start_point:
            start_point = self.head
        start_point_ref = self.repo.lookup_reference(start_point)

        if start_point_ref.type != pygit2.GIT_OBJ_COMMIT:
            raise ValueError('Given reference must point to a commit')

        branch_ref = 'refs/heads/{}'.format(name)
        self.repo.create_reference(branch_ref, start_point_ref.target)