Skip to content

Commit

Permalink
Make git-svn branch patterns match complete URL
Browse files Browse the repository at this point in the history
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 <ammon.riley@gmail.com>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
  • Loading branch information
Ammon Riley authored and Eric Wong committed Oct 5, 2012
1 parent a967cb1 commit 9478b11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion perl/Git/SVN/GlobSpec.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ sub new {
my $right = join('/', @right);
$re = join('/', @patterns);
$re = join('\/',
grep(length, quotemeta($left), "($re)", quotemeta($right)));
grep(length, quotemeta($left),
"($re)(?=/|\$)",
quotemeta($right)));
my $left_re = qr/^\/\Q$left\E(\/|$)/;
bless { left => $left, right => $right, left_regex => $left_re,
regex => qr/$re/, glob => $glob, depth => $depth }, $class;
Expand Down
9 changes: 9 additions & 0 deletions t/t9154-git-svn-fancy-glob.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ test_expect_success 'add red branch' "
test_must_fail git rev-parse refs/remotes/blue
"

test_expect_success 'add gre branch' "
GIT_CONFIG=.git/svn/.metadata git config --unset svn-remote.svn.branches-maxRev &&
git config svn-remote.svn.branches 'branches/{red,gre}:refs/remotes/*' &&
git svn fetch &&
git rev-parse refs/remotes/red &&
test_must_fail git rev-parse refs/remotes/green &&
test_must_fail git rev-parse refs/remotes/blue
"

test_expect_success 'add green branch' "
GIT_CONFIG=.git/svn/.metadata git config --unset svn-remote.svn.branches-maxRev &&
git config svn-remote.svn.branches 'branches/{red,green}:refs/remotes/*' &&
Expand Down

0 comments on commit 9478b11

Please sign in to comment.