def test_from_git_trailers(): commit = flexmock(message="""\ Add a test commit Patch-name: test.patch Signed-off-by: Everyday Programmer <*****@*****.**> """) patch_meta = PatchMetadata.from_git_trailers(commit) assert patch_meta.name == "test.patch"
def _rebase_patches(self): """Rebase current branch against the from_branch.""" to_branch = "dist-git-commits" # temporary branch to store the dist-git history BUILD_dir = self.get_BUILD_dir() prep_repo = git.Repo(BUILD_dir) from_branch = get_default_branch(prep_repo) logger.info(f"Rebase patches from dist-git {from_branch}.") self.source_git.git.fetch(BUILD_dir, f"+{from_branch}:{to_branch}") # transform into {patch_name: patch_id} with self.dist_git_specfile.patches() as patches: patch_ids = {p.filename: p.number for p in patches} patch_comments = {p.filename: p.comments.raw for p in patches} # -2 - drop first commit which represents tarball unpacking # -1 - reverse order, HEAD is last in the sequence patch_commits = list(prep_repo.iter_commits(from_branch))[-2::-1] for commit in patch_commits: self.source_git.git.cherry_pick( commit.hexsha, keep_redundant_commits=True, allow_empty=True, strategy_option="theirs", ) # Annotate commits in the source-git repo with patch_id. This info is not provided # during the rpm patching process so we need to do it here. metadata = PatchMetadata.from_git_trailers(commit) trailers = [("Patch-id", patch_ids[metadata.name])] patch_status = "" for line in patch_comments.get(metadata.name, []): patch_status += f" # {line}\n" if patch_status: trailers.append(("Patch-status", f"|\n{patch_status}")) trailers.append( (FROM_DIST_GIT_TOKEN, self.dist_git.head.commit.hexsha)) author = None # If the commit subject matches the one used in _packitpatch # when applying patches with 'patch', get the original (first) # author of the patch file in dist-git. if commit.message.startswith(f"Apply patch {metadata.name}"): author = get_file_author(self.dist_git, metadata.name) logger.debug(f"author={author}") with commit_message_file(commit.message, trailers=trailers) as commit_message: self.source_git.git.commit(file=commit_message, author=author, amend=True, allow_empty=True) self.source_git.git.branch("-D", to_branch)
def _rebase_patches(self, patch_comments: Dict[str, List[str]]): """Rebase current branch against the from_branch Args: patch_comments: dict to map patch names to comment lines serving as a description of those patches. """ to_branch = "dist-git-commits" # temporary branch to store the dist-git history BUILD_dir = self.get_BUILD_dir() prep_repo = git.Repo(BUILD_dir) from_branch = get_default_branch(prep_repo) logger.info(f"Rebase patches from dist-git {from_branch}.") self.source_git.git.fetch(BUILD_dir, f"+{from_branch}:{to_branch}") # transform into {patch_name: patch_id} patch_ids = { p.get_patch_name(): p.index for p in self.dist_git_specfile.patches.get("applied", []) } # -2 - drop first commit which represents tarball unpacking # -1 - reverse order, HEAD is last in the sequence patch_commits = list(prep_repo.iter_commits(from_branch))[-2::-1] for commit in patch_commits: self.source_git.git.cherry_pick( commit.hexsha, keep_redundant_commits=True, allow_empty=True, strategy_option="theirs", ) # Annotate commits in the source-git repo with patch_id. This info is not provided # during the rpm patching process so we need to do it here. metadata = PatchMetadata.from_git_trailers(commit) # commit.message already ends with \n message = commit.message message += f"Patch-id: {patch_ids[metadata.name]}\n" if patch_comments.get(metadata.name): message += "Patch-status: |\n" for line in patch_comments.get(metadata.name, []): message += f" # {line}\n" self.source_git.git.commit(message=message, amend=True, allow_empty=True) self.source_git.git.branch("-D", to_branch)