Skip to content

Commit 9478b11

Browse files
ammonrileyEric Wong
authored andcommitted
Make git-svn branch patterns match complete URL
When using the {word,[...]} style of configuration for tags and branches, it appears the intent is to only match whole path parts, since the words in the {} pattern are meta-character quoted. When the pattern word appears in the beginning or middle of the url, it's matched completely, since the left side, pattern, and (non-empty) right side are joined together with path separators. However, when the pattern word appears at the end of the URL, the right side is an empty pattern, and the resulting regex matches more than just the specified pattern. For example, if you specify something along the lines of branches = branches/project/{release_1,release_2} and your repository also contains "branches/project/release_1_2", you will also get the release_1_2 branch. By restricting the match regex with anchors, this is avoided. Signed-off-by: Ammon Riley <[email protected]> Signed-off-by: Eric Wong <[email protected]>
1 parent a967cb1 commit 9478b11

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

perl/Git/SVN/GlobSpec.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ sub new {
4444
my $right = join('/', @right);
4545
$re = join('/', @patterns);
4646
$re = join('\/',
47-
grep(length, quotemeta($left), "($re)", quotemeta($right)));
47+
grep(length, quotemeta($left),
48+
"($re)(?=/|\$)",
49+
quotemeta($right)));
4850
my $left_re = qr/^\/\Q$left\E(\/|$)/;
4951
bless { left => $left, right => $right, left_regex => $left_re,
5052
regex => qr/$re/, glob => $glob, depth => $depth }, $class;

t/t9154-git-svn-fancy-glob.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ test_expect_success 'add red branch' "
2121
test_must_fail git rev-parse refs/remotes/blue
2222
"
2323

24+
test_expect_success 'add gre branch' "
25+
GIT_CONFIG=.git/svn/.metadata git config --unset svn-remote.svn.branches-maxRev &&
26+
git config svn-remote.svn.branches 'branches/{red,gre}:refs/remotes/*' &&
27+
git svn fetch &&
28+
git rev-parse refs/remotes/red &&
29+
test_must_fail git rev-parse refs/remotes/green &&
30+
test_must_fail git rev-parse refs/remotes/blue
31+
"
32+
2433
test_expect_success 'add green branch' "
2534
GIT_CONFIG=.git/svn/.metadata git config --unset svn-remote.svn.branches-maxRev &&
2635
git config svn-remote.svn.branches 'branches/{red,green}:refs/remotes/*' &&

0 commit comments

Comments
 (0)