summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2019-11-17 17:21:21 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2019-11-17 17:21:21 +0100
commit7ba444312d85af03aa67875ec028d1ac3beafd80 (patch)
tree0337f7f70d33630613e79b047fb53cd4686528df
parentf9756feaffb808b904eab2ba177c42d121ccda48 (diff)
Remove files from git when deleting entries
-rw-r--r--lesana/collection.py15
-rw-r--r--tests/test_collection.py2
2 files changed, 15 insertions, 2 deletions
diff --git a/lesana/collection.py b/lesana/collection.py
index 457b732..4626a7a 100644
--- a/lesana/collection.py
+++ b/lesana/collection.py
@@ -424,12 +424,25 @@ class Collection(object):
for entry in self.entries_from_short_uid(uid):
if entry is not None:
cache.delete_document(entry.idterm)
- os.remove(os.path.join(self.itemdir, entry.fname))
+ self.remove_file(entry.fname)
else:
logging.warning("No such entry: {}, ignoring".format(uid))
cache.commit()
cache.close()
+ def remove_file(self, fname):
+ f_path = os.path.join(self.itemdir, fname)
+ if git_available and self.settings.get('git', False):
+ try:
+ repo = git.Repo(self.basedir, search_parent_directories=True)
+ except git.exc.InvalidGitRepositoryError as e:
+ logging.warning(
+ "Could not find a git repository in {}".format(
+ self.basedir))
+ return False
+ repo.index.remove([f_path])
+ os.remove(f_path)
+
def get_template(self, template_fname, searchpath='.'):
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(
diff --git a/tests/test_collection.py b/tests/test_collection.py
index ab6d807..74f3792 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -412,7 +412,7 @@ class testCollectionCreation(unittest.TestCase):
mset = collection._enquire.get_mset(0, 10)
self.assertEqual(mset.get_matches_estimated(), 0)
- def test_partial_deletion(self):
+ def test_partial_uid_deletion(self):
tmpdir = tempfile.mkdtemp()
shutil.copy('tests/data/simple/settings.yaml', tmpdir)
shutil.copytree(