diff --git a/src/python/OBis/obis/dm/data_mgmt.py b/src/python/OBis/obis/dm/data_mgmt.py index abe89ceadca719c606a2e4890d284ba0e63265fb..c71bc541c3215f57432af879e347c1ce5d8c8b5c 100644 --- a/src/python/OBis/obis/dm/data_mgmt.py +++ b/src/python/OBis/obis/dm/data_mgmt.py @@ -108,22 +108,27 @@ class AbstractDataMgmt(metaclass=abc.ABCMeta): raise ValueError(reason) @abc.abstractmethod - def init_data(self, path): + def init_data(self, path, desc=None): return class NoGitDataMgmt(AbstractDataMgmt): """DataMgmt operations when git is not available -- show error messages.""" - def init_data(self, path): + def init_data(self, path, desc=None): self.error_raise("init data", "No git command found.") class GitDataMgmt(AbstractDataMgmt): """DataMgmt operations in normal state.""" - def init_data(self, path): + def init_data(self, path, desc=None): + """Initialize a data repository at the path with the description.""" result = self.git_wrapper.git_init(path) + if result.returncode != 0: + self.error(result.output) + return result + result = self.git_wrapper.git_annex_init(path, desc) if result.returncode != 0: self.error(result.output) return result @@ -152,3 +157,9 @@ class GitWrapper(object): def git_init(self, path): return run_shell([self.git_path, "init", path]) + + def git_annex_init(self, path, desc): + cmd = [self.git_path, "-C", path, "annex", "init"] + if desc is not None: + cmd.append(desc) + return run_shell(cmd) diff --git a/src/python/OBis/obis/dm/data_mgmt_test.py b/src/python/OBis/obis/dm/data_mgmt_test.py index 1240523115c3e5e44d99b7ef8fe7dc9394051260..920ae053008780d71c153469dedd3a0e76c31ab6 100644 --- a/src/python/OBis/obis/dm/data_mgmt_test.py +++ b/src/python/OBis/obis/dm/data_mgmt_test.py @@ -15,7 +15,7 @@ from . import data_mgmt def test_no_git(tmpdir): dm = data_mgmt.DataMgmt() try: - dm.init_data(str(tmpdir)) + dm.init_data(str(tmpdir), "") assert False, "Command should have failed -- no git defined." except ValueError: pass @@ -31,13 +31,17 @@ def test_locate_command(): def test_normal_use_case(shared_dm, tmpdir): - # The folder should not be a git repo at first + # The folder should not be a git repo at first. result = data_mgmt.run_shell(['git', '-C', str(tmpdir), 'status', ]) assert result.returncode == 128 - result = shared_dm.init_data(str(tmpdir)) + result = shared_dm.init_data(str(tmpdir), "test") assert result.returncode == 0 # The folder should be a git repo now result = data_mgmt.run_shell(['git', '-C', str(tmpdir), 'status', str(tmpdir)]) assert result.returncode == 0 + + # ...and a git-annex repo as well. + result = data_mgmt.run_shell(['git', '-C', str(tmpdir), 'annex', 'status', str(tmpdir)]) + assert result.returncode == 0