diff --git a/dist-git/copr_dist_git/package_import.py b/dist-git/copr_dist_git/package_import.py index 38eb11871..d81197a96 100644 --- a/dist-git/copr_dist_git/package_import.py +++ b/dist-git/copr_dist_git/package_import.py @@ -148,25 +148,7 @@ def cleanup_repo(repo_path): ['git', 'rm', '-r'] + to_remove) -def import_package(opts, namespace, branches, srpm_path, pkg_name): - """ - Import package into a DistGit repo for the given branches. - - :param Munch opts: service configuration - :param str namespace: repo name prefix - :param list(str) branches: list of branch names to import into - :param str srpm_path: path to the srpm file - - :return Munch: resulting import data: - (branch_commits, reponame, pkg_name) - """ - - reponame = "{}/{}".format(namespace, pkg_name) - setup_git_repo(reponame, branches) - - repo_dir = tempfile.mkdtemp() - log.debug("repo_dir: {}".format(repo_dir)) - +def _load_commands(opts, repo_name, repo_dir): # use rpkg lib to import the source rpm commands = Commands(path=repo_dir, lookaside="", @@ -181,12 +163,35 @@ def import_package(opts, namespace, branches, srpm_path, pkg_name): # rpkg gets module_name as a basename of git url # we use module_name as "username/projectname/package_name" # basename is not working here - so I'm setting it manually - commands.repo_name = reponame + commands.repo_name = repo_name # rpkg calls upload.cgi script on the dist git server # here, I just copy the source files manually with custom function # I also add one parameter "repo_dir" to that function with this hack commands.lookasidecache.upload = types.MethodType(my_upload_fabric(opts), repo_dir) + return commands + + +def import_package(opts, namespace, branches, srpm_path, pkg_name): + """ + Import package into a DistGit repo for the given branches. + + :param Munch opts: service configuration + :param str namespace: repo name prefix + :param list(str) branches: list of branch names to import into + :param str srpm_path: path to the srpm file + + :return Munch: resulting import data: + (branch_commits, reponame, pkg_name) + """ + + reponame = "{}/{}".format(namespace, pkg_name) + setup_git_repo(reponame, branches) + + repo_dir = tempfile.mkdtemp() + log.debug("repo_dir: {}".format(repo_dir)) + + commands = _load_commands(opts, reponame, repo_dir) try: log.debug("clone the pkg repository into repo_dir directory") @@ -218,6 +223,15 @@ def import_package(opts, namespace, branches, srpm_path, pkg_name): try: if not branch_commits: upload_files = commands.import_srpm(srpm_path) + # in case of importing, the content of directory in `reponame` + # changes. To update the state of `Commands` class isn't an easy + # process - look how much logic pyrpkg.cli.cliClient.load_cmd has + # and the logic is written for context in cliClient, not for Commands + # which we are using. Considering this wouldn't be an easy task for + # pyrpkg to implement, we can refresh the Commands class after every + # import - even if it is not elegant + # note: if https://pagure.io/rpkg/issue/690 is resolved, you may delete this + commands = _load_commands(opts, reponame, repo_dir) if upload_files: commands.upload(upload_files, replace=True) try: diff --git a/dist-git/tests/test_crazy_merging.py b/dist-git/tests/test_crazy_merging.py index c2be93169..48575ae85 100644 --- a/dist-git/tests/test_crazy_merging.py +++ b/dist-git/tests/test_crazy_merging.py @@ -189,7 +189,6 @@ def commit_to_branches(self, to_branches, opts, version): def setup_method(self, method): srpm_cache = {} - @pytest.mark.skip(reason="Remove the skip once python-rpkg is repared (correct version is 1.65)") def test_merged_everything(self, initial_commit_everywhere, mc_setup_git_repo): branches, opts, v1_hash = initial_commit_everywhere origin, all_branches, middle_branches, border_branches = branches @@ -209,7 +208,6 @@ def test_merged_everything(self, initial_commit_everywhere, mc_setup_git_repo): assert v3_hash != v1_hash assert v3_hash != v2_hash - @pytest.mark.skip(reason="Remove the skip once python-rpkg is repared (correct version is 1.65)") def test_diverge_middle_branches(self, initial_commit_everywhere, mc_setup_git_repo): branches, opts, v1_hash = initial_commit_everywhere origin, all_branches, middle_branches, border_branches = branches