Esempio n. 1
0
 def test_commit_dropped_patches(self):
     """Test if we commit the patch-queue branch with all patches dropped"""
     repo = self.repo
     start = repo.get_branch()
     pq_branch = os.path.join('patch-queue', start)
     opts = TestExport.Options()
     opts.commit = True
     patch_dir = os.path.join(repo.path, 'debian/patches')
     os.makedirs(patch_dir)
     with open(os.path.join(patch_dir, 'series'), 'w') as f:
         f.write("patch1.diff\n")
         f.write("patch2.diff\n")
     repo.add_files('debian/patches')
     repo.commit_all('Add series file')
     repo.create_branch(pq.pq_branch_name('master'))
     pq.switch_pq(repo, start)
     self.assertEqual(len(repo.get_commits()), 2)
     self.assertEqual(repo.get_branch(), pq_branch)
     export_patches(repo, pq_branch, opts)
     self.assertEqual(repo.get_branch(), start)
     self.assertTrue(repo.has_branch(pq_branch))
     self.assertEqual(len(repo.get_commits()), 3,
                      "Export did not create commit")
     self.assertIn(b"Dropped patch1.diff:", repo.show('HEAD'))
     self.assertIn(b"Dropped patch2.diff:", repo.show('HEAD'))
Esempio n. 2
0
 def test_drop(self):
     """Test if we drop the patch-queue branch with --drop"""
     repo = self.repo
     start = repo.get_branch()
     pq_branch = os.path.join('patch-queue', start)
     pq.switch_pq(repo, start)
     self.assertEqual(repo.get_branch(), pq_branch)
     export_patches(repo, pq_branch, TestExport.Options)
     self.assertEqual(repo.get_branch(), start)
     self.assertFalse(repo.has_branch(pq_branch))
Esempio n. 3
0
 def test_adding_patch(self):
     import_quilt_patches(self.repo,
                          branch=self.repo.get_branch(),
                          series=SERIES_FILE,
                          tries=1,
                          force=TestFromTAG.Options.force,
                          pq_from=TestFromTAG.Options.pq_from,
                          upstream_tag=TestFromTAG.Options.upstream_tag)
     self.add_file('bar', 'bar', 'added bar')
     export_patches(self.repo,
                    branch=self.repo.get_branch(),
                    options=TestFromTAG.Options())
     self.assertTrue(
         os.path.exists(
             os.path.join(self.repo.path, os.path.dirname(SERIES_FILE),
                          'added-bar.patch')))
     pq.switch_pq(self.repo, 'master')
     rebase_pq(self.repo,
               branch=self.repo.get_branch(),
               pq_from=TestFromTAG.Options.pq_from,
               upstream_tag=TestFromTAG.Options.upstream_tag)
     export_patches(self.repo,
                    branch=self.repo.get_branch(),
                    options=TestFromTAG.Options())
     self.assertTrue(
         os.path.exists(
             os.path.join(self.repo.path, os.path.dirname(SERIES_FILE),
                          'added-bar.patch')))
     # New upstream release
     self.repo.set_branch('bar')
     GitCommand('cherry-pick', cwd=self.repo.path)(['patch-queue/master'])
     self.repo.create_tag('upstream/0.0.2')
     self.repo.set_branch('master')
     self.add_file(
         'debian/changelog', 'foo (0.0.2-1) UNRELEASED; urgency=medium\n'
         '\n'
         '  * Initial foo\n'
         '\n'
         ' -- Mr. T. S. <*****@*****.**>  '
         'Thu, 01 Jan 1970 00:00:00 +0000\n')
     pq.switch_pq(self.repo, 'master')
     rebase_pq(self.repo,
               branch=self.repo.get_branch(),
               pq_from=TestFromTAG.Options.pq_from,
               upstream_tag=TestFromTAG.Options.upstream_tag)
     export_patches(self.repo,
                    branch=self.repo.get_branch(),
                    options=TestFromTAG.Options())
     self.assertFalse(
         os.path.exists(
             os.path.join(self.repo.path, os.path.dirname(SERIES_FILE),
                          'added-bar.patch')))
Esempio n. 4
0
    def test_drop(self):
        """Test if we drop the patch-queue branch with --drop"""
        repo = self.repo
        start = repo.get_branch()
        pq_branch = os.path.join('patch-queue', start)
        opts = TestExport.Options()
        opts.drop = True

        repo.create_branch(pq.pq_branch_name('master'))
        pq.switch_pq(repo, start)
        self.assertEqual(repo.get_branch(), pq_branch)
        export_patches(repo, pq_branch, opts)
        self.assertEqual(repo.get_branch(), start)
        self.assertFalse(repo.has_branch(pq_branch))
