aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Spiers <git@adamspiers.org>2016-06-30 18:23:21 +0100
committerAdam Spiers <git@adamspiers.org>2018-05-15 13:42:16 +0100
commitd2bc634c373f86133b386af90eb931ee2ee59e02 (patch)
tree7023de4d2d1d7846fcb7132105dbee33102d6919
parent4a5d64215075502e79d2a0b35c3a18a10d68c8fd (diff)
downloadgit-deps-d2bc634c373f86133b386af90eb931ee2ee59e02.tar.gz
move Repository instantiation to GitUtils
-rw-r--r--git_deps/detector.py13
-rw-r--r--git_deps/gitutils.py10
2 files changed, 15 insertions, 8 deletions
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)