diff --git a/kas/config.py b/kas/config.py index 2ffa8b0..5e8cdd6 100644 --- a/kas/config.py +++ b/kas/config.py @@ -199,16 +199,12 @@ class Config: name) url = path - rep = Repo(url=url, - path=path, - layers=layers) + rep = Repo.factory(url=url, path=path, layers=layers) rep.disable_operations() else: path = path or os.path.join(self.kas_work_dir, name) - rep = Repo(url=url, - path=path, - refspec=refspec, - layers=layers) + rep = Repo.factory(url=url, path=path, refspec=refspec, + layers=layers) repo_dict[repo] = rep return repo_dict diff --git a/kas/repos.py b/kas/repos.py index 4e4e3b7..02910f7 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -38,7 +38,7 @@ class Repo: Represents a repository in the kas configuration. """ - def __init__(self, url, path, refspec=None, layers=None): + def __init__(self, url, path, refspec, layers): self.url = url self.path = path self.refspec = refspec @@ -73,6 +73,36 @@ class Repo: return '%s:%s %s %s' % (self.url, self.refspec, self.path, self._layers) + @staticmethod + def factory(url, path, refspec=None, layers=None): + """ + Return an instance Repo depending on params. + """ + return GitRepo(url, path, refspec, layers) + + @staticmethod + def get_root_path(path, environ): + """ + Check if path is a version control repo and return its root path. + """ + (ret, output) = run_cmd(['git', + 'rev-parse', + '--show-toplevel'], + cwd=path, + env=environ, + fail=False, + liveupdate=False) + if ret == 0: + return output.strip() + + return path + + +class GitRepo(Repo): + """ + Provides the git implementations for a Repo. + """ + @asyncio.coroutine def fetch_async(self, config): """ @@ -155,20 +185,3 @@ class Repo: run_cmd(['git', 'checkout', '-q', '{refspec}'.format(refspec=self.refspec)], cwd=self.path) - - @staticmethod - def get_root_path(path, environ): - """ - Check if path is a version control repo and return its root path. - """ - (ret, output) = run_cmd(['git', - 'rev-parse', - '--show-toplevel'], - cwd=path, - env=environ, - fail=False, - liveupdate=False) - if ret == 0: - return output.strip() - - return path