Skip to content

Commit

Permalink
Database: Do not open worktree if GIT is desactivated
Browse files Browse the repository at this point in the history
  • Loading branch information
M3te0r committed Dec 16, 2021
1 parent 9b75f23 commit 1915250
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions itools/database/backends/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -340,26 +343,25 @@ 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):
worktree = self.worktree
# 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')
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1915250

Please sign in to comment.