diff options
-rw-r--r-- | lesana/collection.py | 15 | ||||
-rw-r--r-- | tests/test_collection.py | 2 |
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( |