def test_generate_patches(self): """Test generation of patches""" class opts: patch_numbers = False # Add test file with topic: msg = ("added foo\n\n" "Gbp-Pq-Topic: gbptest") self.add_file('foo', 'foo', msg) # Write it out as patch and check it's existence d = context.new_tmpdir(__name__) patchfile = generate_patches(self.repo, 'HEAD^', 'HEAD', str(d), opts)[0] expected = os.path.join(str(d), 'gbptest', 'added-foo.patch') self.assertTrue(os.path.exists(expected)) logging.debug(file(expected).read()) # Reapply the patch to a new branch self.repo.create_branch('testapply', 'HEAD^') self.repo.set_branch('testapply') self.repo.apply_patch(expected) self.repo.commit_all("foo") diff = self.repo.diff('master', 'testapply') # Branches must be identical afterwards self.assertEqual('', diff)
def _test_generate_patches(self, changes, expected_patches, opts): self.assertEqual(len(changes), len(expected_patches)) d = context.new_tmpdir(__name__) expected_paths = [os.path.join(str(d), n) for n in expected_patches ] # Commit changes for c in changes: self.add_file(c[0], c[1], c[2]) # Write it out as patch and check its existence origin = 'HEAD~%d' % len(changes) patchfiles = generate_patches(self.repo, origin, 'HEAD', str(d), opts) for expected in expected_paths: self.assertIn(expected, patchfiles) self.assertTrue(os.path.exists(expected)) # Reapply the patch to a new branch self.repo.create_branch('testapply', origin) self.repo.set_branch('testapply') for expected in expected_paths: self.repo.apply_patch(expected) self.repo.commit_all("foo") diff = self.repo.diff('master', 'testapply') # Branches must be identical afterwards self.assertEqual('', diff)