diff options
Diffstat (limited to 'git')
| -rw-r--r-- | git/index/base.py | 14 | ||||
| -rw-r--r-- | git/remote.py | 2 | ||||
| -rw-r--r-- | git/test/test_index.py | 19 | ||||
| -rw-r--r-- | git/test/test_repo.py | 1 |
4 files changed, 33 insertions, 3 deletions
diff --git a/git/index/base.py b/git/index/base.py index 524b4568..86eda41e 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -118,13 +118,17 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # read the current index # try memory map for speed lfd = LockedFD(self._file_path) + ok = False try: fd = lfd.open(write=False, stream=False) + ok = True except OSError: - lfd.rollback() # in new repositories, there may be no index, which means we are empty self.entries = dict() return + finally: + if not ok: + lfd.rollback() # END exception handling # Here it comes: on windows in python 2.5, memory maps aren't closed properly @@ -209,8 +213,14 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): self.entries lfd = LockedFD(file_path or self._file_path) stream = lfd.open(write=True, stream=True) + ok = False - self._serialize(stream, ignore_extension_data) + try: + self._serialize(stream, ignore_extension_data) + ok = True + finally: + if not ok: + lfd.rollback() lfd.commit() diff --git a/git/remote.py b/git/remote.py index 12129460..4a8a5ee9 100644 --- a/git/remote.py +++ b/git/remote.py @@ -445,7 +445,7 @@ class Remote(LazyMixin, Iterable): def iter_items(cls, repo): """:return: Iterator yielding Remote objects of the given repository""" for section in repo.config_reader("repository").sections(): - if not section.startswith('remote'): + if not section.startswith('remote '): continue lbound = section.find('"') rbound = section.rfind('"') diff --git a/git/test/test_index.py b/git/test/test_index.py index ca877838..178a59d2 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -135,6 +135,25 @@ 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: + msg_py3 = "required argument is not an integer" + msg_py2 = "cannot convert argument to integer" + assert msg_py2 in str(ex) or msg_py3 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): diff --git a/git/test/test_repo.py b/git/test/test_repo.py index e24062c1..d04a0f66 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -115,6 +115,7 @@ class TestRepo(TestBase): assert commit.type == 'commit' assert self.rorepo.commit(commit) == commit + def test_commits(self): mc = 10 commits = list(self.rorepo.iter_commits('0.1.6', max_count=mc)) assert len(commits) == mc |
