def test_is_commit_needed_no_change(): tmp = maketemp() repo = os.path.join(tmp, 'repo') os.mkdir(repo) commands.init_bare(repo) index = os.path.join(tmp, 'index') sha_foo = commands.write_object(repo=repo, content='FOO') commands.update_index( repo=repo, index=index, files=[ dict( object=sha_foo, path='quux/foo', ), ], ) tree = commands.write_tree( repo=repo, index=index, ) got = commands.is_commit_needed( repo=repo, tree=tree, parents=[], ) eq(got, True)
def test_is_commit_needed_has_change(): tmp = maketemp() commands.init_bare(tmp) commands.fast_import( repo=tmp, commits=[ dict( message='one', committer='John Doe <*****@*****.**>', commit_time='1216235872 +0300', files=[ dict( path='foo', content='FOO', ), ], ), ], ) head = commands.rev_parse(repo=tmp, rev='HEAD') tree = commands.rev_parse(repo=tmp, rev='HEAD^{tree}') got = commands.is_commit_needed( repo=tmp, tree='deadbeefdeadbeefdeadbeefdeadbeefdeadbeef', parents=[head], ) eq(got, True)
def test_is_commit_needed_no_change(): tmp = maketemp() repo = os.path.join(tmp, 'repo') os.mkdir(repo) commands.init_bare(repo) commands.fast_import( repo=tmp, commits=[ dict( message='one', committer='John Doe <*****@*****.**>', commit_time='1216235872 +0300', files=[ dict( path='foo', content='FOO', ), ], ), ], ) head = commands.rev_parse(repo=tmp, rev='HEAD') tree = commands.rev_parse(repo=tmp, rev='HEAD^{tree}') got = commands.is_commit_needed( repo=repo, tree=tree, parents=[head], ) eq(got, False)
def test_is_commit_needed_merge(): got = commands.is_commit_needed( repo='/does-not-exist', tree='deadbeefdeadbeefdeadbeefdeadbeefdeadbeef', parents=[ '1111111111111111111111111111111111111111', '2222222222222222222222222222222222222222', ], ) eq(got, True)
def test_is_commit_needed_root_empty(): tmp = maketemp() repo = os.path.join(tmp, 'repo') os.mkdir(repo) commands.init_bare(repo) index = os.path.join(tmp, 'index') tree = commands.write_tree( repo=repo, index=index, ) got = commands.is_commit_needed( repo=repo, tree=tree, parents=[], ) eq(got, False)
def __exit__(self, type_, value, traceback): ret = self.indexfs.__exit__(type_, value, traceback) assert not ret, \ "TemporaryIndexFS must not eat the exception." tree = self.indexfs.tree del self.indexfs if (type_ is None and value is None and traceback is None): # no exception -> commit transaction assert tree is not None, \ "TemporaryIndexFS must write the tree." parents = [] if self.original is not None: parents.append(self.original) if not commands.is_commit_needed( repo=self.repo.path, tree=tree, parents=parents, ): return self.commit = commands.commit_tree( repo=self.repo.path, tree=tree, parents=parents, message='pygitfs', committer_name='pygitfs', committer_email='pygitfs@invalid', ) try: commands.update_ref( repo=self.repo.path, ref=self.ref, newvalue=self.commit, oldvalue=self.original, reason='pygitfs transaction commit', ) except RuntimeError: # TODO this could be caused by pretty much anything # from OOM to invalid input, but as there's no way to # tell (with current git), we'll just assume it's # always caused by race condition.. raise TransactionRaceLostError()