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.assertEquals(None, push.db.top_patch()) push.apply_next_patch(quiet=True) self.assertEquals(patch1, push.db.top_patch()) self.assertTrue(f1.exists()) self.assertFalse(f2.exists()) push.apply_next_patch(quiet=True) self.assertEquals(patch2, push.db.top_patch()) self.assertTrue(f1.exists()) self.assertTrue(f2.exists())
def test_apply_all(self): 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 + "test1" 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_all(quiet=True) self.assertEqual(patch2, push.db.top_patch()) self.assertTrue(f1.exists()) self.assertTrue(f2.exists())
def _push(force=False, quiet=True): push = Push(os.getcwd(), pc_dir, patches_dir) try: push.apply_all(force, quiet) except AllPatchesApplied: print t.green('OK: Patches already Applied') return 0 except QuiltError, e: print t.red('KO: Error applying patch:' + str(e)) return -1
def push(self): """ Apply next patch """ from quilt.push import Push from quilt.error import NoPatchesInSeries, AllPatchesApplied push = Push(self.work_dir, os.path.join(self.work_dir, ".pc"), self.patch_dir) try: push.apply_next_patch() except NoPatchesInSeries, e: print e
def apply(self): """ Apply all patches """ from quilt.push import Push from quilt.error import NoPatchesInSeries, AllPatchesApplied self.log.debug("applying patches of %s in %s" % (self.patch_dir, self.work_dir)) push = Push(self.work_dir, os.path.join(self.work_dir, ".pc"), self.patch_dir) try: push.apply_all() except NoPatchesInSeries, e: print e
def test_upto_applied(self): """ Push up to a specified patch when a patch is already applied """ top = os.path.join(test_dir, "data", "pop", "test1") pc = os.path.join(top, "pc") patches = os.path.join(top, "patches") cmd = Push(top, pc, patches) self.assertRaises(AllPatchesApplied, cmd.apply_patch, "p1.patch")
def run(self, args): push = Push(self.get_cwd(), self.get_pc_dir(), self.get_patches_dir()) push.applying_patch.connect(self.applying_patch) push.applied.connect(self.applied) push.applied_empty_patch.connect(self.applied_empty_patch) if args.all: push.apply_all(args.force) elif args.patch: push.apply_patch(args.patch, args.force) else: push.apply_next_patch(args.force)
def run(self, options, args): push = Push(self.get_cwd(), self.get_pc_dir(), self.get_patches_dir()) push.applying_patch.connect(self.applying_patch) push.applied.connect(self.applied) push.applied_empty_patch.connect(self.applied_empty_patch) if options.all: push.apply_all(options.force) elif not args: push.apply_next_patch(options.force) else: push.apply_patch(args[0], options.force)
def test_fail_after_success(self): """ Test where the first patch applies but a later patch fails """ with tmp_series() as [dir, series]: make_file( b"--- /dev/null\n" b"+++ dir/new-file\n" b"@@ -0,0 +1,1 @@\n" b"+new file\n", series.dirname, "good.patch") series.add_patch(Patch("good.patch")) self._make_conflict(dir, series) series.save() cmd = Push(dir, quilt_pc=dir, quilt_patches=series.dirname) with six.assertRaisesRegex(self, QuiltError, r"conflict\.patch does not apply"), \ self._suppress_output(): cmd.apply_all() [applied] = Db(dir).patches() self.assertEqual(applied.get_name(), "good.patch") with open(os.path.join(dir, "new-file"), "rb") as file: self.assertEqual(file.read(), b"new file\n") with open(os.path.join(dir, "file"), "rb") as file: self.assertEqual(file.read(), b"conflict\n")
def test_force(self): with tmp_series() as [dir, series]: self._make_conflict(dir, series) series.save() cmd = Push(dir, quilt_pc=dir, quilt_patches=series.dirname) with six.assertRaisesRegex( self, QuiltError, r"does not apply"), \ self._suppress_output(): cmd.apply_next_patch(quiet=True) with six.assertRaisesRegex(self, QuiltError, r"Applied patch.*needs refresh"), \ self._suppress_output(): cmd.apply_next_patch(quiet=True, force=True)