Esempio n. 5
0
 def test_commit(self):
     """Test if we commit the patch-queue branch with --commit"""
     repo = self.repo
     start = repo.get_branch()
     pq_branch = os.path.join('patch-queue', start)
     opts = TestExport.Options()
     opts.commit = True
     pq.switch_pq(repo, start)
     self.assertEqual(len(repo.get_commits()), 1)
     self.assertEqual(repo.get_branch(), pq_branch)
     self.add_file('foo', 'foo')
     export_patches(repo, pq_branch, opts)
     self.assertEqual(repo.get_branch(), start)
     self.assertTrue(repo.has_branch(pq_branch))
     self.assertEqual(len(repo.get_commits()), 2,
                      "Export did not create commit")
     export_patches(repo, pq_branch, opts)
     self.assertEqual(repo.get_branch(), start)
     self.assertEqual(len(repo.get_commits()), 2,
                      "Export must not create another commit")
Esempio n. 6
0
 def test_commit(self):
     """Test if we commit the patch-queue branch with --commit"""
     repo = self.repo
     start = repo.get_branch()
     pq_branch = os.path.join('patch-queue', start)
     opts = TestExport.Options()
     opts.commit = True
     pq.switch_pq(repo, start)
     self.assertEqual(len(repo.get_commits()), 1)
     self.assertEqual(repo.get_branch(), pq_branch)
     self.add_file('foo', 'foo')
     export_patches(repo, pq_branch, opts)
     self.assertEqual(repo.get_branch(), start)
     self.assertTrue(repo.has_branch(pq_branch))
     self.assertEqual(len(repo.get_commits()), 2,
                      "Export did not create commit")
     export_patches(repo, pq_branch, opts)
     self.assertEqual(repo.get_branch(), start)
     self.assertEqual(len(repo.get_commits()), 2,
                      "Export must not create another commit")
Esempio n. 7
0
def main(argv):
    """Main function for the gbp pq-rpm command"""
    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", "convert"]:
        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 = RpmGitRepository(os.path.curdir)
    except GitRepositoryError:
        gbp.log.err("%s is not a git repository" % (os.path.abspath('.')))
        return 1

    try:
        # Create base temporary directory for this run
        init_tmpdir(options.tmp_dir, prefix='pq-rpm_')
        current = repo.get_branch()
        if action == "export":
            export_patches(repo, options)
        elif action == "import":
            import_spec_patches(repo, options)
        elif action == "drop":
            drop_pq(repo, current)
        elif action == "rebase":
            rebase_pq(repo, options)
        elif action == "apply":
            patch = Patch(patchfile)
            apply_single_patch(repo, current, patch, fallback_author=None)
        elif action == "switch":
            switch_pq(repo, current)
    except KeyboardInterrupt:
        retval = 1
        gbp.log.err("Interrupted. Aborting.")
    except CommandExecFailed:
        retval = 1
    except GitRepositoryError as err:
        gbp.log.err("Git command failed: %s" % err)
        retval = 1
    except GbpError as err:
        if str(err):
            gbp.log.err(err)
        retval = 1
    finally:
        del_tmpdir()

    return retval
Esempio n. 8
0
def main(argv):
    """Main function for the gbp pq-rpm command"""
    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", "convert"]:
        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 = RpmGitRepository(os.path.curdir)
    except GitRepositoryError:
        gbp.log.err("%s is not a git repository" % (os.path.abspath('.')))
        return 1

    try:
        # Create base temporary directory for this run
        options.tmp_dir = tempfile.mkdtemp(dir=options.tmp_dir,
                                           prefix='gbp-pq-rpm_')
        current = repo.get_branch()
        if action == "export":
            export_patches(repo, options)
        elif action == "import":
            import_spec_patches(repo, options)
        elif action == "drop":
            drop_pq(repo, current)
        elif action == "rebase":
            rebase_pq(repo, options)
        elif action == "apply":
            patch = Patch(patchfile)
            apply_single_patch(repo, current, patch, fallback_author=None)
        elif action == "switch":
            switch_pq(repo, current)
    except CommandExecFailed:
        retval = 1
    except GitRepositoryError as err:
        gbp.log.err("Git command failed: %s" % err)
        retval = 1
    except GbpError, err:
        if str(err):
            gbp.log.err(err)
        retval = 1
Esempio n. 9
0
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 str(err):
            gbp.log.err(err)
        retval = 1

    return retval
Esempio n. 10
0
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 str(err):
            gbp.log.err(err)
        retval = 1

    return retval