From 6d46d2bced3db27144564cfe8fe2326d69b15fee Mon Sep 17 00:00:00 2001 From: Yves Noirjean <yves.noirjean@id.ethz.ch> Date: Wed, 15 Aug 2018 18:44:20 +0200 Subject: [PATCH] SSDM-6987: obis - storing git attributes in .git/info/attributes instead of .gitattributes --- obis/src/python/obis/dm/checksum.py | 2 +- obis/src/python/obis/dm/data_mgmt.py | 3 +++ obis/src/python/obis/dm/git.py | 22 +++++++++++++++------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/obis/src/python/obis/dm/checksum.py b/obis/src/python/obis/dm/checksum.py index e809b48315f..2df5356dc4b 100644 --- a/obis/src/python/obis/dm/checksum.py +++ b/obis/src/python/obis/dm/checksum.py @@ -144,7 +144,7 @@ class ChecksumGeneratorGitAnnex(object): raise ValueError("Git annex backend not supported: " + self.backend) def _get_annex_backend(self): - with open('.gitattributes') as gitattributes: + with open('.git/info/attributes') as gitattributes: for line in gitattributes.readlines(): if 'annex.backend' in line: backend = line.split('=')[1].strip() diff --git a/obis/src/python/obis/dm/data_mgmt.py b/obis/src/python/obis/dm/data_mgmt.py index 339bb2f40b8..5c54b14b3ad 100644 --- a/obis/src/python/obis/dm/data_mgmt.py +++ b/obis/src/python/obis/dm/data_mgmt.py @@ -283,6 +283,9 @@ class GitDataMgmt(AbstractDataMgmt): if result.failure(): return result with cd(path): + result = self.git_wrapper.initial_commit() + if result.failure(): + return result # Update the resolvers location self.settings_resolver.set_resolver_location_roots('data_set', '.') self.settings_resolver.copy_global_to_local() diff --git a/obis/src/python/obis/dm/git.py b/obis/src/python/obis/dm/git.py index 43261db427a..32a5b670283 100644 --- a/obis/src/python/obis/dm/git.py +++ b/obis/src/python/obis/dm/git.py @@ -1,5 +1,6 @@ import shutil import os +from pathlib import Path from .utils import run_shell from .command_result import CommandResult, CommandException from .checksum import ChecksumGeneratorCrc32, ChecksumGeneratorGitAnnex @@ -63,18 +64,25 @@ class GitWrapper(object): return result attributes_src = os.path.join(os.path.dirname(__file__), "git-annex-attributes") - attributes_dst = os.path.join(path, ".gitattributes") + attributes_dst = os.path.join(path, ".git/info/attributes") shutil.copyfile(attributes_src, attributes_dst) self._apply_git_annex_backend(attributes_dst, git_annex_backend) - cmd = [self.git_path, "-C", path, "add", ".gitattributes"] - result = run_shell(cmd) - if result.failure(): - return result - cmd = [self.git_path, "-C", path, "commit", "-m", "Initial commit."] - result = run_shell(cmd) return result + def initial_commit(self): + # initial commit is needed. we can restore to it when something fails + folder = '.obis' + file = '.gitignore' + path = folder + '/' + file + if not os.path.exists(folder): + os.makedirs(folder) + Path(path).touch() + result = self.git_add(path) + if result.failure(): + return result + return self.git_commit("Initial commit.") + def _apply_git_annex_backend(self, filename, git_annex_backend): if git_annex_backend is not None: lines = [] -- GitLab