diff --git a/nf_core/download.py b/nf_core/download.py index 7bbb22f32..976472a1c 100644 --- a/nf_core/download.py +++ b/nf_core/download.py @@ -1736,17 +1736,22 @@ def __add_additional_tags(self) -> None: if self.repo.is_valid_object(anchor) and not self.repo.is_valid_object(tag): try: self.repo.create_tag( - tag, ref=anchor, message=f"Synonynmous tag to {anchor}; added by 'nf-core download'." + tag, ref=anchor, message=f"Synonynmous tag to {anchor}; added by `nf-core download`." ) self.repo.create_head(tag, anchor) # should heads be created as well? except (GitCommandError, InvalidGitRepositoryError) as e: log.error(f"[red]Additional tag(s) could not be applied:[/]\n{e}\n") else: - log.error( - f"[red]Adding the additional tag '{tag}' to '{anchor}' failed.[/]\n Mind that '{anchor}' must be a valid git reference that resolves to a commit, while '{tag}' must not exist hitherto." - ) + if not self.repo.is_valid_object(anchor): + log.error( + f"[red]Adding tag '{tag}' to '{anchor}' failed.[/]\n Mind that '{anchor}' must be a valid git reference that resolves to a commit." + ) + if self.repo.is_valid_object(tag): + log.error( + f"[red]Adding tag '{tag}' to '{anchor}' failed.[/]\n Mind that '{tag}' must not exist hitherto." + ) else: - log.error(f"[red]Could not apply invalid '--tag' specification[/]: '{additional_tag}'") + log.error(f"[red]Could not apply invalid `--tag` specification[/]: '{additional_tag}'") def bare_clone(self, destination): if self.repo: diff --git a/tests/test_download.py b/tests/test_download.py index 589fe6eda..3e0f11d57 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -645,7 +645,23 @@ def test_download_workflow_for_platform(self, tmp_dir, _): ) # indirect definition via $container variable. # - # Test adding custom tags to Seqera Platform download + # Brief test adding a single custom tag to Seqera Platform download + # + @mock.patch("nf_core.download.DownloadWorkflow.get_singularity_images") + @with_temporary_folder + def test_download_workflow_for_platform_with_one_custom_tag(self, _, tmp_dir): + download_obj = DownloadWorkflow( + pipeline="nf-core/rnaseq", + revision=("3.9"), + compress_type="none", + platform=True, + container_system=None, + additional_tags=("3.9=cool_revision",), + ) + assert isinstance(download_obj.additional_tags, list) and len(download_obj.additional_tags) == 1 + + # + # Test adding custom tags to Seqera Platform download (full test) # @mock.patch("nf_core.download.DownloadWorkflow.get_singularity_images") @with_temporary_folder @@ -707,21 +723,8 @@ def test_download_workflow_for_platform_with_custom_tags(self, _, tmp_dir): assert all( log in self.logged_messages for log in { - "[red]Could not apply invalid '-a' / '--additional-tag' specification[/]: '3.9=invalid tag'", - "[red]Adding the additional tag 'not_included' to '3.14.0' failed.[/]\n Mind that '3.14.0' must be a valid git reference that resolves to a commit, while 'not_included' must not exist hitherto.", - "[red]Could not apply invalid '-a' / '--additional-tag' specification[/]: 'What is this?'", + "[red]Could not apply invalid `--tag` specification[/]: '3.9=invalid tag'", + "[red]Adding tag 'not_included' to '3.14.0' failed.[/]\n Mind that '3.14.0' must be a valid git reference that resolves to a commit.", + "[red]Could not apply invalid `--tag` specification[/]: 'What is this?'", } ) - - @mock.patch("nf_core.download.DownloadWorkflow.get_singularity_images") - @with_temporary_folder - def test_download_workflow_for_platform_with_one_custom_tag(self, _, tmp_dir): - download_obj = DownloadWorkflow( - pipeline="nf-core/rnaseq", - revision=("3.9"), - compress_type="none", - platform=True, - container_system=None, - additional_tags=("3.9=cool_revision",), - ) - assert isinstance(download_obj.additional_tags, list) and len(download_obj.additional_tags) == 1