# HG changeset patch # User Marcin Kuzminski # Date 2019-07-11 15:31:52 # Node ID 28a01042012caaee9ad304c67a964bc8715d0d3a # Parent f20a643085c5081d91c9d6f68178df576117c2fe libgit2: check for dangling commits in get_object method diff --git a/vcsserver/git.py b/vcsserver/git.py --- a/vcsserver/git.py +++ b/vcsserver/git.py @@ -600,15 +600,20 @@ class GitRemote(object): def get_object(self, wire, sha): repo = self._factory.repo_libgit2(wire) + missing_commit_err = 'Commit {} does not exist for `{}`'.format(sha, wire['path']) try: commit = repo.revparse_single(sha) except (KeyError, ValueError) as e: - msg = 'Commit {} does not exist for `{}`'.format(sha, wire['path']) - raise exceptions.LookupException(e)(msg) + raise exceptions.LookupException(e)(missing_commit_err) if isinstance(commit, pygit2.Tag): commit = repo.get(commit.target) + # check for dangling commit + branches = [x for x in repo.branches.with_commit(commit.hex)] + if not branches: + raise exceptions.LookupException(None)(missing_commit_err) + commit_id = commit.hex type_id = commit.type