def test_bump_changelog(self, tmpdir, monkeypatch): """ test bumping a debian changelog """ monkeypatch.setenv('HOME', FIXTURES_DIR) monkeypatch.chdir(tmpdir) # Our /debian/changelog fixture: source = py.path.local(FIXTURES_DIR).join('changelog') # Copy this fixture file to our tmpdir. source.copy(tmpdir.mkdir('debian')) assert util.bump_changelog(['some change']) is True assert str(util.get_deb_version()) == '10.2.0-5redhat1'
def test_bump_changelog(self, testpkg): """ test bumping a debian changelog """ assert util.bump_changelog(['some change']) is True assert str(util.get_deb_version()) == '1.0.0-3redhat1'
def _run(self): """ Generate quilt patch series with gbp pq, and update d/rules """ # Determine the names of the patch-queue branch and debian branch current_branch = util.current_branch() patch_queue_branch = util.current_patch_queue_branch() debian_branch = util.current_debian_branch() # TODO: default to fetching from upstream, the way rdopkg patch does. # Get the new sha1 to insert into the $COMMIT variable in d/rules cmd = ['git', 'rev-parse', patch_queue_branch] output = subprocess.check_output(cmd) patch_queue_sha1 = output.rstrip() if six.PY3: patch_queue_sha1 = output.decode('utf-8').rstrip() # Switch to "debian" branch if necessary if current_branch != debian_branch: cmd = ['git', 'checkout', debian_branch] subprocess.check_call(cmd) # Get the original (old) patch series old_series = self.read_series_file('debian/patches/series') old_subjects = [patch.subject for patch in old_series] # Git-buildpackage pq operation cmd = ['gbp', 'pq', 'export'] subprocess.check_call(cmd) # Add all patch files to Git's index cmd = ['git', 'add', '--all', 'debian/patches'] subprocess.check_call(cmd) # Bail early if gbp pq did nothing. if not self.read_git_debian_patches_status(): print('No new patches, quitting.') raise SystemExit(1) # Replace $COMMIT sha1 in d/rules old_sha1 = read_commit() if old_sha1: rules = read_rules_file() with open('debian/rules', 'w') as fileh: fileh.write(rules.replace(old_sha1, patch_queue_sha1)) # Get the new patch series new_series = self.read_series_file('debian/patches/series') # Select only the ones that are new (according to commit subjects) new_series = [p for p in new_series if p.subject not in old_subjects] if not new_series: # Maybe we rewrote some patch files in place? # Check Git itself for changed files: new_series = self.read_git_debian_patches() # Add patch entries to d/changelog changelog = self.generate_changelog(new_series) try: ensure_bzs(changelog) except BzNotFound: if not self.parser.has('--nobz'): raise util.bump_changelog(changelog) # Assemble a standard commit message string "clog". clog = "debian: %s\n" % util.get_deb_version() clog += "\n" clog += "Add patches from %s\n" % patch_queue_branch clog += "\n" clog += util.format_changelog(changelog) # Commit everything with the standard commit message. with tempfile.NamedTemporaryFile(mode='w+') as temp: temp.write(clog) temp.flush() cmd = [ 'git', 'commit', 'debian/changelog', 'debian/patches', 'debian/rules', '-F', temp.name ] subprocess.check_call(cmd) # Summarize this commit on STDOUT for the developer. # (This matches the behavior of "rdopkg patch".) cmd = ['git', '--no-pager', 'log', '--name-status', 'HEAD~..HEAD'] subprocess.check_call(cmd)
def _run(self): """ Generate quilt patch series with gbp pq, and update d/rules """ # Determine the names of the patch-queue branch and debian branch current_branch = util.current_branch() patches_branch = util.current_patches_branch() debian_branch = util.current_debian_branch() # TODO: default to fetching from upstream, the way rdopkg patch does. # Get the new sha1 to insert into the $COMMIT variable in d/rules cmd = ['git', 'rev-parse', patches_branch] patches_sha1 = subprocess.check_output(cmd).rstrip() # Switch to "debian" branch if necessary if current_branch != debian_branch: cmd = ['git', 'checkout', debian_branch] subprocess.check_call(cmd) # Get the original (old) patch series old_series = self.read_series_file('debian/patches/series') old_subjects = map(lambda x: x.subject, old_series) # Git-buildpackage pq operation cmd = ['gbp', 'pq', 'export'] subprocess.check_call(cmd) # Add all patch files to Git's index cmd = ['git', 'add', '--all', 'debian/patches'] subprocess.check_call(cmd) # Replace $COMMIT sha1 in d/rules with open('debian/rules') as rules: rules_file = rules.read() old = r'export COMMIT=[0-9a-f]{40}' new = 'export COMMIT=%s' % patches_sha1 with open('debian/rules', 'w') as fileh: fileh.write(re.sub(old, new, rules_file)) # Get the new patch series new_series = self.read_series_file('debian/patches/series') # Add patch entries to d/changelog changelog = [] for p in new_series: if p.subject in old_subjects: continue change = p.subject bzs = self.get_rhbzs(p) bzstr = ' '.join(map(lambda x: 'rhbz#%s' % x, bzs)) if bzstr != '': change += ' (%s)' % bzstr changelog.append(change) util.bump_changelog(changelog) # Assemble a standard commit message string "clog". clog = "debian: %s\n" % util.get_deb_version() clog += "\n" clog += "Add patches from %s\n" % patches_branch clog += "\n" clog += util.format_changelog(changelog) # Commit everything with the standard commit message. with tempfile.NamedTemporaryFile() as temp: temp.write(clog) temp.flush() cmd = [ 'git', 'commit', 'debian/changelog', 'debian/patches', 'debian/rules', '-F', temp.name ] subprocess.check_call(cmd) # Summarize this commit on STDOUT for the developer. # (This matches the behavior of "rdopkg patch".) cmd = ['git', '--no-pager', 'log', '--name-status', 'HEAD~..HEAD'] subprocess.check_call(cmd)
def test_bump_changelog(self, testpkg, monkeypatch): """ test bumping a debian changelog """ assert util.bump_changelog(['some change']) is True assert str(util.get_deb_version()) == '1.0.0-3redhat1'