diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1461,6 +1461,13 @@ # dirstate is invalidated separately in invalidatedirstate() if k == 'dirstate': continue + if (k == 'changelog' and + self.currenttransaction() and + self.changelog._delayed): + # The changelog object may store unwritten revisions. We don't + # want to lose them. + # TODO: Solve the problem instead of working around it. + continue if clearfilecache: del self._filecache[k] diff --git a/tests/test-context.py b/tests/test-context.py --- a/tests/test-context.py +++ b/tests/test-context.py @@ -179,3 +179,14 @@ print('data mismatch') except Exception as ex: print('cannot read data: %r' % ex) + +with repo.wlock(), repo.lock(), repo.transaction('test'): + with open(b'4', 'wb') as f: + f.write(b'4') + repo.dirstate.normal('4') + repo.commit('4') + revsbefore = len(repo.changelog) + repo.invalidate(clearfilecache=True) + revsafter = len(repo.changelog) + if revsbefore != revsafter: + print('changeset lost by repo.invalidate()')