Mirror branches and tags with slashes in their name - #30
Merged
Conversation
1.3.0 excluded the heads/tags namespaces with a glob (`refs/heads/*`), but git for-each-ref matches patterns path-aware: `*` does not cross a `/`, so a ref like `refs/heads/feature/foo` was not excluded and got deleted before the push — silently dropping any branch or tag with a slash in its name. Drop the glob and exclude the bare namespaces (`refs/heads`, `refs/tags`), which match the whole hierarchy including nested refs. The CI test is extended with a nested branch and tag to cover this: it would pass against the buggy script (which drops them without error) only because the old assertion just checked for the single-level refs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
1.3.0 (#28) stopped mirroring branches and tags whose names contain a slash, e.g.
feature/fooorrelease/1.0.0. Reported in #27.The whitelist step excluded the heads/tags namespaces with a glob:
git for-each-refmatches patterns path-aware:*does not cross a/. Sorefs/heads/*matchesrefs/heads/mainbut notrefs/heads/feature/foo. The nested ref was therefore not excluded, got deleted before the push, and silently disappeared from the mirror (no error — the push still succeeded).Fix
Exclude the bare namespaces without a glob. A pattern without wildcards is matched literally "completely or from the beginning up to a slash", i.e. it matches the whole hierarchy including nested refs:
Test
The existing CI test only used single-level refs (
main,v1), so it passed against the buggy script — the bug was invisible. This PR adds a nested branch (feature/foo) and tag (release/1.0.0) to the fixture and asserts the exact destination ref set, so a regression here fails the job.Verified locally: the hardened test passes on this fix and fails on 1.3.0.
Fixes #27.