def convert(ctx, origin: str, dest: str): """Convert a dist-git repository into a source-git repository, using 'rpmbuild' and executing the "%prep" stage from the spec file. Update if the branch exists. ORIGIN and DEST are in the format of REPO_PATH:BRANCH Set DIST2SRC_GET_SOURCES to the path to git_sources.sh, if it's not in the PATH. """ origin_dir, origin_branch = origin.split(":") dest_dir, dest_branch = dest.split(":") d2s = Dist2Src( dist_git_path=Path(origin_dir), source_git_path=Path(dest_dir), log_level=ctx.obj[VERBOSE_KEY], ) if d2s.source_git_path.exists( ) and dest_branch in d2s.source_git.repo.branches: logger.info( "The source-git repository and branch exist. Updating existing source-git..." ) d2s.update_source_git(origin_branch, dest_branch) else: d2s.convert(origin_branch, dest_branch)
def convert(ctx, origin: str, dest: str): """Convert a dist-git repository into a source-git repository, using 'rpmbuild' and executing the "%prep" stage from the spec file. If the package is on the list of "hard" packages, there will be only a single commit representing the current dist-git tree, if it's not on the list, multiple commits will be in the repo: * upstream archive unpacked as a single commit * multiple commits for spec file, packit.yaml and additional sources * every patch is a commit Update if the branch exists. ORIGIN and DEST are in the format of REPO_PATH:BRANCH Set DIST2SRC_GET_SOURCES to the path to git_sources.sh, if it's not in the PATH. """ origin_dir, origin_branch = origin.split(":") dest_dir, dest_branch = dest.split(":") d2s = Dist2Src( dist_git_path=Path(origin_dir), source_git_path=Path(dest_dir), log_level=ctx.obj[VERBOSE_KEY], ) d2s.convert(origin_branch, dest_branch)
def test_pkg_name(acl, set_dist, set_src, expected): dist_path, src_path = None, None if set_dist: dist_path = acl if set_src: src_path = acl assert (Dist2Src(dist_git_path=dist_path, source_git_path=src_path).package_name == expected)
def copy_all_sources(ctx, origin: str, dest: str): """Copy 'SOURCES/*' from a dist-git repo to a source-git repo.""" d2s = Dist2Src( dist_git_path=Path(origin), source_git_path=Path(dest), log_level=ctx.obj[VERBOSE_KEY], ) d2s.copy_all_sources()
def copy_spec(ctx, origin: str, dest: str): """Copy 'SPECS/*.spec' from a dist-git repo to a source-git repo.""" d2s = Dist2Src( dist_git_path=Path(origin), source_git_path=Path(dest), log_level=ctx.obj[VERBOSE_KEY], ) d2s.copy_spec()
def add_packit_config(ctx, dest: str): """ Add packit config to the source-git repo and commit it. """ d2s = Dist2Src(dist_git_path=None, source_git_path=Path(dest), log_level=ctx.obj[VERBOSE_KEY]) d2s.add_packit_config()
def run_prep(ctx, path: str): """Run `rpmbuild -bp` in GITDIR. PATH needs to be a dist-git repository. """ d2s = Dist2Src(dist_git_path=Path(path), source_git_path=None, log_level=ctx.obj[VERBOSE_KEY]) d2s.run_prep()
def add_packit_config(ctx, dest: str, branch: str): """ Add packit config to the source-git repo and commit it. """ d2s = Dist2Src(dist_git_path=None, source_git_path=Path(dest), log_level=ctx.obj[VERBOSE_KEY]) d2s.add_packit_config( upstream_ref=START_TAG_TEMPLATE.format(branch=branch), lookaside_branch=branch)
def convert(self) -> bool: try: self.d2s = Dist2Src( dist_git_path=self.rpm_package_dir, source_git_path=self.src_package_dir, ) self.d2s.convert(self.distgit_branch, self.distgit_branch) return True except Exception as ex: self.result["error"] = f"ConvertError: {ex}" return False
def rebase_patches(ctx, gitdir: str, from_branch: str, to_branch: str): """Rebase FROM_BRANCH to TO_BRANCH With this commits corresponding to patches can be transferred to the TO_BRANCH. FROM_BRANCH is cleaned up (deleted). """ d2s = Dist2Src(dist_git_path=None, source_git_path=Path(gitdir), log_level=ctx.obj[VERBOSE_KEY]) d2s.rebase_patches(from_branch, to_branch)
def get_archive(ctx, gitdir: str): """Calls get_sources.sh in GITDIR. GITDIR needs to be a dist-git repository. Set DIST2SRC_GET_SOURCES to the path to git_sources.sh, if it's not in the PATH. """ d2s = Dist2Src(dist_git_path=Path(gitdir), source_git_path=None, log_level=ctx.obj[VERBOSE_KEY]) d2s.fetch_archive()
def test_pkg_name_when_paths_not_set(): with pytest.raises(RuntimeError) as exc: assert not Dist2Src(dist_git_path=None, source_git_path=None).package_name assert "I'm sorry but nor dist_git_path nor source_git_path are defined." in str( exc)
def update_project(self, project: GitlabProject, conversion_tag: str): self.cleanup() # Clone repo from rpms/ and checkout the branch. dist_git_repo = git.Repo.clone_from( f"https://{self.cfg.dist_git_host}/{self.fullname}.git", self.dist_git_dir ) dist_git_repo.git.checkout(self.branch) # Check if the commit is the one we are expecting. if dist_git_repo.branches[self.branch].commit.hexsha != self.end_commit: logger.warning( f"Abandon updating {self.name}. " f"HEAD of {self.branch!r} is not matching commit " f"{self.end_commit!r} for which this updated was started." ) Pushgateway().push_abandoned_update() return # Clone repo from source-git/ using ssh, so it can be pushed later on. src_git_ssh_url = project.get_git_urls()["ssh"] src_git_repo = git.Repo.clone_from( src_git_ssh_url, self.src_git_dir, ) # Check-out the source-git branch, if already exists, # so that 'convert' knows that this is an update. remote_heads = [ ref.remote_head for ref in src_git_repo.references if isinstance(ref, git.RemoteReference) ] if self.branch in remote_heads: src_git_repo.git.checkout(self.branch) d2s = Dist2Src( dist_git_path=self.dist_git_dir, source_git_path=self.src_git_dir, ) d2s.convert(self.branch, self.branch) try: src_git_repo.git.tag( "--annotate", "--message", f"Converted from commit {self.end_commit},\nfrom branch {self.branch}.", conversion_tag, src_git_repo.heads[self.branch].commit, ) except git.GitCommandError as ex: if "already exists" in ex.stderr: # It might happen that an another task already updated the repo. # If this is the case, do nothing. return else: raise # Push the result to source-git. # Update moves the upstream ref tag, we need --tags --force to move it in remote. src_git_repo.git.push("origin", self.branch, tags=True, force=True) Pushgateway().push_created_update()