From d6b1a9272455ef80f01a48ea22efc85b7f976503 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 25 Sep 2016 17:10:38 +0200 Subject: fix(index): improve LockedFD handling Relying on the destructor will not work, even though the code used to rely on it. Now we handle failures more explicitly. Far from perfect, but a good start for a fix. Fixes #514 --- git/test/test_index.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'git/test/test_index.py') diff --git a/git/test/test_index.py b/git/test/test_index.py index ca877838..bce56089 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -135,6 +135,23 @@ class TestIndex(TestBase): raise AssertionError("CMP Failed: Missing entries in index: %s, missing in tree: %s" % (bset - iset, iset - bset)) # END assertion message + + @with_rw_repo('0.1.6') + def test_index_lock_handling(self, rw_repo): + def add_bad_blob(): + rw_repo.index.add([Blob(rw_repo, b'f' * 20, 'bad-permissions', 'foo')]) + + try: + ## 1st fail on purpose adding into index. + add_bad_blob() + except Exception as ex: + assert "cannot convert argument to integer" in str(ex) + + ## 2nd time should not fail due to stray lock file + try: + add_bad_blob() + except Exception as ex: + assert "index.lock' could not be obtained" not in str(ex) @with_rw_repo('0.1.6') def test_index_file_from_tree(self, rw_repo): -- cgit v1.2.1