From d2bc634c373f86133b386af90eb931ee2ee59e02 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Thu, 30 Jun 2016 18:23:21 +0100 Subject: move Repository instantiation to GitUtils --- git_deps/detector.py | 13 +++++-------- git_deps/gitutils.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'git_deps') diff --git a/git_deps/detector.py b/git_deps/detector.py index 3f51f0e..3cb8828 100644 --- a/git_deps/detector.py +++ b/git_deps/detector.py @@ -20,20 +20,17 @@ class DependencyDetector(object): tree represented (conceptually) by a list of edges. """ - def __init__(self, options, repo_path=None, logger=None): + def __init__(self, options, repo=None, logger=None): self.options = options if logger is None: self.logger = standard_logger(self.__class__.__name__, options.debug) - if repo_path is None: - try: - repo_path = pygit2.discover_repository('.') - except KeyError: - abort("Couldn't find a repository in the current directory.") - - self.repo = pygit2.Repository(repo_path) + if repo is None: + self.repo = GitUtils.get_repo() + else: + self.repo = repo # Nested dict mapping dependents -> dependencies -> files # causing that dependency -> numbers of lines within that file diff --git a/git_deps/gitutils.py b/git_deps/gitutils.py index f349f44..f7b5470 100644 --- a/git_deps/gitutils.py +++ b/git_deps/gitutils.py @@ -3,6 +3,8 @@ import re import subprocess from git_deps.errors import InvalidCommitish +from git_deps.utils import abort + class GitUtils(object): @classmethod @@ -89,3 +91,11 @@ class GitUtils(object): return commit + @classmethod + def get_repo(cls, path='.'): + try: + repo_path = pygit2.discover_repository(path) + except KeyError: + abort("Couldn't find a repository in the current directory.") + + return pygit2.Repository(repo_path) -- cgit