diff options
Diffstat (limited to 'git_deps')
-rw-r--r-- | git_deps/detector.py | 8 | ||||
-rw-r--r-- | git_deps/gitutils.py | 15 |
2 files changed, 16 insertions, 7 deletions
diff --git a/git_deps/detector.py b/git_deps/detector.py index beeb221..3f51f0e 100644 --- a/git_deps/detector.py +++ b/git_deps/detector.py @@ -80,13 +80,7 @@ class DependencyDetector(object): if rev in self.commits: return self.commits[rev] - try: - commit = self.repo.revparse_single(rev) - if isinstance(commit, pygit2.Tag): - commit = commit.get_object() - self.commits[rev] = commit - except (KeyError, ValueError): - raise InvalidCommitish(rev) + self.commits[rev] = GitUtils.ref_commit(self.repo, rev) return self.commits[rev] diff --git a/git_deps/gitutils.py b/git_deps/gitutils.py index d5981d2..f349f44 100644 --- a/git_deps/gitutils.py +++ b/git_deps/gitutils.py @@ -1,6 +1,8 @@ +import pygit2 import re import subprocess +from git_deps.errors import InvalidCommitish class GitUtils(object): @classmethod @@ -74,3 +76,16 @@ class GitUtils(object): def rev_list(cls, rev_range): cmd = ['git', 'rev-list', rev_range] return subprocess.check_output(cmd).strip().split('\n') + + @classmethod + def ref_commit(cls, repo, rev): + try: + commit = repo.revparse_single(rev) + except (KeyError, ValueError): + raise InvalidCommitish(rev) + + if isinstance(commit, pygit2.Tag): + commit = commit.get_object() + + return commit + |