def test_debian_missing_author(self): """ Check if we parse the author from debian control if it's missing in the patch. """ def _check_log(msg): self.assertEqual(msg, "Patch 'foo.patch' has no authorship " "information, using 'Guido Günther <*****@*****.**>'") patch = gbp.patch_series.Patch(_patch_path('foo.patch')) # Overwrite data parsed from patch: patch.author patch.info['author'] = None patch.info['email'] = None # Fake a control file self.add_file("debian/control", "Maintainer: Guido Günther <*****@*****.**>") maintainer = pq.get_maintainer_from_control(self.repo) orig_warn = gbp.log.warn gbp.log.warn = _check_log pq.apply_and_commit_patch(self.repo, patch, maintainer) gbp.log.warn = orig_warn info = self.repo.get_commit_info('HEAD') self.assertEqual(info['author'].email, '*****@*****.**') self.assertIn('foo', self.repo.list_files())
def main(argv): retval = 0 (options, args) = parse_args(argv) if not options: return ExitCodes.parse_error gbp.log.setup(options.color, options.verbose, options.color_scheme) if len(args) < 2: gbp.log.err("No action given.") return 1 else: action = args[1] if args[1] in ["export", "import", "rebase", "drop", "switch"]: pass elif args[1] in ["apply"]: if len(args) != 3: gbp.log.err("No patch name given.") return 1 else: patchfile = args[2] else: gbp.log.err("Unknown action '%s'." % args[1]) return 1 try: repo = DebianGitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: current = repo.get_branch() if action == "export": export_patches(repo, current, options) elif action == "import": import_pq(repo, current, options) elif action == "drop": drop_pq(repo, current) elif action == "rebase": rebase_pq(repo, current, options) elif action == "apply": patch = Patch(patchfile) maintainer = get_maintainer_from_control(repo) apply_single_patch(repo, current, patch, maintainer, options.topic) elif action == "switch": switch_pq(repo, current, options) except KeyboardInterrupt: retval = 1 gbp.log.err("Interrupted. Aborting.") except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if str(err): gbp.log.err(err) retval = 1 return retval
def main(argv): retval = 0 (options, args) = parse_args(argv) if not options: return 1 gbp.log.setup(options.color, options.verbose, options.color_scheme) if len(args) < 2: gbp.log.err("No action given.") return 1 else: action = args[1] if args[1] in ["export", "import", "rebase", "drop", "switch"]: pass elif args[1] in ["apply"]: if len(args) != 3: gbp.log.err("No patch name given.") return 1 else: patchfile = args[2] else: gbp.log.err("Unknown action '%s'." % args[1]) return 1 try: repo = GitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: current = repo.get_branch() if action == "export": export_patches(repo, current, options) elif action == "import": series = SERIES_FILE tries = options.time_machine if (options.time_machine > 0) else 1 import_quilt_patches(repo, current, series, tries, options.force) current = repo.get_branch() gbp.log.info("Patches listed in '%s' imported on '%s'" % (series, current)) elif action == "drop": drop_pq(repo, current) elif action == "rebase": rebase_pq(repo, current) elif action == "apply": patch = Patch(patchfile) maintainer = get_maintainer_from_control(repo) apply_single_patch(repo, current, patch, maintainer, options.topic) elif action == "switch": switch_pq(repo, current) except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if len(err.__str__()): gbp.log.err(err) retval = 1 return retval
def import_quilt_patches(repo, branch, series, tries, force): """ apply a series of quilt patches in the series file 'series' to branch the patch-queue branch for 'branch' @param repo: git repository to work on @param branch: branch to base pqtch queue on @param series; series file to read patches from @param tries: try that many times to apply the patches going back one commit in the branches history after each failure. @param force: import the patch series even if the branch already exists """ tmpdir = None if is_pq_branch(branch): if force: branch = pq_branch_base(branch) pq_branch = pq_branch_name(branch) repo.checkout(branch) else: gbp.log.err("Already on a patch-queue branch '%s' - doing nothing." % branch) raise GbpError else: pq_branch = pq_branch_name(branch) if repo.has_branch(pq_branch): if force: drop_pq(repo, branch) else: raise GbpError("Patch queue branch '%s'. already exists. Try 'rebase' instead." % pq_branch) maintainer = get_maintainer_from_control(repo) commits = repo.get_commits(num=tries, first_parent=True) # If we go back in history we have to safe our pq so we always try to apply # the latest one if len(commits) > 1: tmpdir, series = safe_patches(series) queue = PatchSeries.read_series_file(series) i = len(commits) for commit in commits: if len(commits) > 1: gbp.log.info("%d %s left" % (i, 'tries' if i > 1 else 'try')) try: gbp.log.info("Trying to apply patches at '%s'" % commit) repo.create_branch(pq_branch, commit) except GitRepositoryError: raise GbpError("Cannot create patch-queue branch '%s'." % pq_branch) repo.set_branch(pq_branch) for patch in queue: gbp.log.debug("Applying %s" % patch.path) try: apply_and_commit_patch(repo, patch, maintainer, patch.topic) except (GbpError, GitRepositoryError): gbp.log.err("Failed to apply '%s'" % patch.path) repo.set_branch(branch) repo.delete_branch(pq_branch) break else: # All patches applied successfully break i-=1 else: raise GbpError("Couldn't apply patches") if tmpdir: gbp.log.debug("Remove temporary patch safe '%s'" % tmpdir) shutil.rmtree(tmpdir)
def import_quilt_patches(repo, branch, series, tries, force, pq_from, upstream_tag): """ apply a series of quilt patches in the series file 'series' to branch the patch-queue branch for 'branch' @param repo: git repository to work on @param branch: branch to base patch queue on @param series: series file to read patches from @param tries: try that many times to apply the patches going back one commit in the branches history after each failure. @param force: import the patch series even if the branch already exists @param pq_from: what to use as the starting point for the pq branch. DEBIAN indicates the current branch, TAG indicates that the corresponding upstream tag should be used. @param upstream_tag: upstream tag template to use """ tmpdir = None series = os.path.join(repo.path, series) if is_pq_branch(branch): if force: branch = pq_branch_base(branch) pq_branch = pq_branch_name(branch) repo.checkout(branch) else: raise GbpError("Already on a patch-queue branch '%s' - doing nothing." % branch) else: pq_branch = pq_branch_name(branch) if repo.has_branch(pq_branch): if force: drop_pq(repo, branch) else: raise GbpError("Patch queue branch '%s'. already exists. Try 'rebase' or 'switch' instead." % pq_branch) maintainer = get_maintainer_from_control(repo) if pq_on_upstream_tag(pq_from): commits = [find_upstream_commit(repo, branch, upstream_tag)] else: # pq_from == 'DEBIAN' commits = repo.get_commits(num=tries, first_parent=True) # If we go back in history we have to safe our pq so we always try to apply # the latest one # If we are using the upstream_tag, we always need a copy of the patches if len(commits) > 1 or pq_on_upstream_tag(pq_from): if os.path.exists(series): tmpdir, series = safe_patches(series, repo) queue = PatchSeries.read_series_file(series) i = len(commits) for commit in commits: if len(commits) > 1: gbp.log.info("%d %s left" % (i, 'tries' if i > 1 else 'try')) try: gbp.log.info("Trying to apply patches at '%s'" % commit) repo.create_branch(pq_branch, commit) except GitRepositoryError: raise GbpError("Cannot create patch-queue branch '%s'." % pq_branch) repo.set_branch(pq_branch) for patch in queue: gbp.log.debug("Applying %s" % patch.path) try: name = os.path.basename(patch.path) apply_and_commit_patch(repo, patch, maintainer, patch.topic, name) except (GbpError, GitRepositoryError) as e: gbp.log.err("Failed to apply '%s': %s" % (patch.path, e)) repo.force_head('HEAD', hard=True) repo.set_branch(branch) repo.delete_branch(pq_branch) break else: # All patches applied successfully break i -= 1 else: raise GbpError("Couldn't apply patches") if tmpdir: gbp.log.debug("Remove temporary patch safe '%s'" % tmpdir) shutil.rmtree(tmpdir) return len(queue)
def main(argv): retval = 0 parser = GbpOptionParserDebian(command=os.path.basename(argv[0]), prefix='', usage="%prog [options] action - maintain patches on a patch queue branch\n" "Actions:\n" " export export the patch queue associated to the current branch\n" " into a quilt patch series in debian/patches/ and update the\n" " series file.\n" " import create a patch queue branch from quilt patches in debian/patches.\n" " rebase switch to patch queue branch associated to the current\n" " branch and rebase against current branch.\n" " drop drop (delete) the patch queue associated to the current branch.\n" " apply apply a patch\n" " switch switch to patch-queue branch and vice versa") parser.add_boolean_config_file_option(option_name="patch-numbers", dest="patch_numbers") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="verbose command execution") parser.add_option("--topic", dest="topic", help="in case of 'apply' topic (subdir) to put patch into") parser.add_config_file_option(option_name="time-machine", dest="time_machine", type="int") parser.add_option("--force", dest="force", action="store_true", default=False, help="in case of import even import if the branch already exists") parser.add_config_file_option(option_name="color", dest="color", type='tristate') parser.add_config_file_option(option_name="color-scheme", dest="color_scheme") (options, args) = parser.parse_args(argv) gbp.log.setup(options.color, options.verbose, options.color_scheme) if len(args) < 2: gbp.log.err("No action given.") return 1 else: action = args[1] if args[1] in ["export", "import", "rebase", "drop", "switch"]: pass elif args[1] in ["apply"]: if len(args) != 3: gbp.log.err("No patch name given.") return 1 else: patchfile = args[2] else: gbp.log.err("Unknown action '%s'." % args[1]) return 1 try: repo = GitRepository(os.path.curdir) except GitRepositoryError: gbp.log.err("%s is not a git repository" % (os.path.abspath('.'))) return 1 try: current = repo.get_branch() if action == "export": export_patches(repo, current, options) elif action == "import": series = SERIES_FILE tries = options.time_machine if (options.time_machine > 0) else 1 import_quilt_patches(repo, current, series, tries, options.force) current = repo.get_branch() gbp.log.info("Patches listed in '%s' imported on '%s'" % (series, current)) elif action == "drop": drop_pq(repo, current) elif action == "rebase": rebase_pq(repo, current) elif action == "apply": patch = Patch(patchfile) maintainer = get_maintainer_from_control(repo) apply_single_patch(repo, current, patch, maintainer, options.topic) elif action == "switch": switch_pq(repo, current) except CommandExecFailed: retval = 1 except (GbpError, GitRepositoryError) as err: if len(err.__str__()): gbp.log.err(err) retval = 1 return retval
def import_quilt_patches(repo, branch, series, tries, force, pq_from, upstream_tag): """ apply a series of quilt patches in the series file 'series' to branch the patch-queue branch for 'branch' @param repo: git repository to work on @param branch: branch to base patch queue on @param series: series file to read patches from @param tries: try that many times to apply the patches going back one commit in the branches history after each failure. @param force: import the patch series even if the branch already exists @param pq_from: what to use as the starting point for the pq branch. DEBIAN indicates the current branch, TAG indicates that the corresponding upstream tag should be used. @param upstream_tag: upstream tag template to use """ tmpdir = None series = os.path.join(repo.path, series) if is_pq_branch(branch): if force: branch = pq_branch_base(branch) pq_branch = pq_branch_name(branch) repo.checkout(branch) else: raise GbpError( "Already on a patch-queue branch '%s' - doing nothing." % branch) else: pq_branch = pq_branch_name(branch) if repo.has_branch(pq_branch): if force: drop_pq(repo, branch) else: raise GbpError( "Patch queue branch '%s'. already exists. Try 'rebase' or 'switch' instead." % pq_branch) maintainer = get_maintainer_from_control(repo) if pq_on_upstream_tag(pq_from): commits = [find_upstream_commit(repo, branch, upstream_tag)] else: # pq_from == 'DEBIAN' commits = repo.get_commits(num=tries, first_parent=True) # If we go back in history we have to safe our pq so we always try to apply # the latest one # If we are using the upstream_tag, we always need a copy of the patches if len(commits) > 1 or pq_on_upstream_tag(pq_from): if os.path.exists(series): tmpdir, series = safe_patches(series, repo) queue = PatchSeries.read_series_file(series) i = len(commits) for commit in commits: if len(commits) > 1: gbp.log.info("%d %s left" % (i, 'tries' if i > 1 else 'try')) try: gbp.log.info("Trying to apply patches at '%s'" % commit) repo.create_branch(pq_branch, commit) except GitRepositoryError: raise GbpError("Cannot create patch-queue branch '%s'." % pq_branch) repo.set_branch(pq_branch) for patch in queue: gbp.log.debug("Applying %s" % patch.path) try: name = os.path.basename(patch.path) apply_and_commit_patch(repo, patch, maintainer, patch.topic, name) except (GbpError, GitRepositoryError) as e: gbp.log.err("Failed to apply '%s': %s" % (patch.path, e)) repo.force_head('HEAD', hard=True) repo.set_branch(branch) repo.delete_branch(pq_branch) break else: # All patches applied successfully break i -= 1 else: raise GbpError("Couldn't apply patches") if tmpdir: gbp.log.debug("Remove temporary patch safe '%s'" % tmpdir) shutil.rmtree(tmpdir) return len(queue)