From 19152502e8b363cef5ba2634c72d9f49ba264831 Mon Sep 17 00:00:00 2001 From: "mathieu.pequin" Date: Thu, 16 Dec 2021 10:03:11 +0100 Subject: [PATCH] Database: Do not open worktree if GIT is desactivated --- itools/database/backends/git.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/itools/database/backends/git.py b/itools/database/backends/git.py index 112516d90..71645f8c7 100644 --- a/itools/database/backends/git.py +++ b/itools/database/backends/git.py @@ -109,7 +109,10 @@ def __init__(self, path, fields, read_only=False): error = '"{0}" should be a folder, but it is not'.format(self.path_data) raise ValueError(error) # New interface to Git - self.worktree = open_worktree(self.path_data) + if TEST_DB_DESACTIVATE_GIT is True: + self.worktree = None + else: + self.worktree = open_worktree(self.path_data) # Initialize the database, but chrooted self.fs = lfs.open(self.path_data) # Static FS @@ -340,9 +343,8 @@ def do_git_big_commit(self): def _do_git_big_commit(self): - worktree = self.worktree - worktree._call(['git', 'add', '-A']) - worktree._call(['git', 'commit', '-m', 'Autocommit']) + self.worktree._call(['git', 'add', '-A']) + self.worktree._call(['git', 'commit', '-m', 'Autocommit']) def do_git_transaction(self, commit_message, data, added, changed, removed, handlers): @@ -350,16 +352,16 @@ def do_git_transaction(self, commit_message, data, added, changed, removed, hand # 3. Git add git_add = list(added) + list(changed) git_add = [x for x in git_add if x.endswith('metadata')] - worktree.git_add(*git_add) + self.worktree.git_add(*git_add) # 3. Git rm git_rm = list(removed) git_rm = [x for x in git_rm if x.endswith('metadata')] - worktree.git_rm(*git_rm) + self.worktree.git_rm(*git_rm) # 2. Build the 'git commit' command git_author, git_date, git_msg, docs_to_index, docs_to_unindex = data git_msg = git_msg or 'no comment' # 4. Create the tree - repo = worktree.repo + repo = self.worktree.repo index = repo.index try: head = repo.revparse_single('HEAD') @@ -419,7 +421,7 @@ def do_git_transaction(self, commit_message, data, added, changed, removed, hand else: tb.insert(name, value[0], value[1]) # 5. Git commit - worktree.git_commit(git_msg, git_author, git_date, tree=git_tree) + self.worktree.git_commit(git_msg, git_author, git_date, tree=git_tree) def abort_transaction(self):