From 5b9ee88fb3c1a56e749215c37f1aa65d886cd465 Mon Sep 17 00:00:00 2001
From: Chandrasekhar Ramakrishnan <chandrasekhar.ramakrishnan@id.ethz.ch>
Date: Thu, 2 Feb 2017 16:13:09 +0100
Subject: [PATCH] SSDM-4670: Initialze data repos as git and git-annex repos.

---
 src/python/OBis/obis/dm/data_mgmt.py      | 17 ++++++++++++++---
 src/python/OBis/obis/dm/data_mgmt_test.py | 10 +++++++---
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/python/OBis/obis/dm/data_mgmt.py b/src/python/OBis/obis/dm/data_mgmt.py
index abe89ceadca..c71bc541c32 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 1240523115c..920ae053008 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
-- 
GitLab