diff --git a/CHANGELOG.md b/CHANGELOG.md index cf677ff152..ef260ebf51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - add pre-commit hook to keep uv.lock in sync ([#3933](https://github.com/nf-core/tools/pull/3933)) - Fix quote handling in meta.yml ([#3948](https://github.com/nf-core/tools/pull/3948)) - Add support for SVG files in bump-version command ([#3978](https://github.com/nf-core/tools/pull/3978)) +- Escape original merge branch to compile regex ([#3984](https://github.com/nf-core/tools/pull/3984)) - handle type for val in topics correctly ([#3991](https://github.com/nf-core/tools/pull/3991)) - Update docker/login-action digest to c94ce9f ([#3998](https://github.com/nf-core/tools/pull/3998)) - fix wrong parsing when output values contain spaces ([#3999](https://github.com/nf-core/tools/pull/3999)) diff --git a/nf_core/pipelines/sync.py b/nf_core/pipelines/sync.py index 7ce358cd07..ee4dd1a8bf 100644 --- a/nf_core/pipelines/sync.py +++ b/nf_core/pipelines/sync.py @@ -371,7 +371,7 @@ def create_merge_base_branch(self): # Check if branch exists already branch_list = [b.name for b in self.repo.branches] if self.merge_branch in branch_list: - merge_branch_format = re.compile(rf"{self.original_merge_branch}-(\d+)") + merge_branch_format = re.compile(rf"{re.escape(self.original_merge_branch)}-(\d+)") max_branch = max( [1] + [ diff --git a/tests/pipelines/test_sync.py b/tests/pipelines/test_sync.py index 746b2db76a..b32f21d3ee 100644 --- a/tests/pipelines/test_sync.py +++ b/tests/pipelines/test_sync.py @@ -396,6 +396,27 @@ def test_create_merge_base_branch_thrice(self): for branch_no in [2, 3]: assert f"{psync.original_merge_branch}-{branch_no}" in psync.repo.branches + def test_create_merge_base_branch_with_special_characters(self): + """Test that branch names with regex special characters (like +) are handled correctly. + + This tests that the fix using re.escape() works properly when the version + contains characters that have special meaning in regex patterns (e.g., '+' in '3.6.0.dev0+local0'). + Without re.escape(), the '+' would be interpreted as a regex quantifier instead of a literal character. + """ + psync = nf_core.pipelines.sync.PipelineSync(self.pipeline_dir) + psync.inspect_sync_dir() + psync.get_wf_config() + + psync.original_merge_branch = "nf-core-template-merge-3.6.0.dev0+local0" + psync.merge_branch = psync.original_merge_branch + + for _ in range(3): + psync.create_merge_base_branch() + + assert psync.merge_branch in psync.repo.branches + for branch_no in [2, 3]: + assert f"{psync.original_merge_branch}-{branch_no}" in psync.repo.branches + def test_push_merge_branch(self): """Try pushing merge branch""" psync = nf_core.pipelines.sync.PipelineSync(self.pipeline_dir)