def test_apply_next(self): patch1 = Patch("p1.patch") patch2 = Patch("p2.patch") test_dir = self.data_dir + "test1" with TmpDirectory(dir=self.data_dir.get_name()) as tmp_dir: tmp_test_dir = tmp_dir + "test2" test_dir.copy(tmp_test_dir) pc_dir = tmp_test_dir + "pc" f1 = tmp_test_dir + File("f1") self.assertTrue(f1.exists()) f2 = tmp_test_dir + File("f2") self.assertTrue(f2.exists()) pop = Pop(tmp_test_dir.get_name(), pc_dir.get_name()) self.assertEqual(patch2, pop.db.top_patch()) pop.unapply_top_patch() self.assertEqual(patch1, pop.db.top_patch()) self.assertTrue(f1.exists()) self.assertFalse(f2.exists()) pop.unapply_top_patch() self.assertEqual(None, pop.db.top_patch()) self.assertFalse(f1.exists()) self.assertFalse(f2.exists())
def test_apply_next(self): patch1 = Patch("p1.patch") patch2 = Patch("p2.patch") test_dir = self.data_dir + "test2" with TmpDirectory(dir=self.data_dir.get_name()) as tmp_dir: tmp_test_dir = tmp_dir + "test2" test_dir.copy(tmp_test_dir) pc_dir = tmp_test_dir + "pc" patches_dir = tmp_test_dir + "patches" f1 = tmp_test_dir + File("f1") self.assertFalse(f1.exists()) f2 = tmp_test_dir + File("f2") self.assertFalse(f2.exists()) push = Push(tmp_test_dir.get_name(), pc_dir.get_name(), patches_dir.get_name()) self.assertEqual(None, push.db.top_patch()) push.apply_next_patch(quiet=True) self.assertEqual(patch1, push.db.top_patch()) self.assertTrue(f1.exists()) self.assertFalse(f2.exists()) push.apply_next_patch(quiet=True) self.assertEqual(patch2, push.db.top_patch()) self.assertTrue(f1.exists()) self.assertTrue(f2.exists())
def test_unrefreshed(self): with TmpDirectory() as dir: db = Db(dir.get_name()) db.add_patch(Patch("unrefreshed.patch")) db.save() make_file(b"", db.dirname, "unrefreshed.patch~refresh") cmd = Pop(dir.get_name(), db.dirname) with six.assertRaisesRegex(self, QuiltError, r"needs to be refreshed"): cmd.unapply_top_patch()
def revert_file(self, filename, patch_name=None): """ Revert not added changes of filename. If patch_name is None or empty the topmost patch will be used. """ file = File(filename) if patch_name: patch = Patch(patch_name) else: patch = self.db.top_patch() if not patch: raise QuiltError("No patch available. Nothing to revert.") self._file_in_patch(filename, patch) self._file_in_next_patches(filename, patch) pc_dir = self.quilt_pc + patch.get_name() pc_file = pc_dir + file if not file.exists() and pc_file.is_empty(): # new and empty file will be reverted pc_file.delete() self.file_reverted(file, patch) return with TmpDirectory(prefix="pquilt-") as tmpdir: # apply current patch in temporary directory to revert changes of # file that aren't committed in the patch tmp_file = self._apply_patch_temporary(tmpdir, pc_file, patch) if tmp_file and tmp_file.exists() and not tmp_file.is_empty(): diff = Diff(file, tmp_file) if diff.equal(self.cwd): self.file_unchanged(file, patch) return dir = file.get_directory() if not dir: dir = Directory(os.getcwd()) else: dir.create() tmp_file.copy(dir) self.file_reverted(file, patch) else: self.file_unchanged(file, patch)
def test_refresh(self): with TmpDirectory() as dir: old_dir = os.getcwd() try: os.chdir(dir.get_name()) db = Db(".pc") db.create() backup = os.path.join(".pc", "patch") os.mkdir(backup) make_file(b"", backup, "file") db.add_patch(Patch("patch")) db.save() make_file(b"", "patch") make_file(b"added\n", "file") cmd = quilt.refresh.Refresh(".", ".pc", ".") cmd.refresh() with open("patch", "r") as patch: self.assertTrue(patch.read(30)) finally: os.chdir(old_dir)
def tmp_series(): with TmpDirectory() as dir: patches = os.path.join(dir.get_name(), "patches") os.mkdir(patches) yield (dir.get_name(), Series(patches))
def test_version(self): version = "234\n" self.assertTrue(version.startswith(format(DB_VERSION))) with TmpDirectory() as dir: make_file(version.encode("ascii"), dir.get_name(), ".version") self.assertRaises(DBError, Db, dir.get_name())