def run(self, args): db = Db(self.get_pc_dir()) top = db.top_patch() if not top: self.exit_error("No patches applied.") print(top)
def __init__(self, cwd, quilt_pc, quilt_patches): super(Delete, self).__init__(cwd) self.quilt_pc = Directory(quilt_pc) self.quilt_patches = Directory(quilt_patches) self.db = Db(quilt_pc) self.series = Series(quilt_patches) self.pop = Pop(cwd, quilt_pc)
def run(self, args): series = Series(self.get_patches_dir()) if not series.exists(): self.exit_error("No series file found.") db = Db(self.get_pc_dir()) top = None if args.patch: patch_name = args.patch top = Patch(patch_name) else: if db.exists(): top = db.top_patch() if not top: top = series.first_patch() if not top: self.exit_error("No patch in series.") else: print(top) else: patch = series.patch_after(top) if not patch: self.exit_error("No patch available after %s." % top) else: print(patch)
def test_unreverted(self): """ Test when the patch modifies unreverted files """ with tmp_series() as [dir, series]: old_dir = os.getcwd() try: os.chdir(dir) db = Db(dir) db.add_patch(Patch("patch")) db.save() originals = os.path.join(db.dirname, "patch") os.mkdir(originals) make_file(b"unreverted original\n", originals, "unreverted") make_file(b"reverted original\n", originals, "reverted") make_file(b"unreverted patched\n", dir, "unreverted") make_file(b"reverted patched\n", dir, "reverted") Refresh(dir, db.dirname, series.dirname).refresh() make_file(b"unreverted change\n", dir, "unreverted") make_file(b"reverted change\n", dir, "reverted") cmd = quilt.revert.Revert(dir, db.dirname, series.dirname) cmd.revert_file("reverted") with open(os.path.join(dir, "reverted"), "rb") as file: self.assertEqual(file.read(), b"reverted patched\n") with open(os.path.join(dir, "unreverted"), "rb") as file: self.assertEqual(file.read(), b"unreverted change\n") finally: os.chdir(old_dir)
def run(self, args): db = Db(self.get_pc_dir()) top = db.top_patch() series = Series(self.get_patches_dir()) if top is None: patches = series.patches() else: patches = series.patches_after(top) for patch in patches: print(patch)
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 test_next_after(self): """ Delete the successor to the topmost patch """ with tmp_series() as [dir, series]: series.add_patch(Patch("topmost")) series.add_patch(Patch("unapplied")) series.save() db = Db(dir) db.add_patch(Patch("topmost")) db.save() cmd = Delete(dir, db.dirname, series.dirname) cmd.delete_next() series.read() [patch] = series.patches() self.assertEqual(patch, Patch("topmost"))
def test_series_v(self): with tmp_series() as [dir, series]: applied = Db(dir) applied.add_patch(Patch("applied.patch")) applied.add_patch(Patch("topmost.patch")) applied.save() series.add_patches(applied.applied_patches()) series.add_patch(Patch("unapplied.patch")) series.save() output = run_cli(SeriesCommand, dict(v=True), series.dirname, applied.dirname) self.assertMultiLineEqual(output, "+ applied.patch\n" "= topmost.patch\n" " unapplied.patch\n")
def run(self, args): series = Series(self.get_patches_dir()) if args.v: applied = Db(self.get_pc_dir()).patches() for patch in applied[:-1]: print("+ " + patch.get_name()) if applied: print("= " + applied[-1].get_name()) patches = series.patches_after(applied[-1]) else: patches = series.patches() for patch in patches: print(" " + patch.get_name()) else: for patch in series.patches(): print(patch.get_name())
def run(self, args): series = Series(self.get_patches_dir()) db = Db(self.get_pc_dir()) top = None if args.patch: top = Patch(args.patch) else: if db.exists(): top = db.top_patch() if not top: self.exit_error("No patches applied.") else: patch = series.patch_before(top) if not patch: self.exit_error("No patch available before %s." % top) else: print(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 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 __init__(self, cwd, quilt_pc): super(Pop, self).__init__(cwd) self.quilt_pc = Directory(quilt_pc) self.db = Db(quilt_pc)
def __init__(self, cwd, quilt_pc, quilt_patches): super(Revert, self).__init__(cwd) self.quilt_pc = Directory(quilt_pc) self.quilt_patches = Directory(quilt_patches) self.db = Db(quilt_pc) self.series = Series(quilt_patches)