def _run(self, force=False): # Determine the names of the relevant branches current_branch = util.current_branch() debian_branch = util.current_debian_branch() patches_branch = util.current_patches_branch() rhel_patches_branch = self.get_rhel_patches_branch(debian_branch) # Do the merge if current_branch == patches_branch: # HEAD is our patch-queue branch. Use "git pull" directly. # For example: "git pull --ff-only patches/ceph-2-rhel-patches" cmd = ['git', 'pull', '--ff-only', 'patches/' + rhel_patches_branch] if force: # Do a hard reset on HEAD instead. cmd = ['git', 'reset', '--hard', 'patches/' + rhel_patches_branch] else: # HEAD is our debian branch. Use "git fetch" to update the # patch-queue ref. For example: # "git fetch . \ # patches/ceph-2-rhel-patches:patch-queue/ceph-2-ubuntu" cmd = ['git', 'fetch', '.', 'patches/%s:%s' % (rhel_patches_branch, patches_branch)] if force: # Do a hard push (with "+") instead. cmd = ['git', 'push', '.', '+patches/%s:%s' % (rhel_patches_branch, patches_branch)] log.info(' '.join(cmd)) subprocess.check_call(cmd)
def _run(self, force=False): # Determine the names of the relevant branches current_branch = util.current_branch() debian_branch = util.current_debian_branch() patches_branch = util.current_patches_branch() rhel_patches_branch = self.get_rhel_patches_branch(debian_branch) # Do the merge if current_branch == patches_branch: # HEAD is our patch-queue branch. Use "git pull" directly. # For example: "git pull --ff-only patches/ceph-2-rhel-patches" cmd = [ 'git', 'pull', '--ff-only', 'patches/' + rhel_patches_branch ] if force: # Do a hard reset on HEAD instead. cmd = [ 'git', 'reset', '--hard', 'patches/' + rhel_patches_branch ] else: # HEAD is our debian branch. Use "git fetch" to update the # patch-queue ref. For example: # "git fetch . \ # patches/ceph-2-rhel-patches:patch-queue/ceph-2-ubuntu" cmd = [ 'git', 'fetch', '.', 'patches/%s:%s' % (rhel_patches_branch, patches_branch) ] if force: # Do a hard push (with "+") instead. cmd = [ 'git', 'push', '.', '+patches/%s:%s' % (rhel_patches_branch, patches_branch) ] log.info(' '.join(cmd)) 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_current_patches_and_debian_branches(self, monkeypatch, current_branch): monkeypatch.setattr('rhcephpkg.util.current_branch', lambda: current_branch) assert util.current_patches_branch() == 'patch-queue/ceph-2-ubuntu' assert util.current_debian_branch() == 'ceph-2-ubuntu'
def test_current_patches_branch(self, testpkg, monkeypatch): assert util.current_patches_branch() == 'patch-queue/ceph-2-ubuntu'