def test_rebase(self): """Basic test for rebase action""" repo = self.init_test_repo('gbp-test') repo.rename_branch('pq/master', 'patch-queue/master') repo.set_branch('patch-queue/master') branches = repo.get_local_branches() # Make development branch out-of-sync GitCommand("rebase")(['--onto', 'upstream^', 'upstream']) # Sanity check for our git rebase... ok_(repo.get_merge_base('patch-queue/master', 'upstream') != repo.rev_parse('upstream')) # Do rebase eq_(mock_pq(['rebase']), 0) self._check_repo_state(repo, 'patch-queue/master', branches) ok_(repo.get_merge_base('patch-queue/master', 'upstream') == repo.rev_parse('upstream')) # Get to out-of-sync, again, and try rebase from master branch GitCommand("rebase")(['--onto', 'upstream^', 'upstream']) eq_(mock_pq(['switch']), 0) eq_(mock_pq(['rebase']), 0) self._check_repo_state(repo, 'patch-queue/master', branches) ok_(repo.get_merge_base('patch-queue/master', 'upstream') == repo.rev_parse('upstream'))
def rebase_pq(repo, branch): if is_pq_branch(branch): base = pq_branch_base(branch) else: switch_to_pq_branch(repo, branch) base = branch GitCommand("rebase")([base])
def rebase_pq(repo, branch, options): maybe_import_pq(repo, branch, options) # Make sure we're on the pq branch switch_to_pq_branch(repo, branch) if pq_on_upstream_tag(options.pq_from): base = find_upstream_commit(repo, branch, options.upstream_tag) else: base = pq_branch_base(repo.branch) GitCommand("rebase", cwd=repo.path)([base])
def rebase_pq(repo, branch, pq_from, upstream_tag): if is_pq_branch(branch): base = pq_branch_base(branch) else: raise GbpError("Rebase must be run from the patch-queue branch. " "Try 'import' instead.") if pq_on_upstream_tag(pq_from): base = find_upstream_commit(repo, base, upstream_tag) GitCommand("rebase", cwd=repo.path)([base])
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')))
def rebase_pq(repo, options): """Rebase pq branch on the correct upstream version (from spec file).""" current = repo.get_branch() if is_pq_branch(current): base = pq_branch_base(current) spec = parse_spec(options, repo, base) else: base = current spec = parse_spec(options, repo) upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag) switch_to_pq_branch(repo, base) GitCommand("rebase")([upstream_commit])
def rebase_pq(cfg, repo, options): """Rebase pq branch on the correct upstream version""" current = repo.get_branch() if is_pq_branch(current, options): base = pq_branch_base(current, options) bbfile = parse_bb(cfg, options, repo, base) else: base = current bbfile = parse_bb(cfg, options, repo) upstream_commit = find_upstream_commit(repo, bbfile, options.upstream_tag) switch_to_pq_branch(cfg, repo, base, options) GitCommand("rebase")([upstream_commit])
def rebase_pq(repo, branch, pq_from, upstream_tag): if is_pq_branch(branch): base = pq_branch_base(branch) else: switch_to_pq_branch(repo, branch) base = branch if pq_on_upstream_tag(pq_from): _from = find_upstream_commit(repo, base, upstream_tag) else: _from = base GitCommand("rebase", cwd=repo.path)([_from])
def export_patches(repo, branch, options): """Export patches from the pq branch into a patch series""" patch_dir = os.path.join(repo.path, PATCH_DIR) series_file = os.path.join(repo.path, SERIES_FILE) if is_pq_branch(branch): base = pq_branch_base(branch) gbp.log.info("On '%s', switching to '%s'" % (branch, base)) branch = base repo.set_branch(branch) pq_branch = pq_branch_name(branch) try: shutil.rmtree(patch_dir) except OSError as e: if e.errno != errno.ENOENT: raise GbpError("Failed to remove patch dir: %s" % e.strerror) else: gbp.log.debug("%s does not exist." % patch_dir) if pq_on_upstream_tag(options.pq_from): base = find_upstream_commit(repo, branch, options.upstream_tag) else: base = branch patches = generate_patches(repo, base, pq_branch, patch_dir, options) if patches: with open(series_file, 'w') as seriesfd: for patch in patches: seriesfd.write(os.path.relpath(patch, patch_dir) + '\n') if options.commit: added, removed = commit_patches(repo, branch, patches, options, patch_dir) if added: what = 'patches' if len(added) > 1 else 'patch' gbp.log.info("Added %s %s to patch series" % (what, ', '.join(added))) if removed: what = 'patches' if len(removed) > 1 else 'patch' gbp.log.info("Removed %s %s from patch series" % (what, ', '.join(removed))) else: GitCommand('status', cwd=repo.path)(['--', PATCH_DIR]) else: gbp.log.info("No patches on '%s' - nothing to do." % pq_branch) if options.drop: drop_pq(repo, branch)
def export_patches(repo, options): """Export patches from the pq branch into a packaging branch""" current = repo.get_branch() if is_pq_branch(current): base = pq_branch_base(current) gbp.log.info("On branch '%s', switching to '%s'" % (current, base)) repo.set_branch(base) pq_branch = current else: pq_branch = pq_branch_name(current) spec = parse_spec(options, repo) upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag) export_treeish = pq_branch update_patch_series(repo, spec, upstream_commit, export_treeish, options) GitCommand('status')(['--', spec.specdir])
def export_patches(cfg, repo, options): """Export patches from the pq branch into a packaging branch""" current = repo.get_branch() if is_pq_branch(current, options): base = pq_branch_base(current, options) gbp.log.info("On branch '%s', switching to '%s'" % (current, base)) repo.set_branch(base) bbfile = parse_bb(cfg, options, repo) pq_branch = current else: bbfile = parse_bb(cfg, options, repo) pq_branch = pq_branch_name(current, options, pkg_version(bbfile)) upstream_commit = find_upstream_commit(repo, bbfile, options.upstream_tag) export_treeish = options.export_rev if options.export_rev else pq_branch update_patch_series(repo, bbfile, upstream_commit, export_treeish, options) bb_dir = os.path.dirname(bbfile.getVar('FILE', True)) GitCommand('status')(['--', bb_dir])
def export_patches(repo, options): """Export patches from the pq branch into a packaging branch""" current = repo.get_branch() if is_pq_branch(current, options): base = pq_branch_base(current, options) gbp.log.info("On branch '%s', switching to '%s'" % (current, base)) repo.set_branch(base) spec = parse_spec(options, repo) pq_branch = current else: spec = parse_spec(options, repo) pq_branch = pq_branch_name(current, options, spec.version) upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag) export_treeish = options.export_rev if options.export_rev else pq_branch if not repo.has_treeish(export_treeish): raise GbpError('Invalid treeish object %s' % export_treeish) update_patch_series(repo, spec, upstream_commit, export_treeish, options) GitCommand('status')(['--', spec.specdir])
pq_branch = pq_branch_name(branch) try: shutil.rmtree(PATCH_DIR) except OSError as (e, msg): if e != errno.ENOENT: raise GbpError("Failed to remove patch dir: %s" % msg) else: gbp.log.debug("%s does not exist." % PATCH_DIR) patches = generate_patches(repo, branch, pq_branch, PATCH_DIR, options) if patches: with open(SERIES_FILE, 'w') as seriesfd: for patch in patches: seriesfd.write(os.path.relpath(patch, PATCH_DIR) + '\n') GitCommand('status')(['--', PATCH_DIR]) else: gbp.log.info("No patches on '%s' - nothing to do." % pq_branch) def safe_patches(series): """ Safe the current patches in a temporary directory below .git/ @param series: path to series file @return: tmpdir and path to safed series file @rtype: tuple """ src = os.path.dirname(series)
def git_create_empty_branch(self, branch): GitCommand('checkout', cwd=self.repo.path)(['-q', '--orphan', branch]) GitCommand('rm', cwd=self.repo.path)(['-rf', '.'])
def push_branches(remote, branches): gitPush = GitCommand('push') gitPush([remote['url']] + branches) gitPush([remote['url'], '--tags'])
def setup_branch_tracking(repo, remote, branches): repo.add_remote_repo(name=remote['name'], url=remote['url'], fetch=True) gitTrackRemote = GitCommand('branch', ['--set-upstream']) for branch in branches: gitTrackRemote(['%s' % branch, '%s/%s' % (remote['name'], branch)])