Search code examples
regexgitolite

Match repository names with regex


Some of my repositories share a naming convention and thus have the same ending, e.g

tools2
subdirectory/tools2
subdirectory/etc/tools2

I want to match these repositories with a single regex (if possible) in my gitolite conf file.

@tools_repos = .*tools2

When I try to push this change, it gives me an error

FATAL: bad expansion '.*tools'

If I understand correctly my pattern needs to be a subset of

$REPONAME_PATT        =  qr(^\@?[0-9a-zA-Z][-0-9a-zA-Z._\@/+]*$);
$REPOPATT_PATT        = qr(^\@?[[0-9a-zA-Z][-0-9a-zA-Z._\@/+\\^$|()[\]*?{},]*$);

Reading the documentation I came up with this regex

[a-zA-Z0-9].*tools2

but this solution does not match

tools2

Is there a simple way to match the repositories with a single regex?


Solution

  • If '?' is supported, you can try:

     [a-zA-Z0-9]?.*?tools2
     # or
     [a-zA-Z0-9].*?t?ools2 (suggested by HamZa)
    

    Maybe the non-greedy form would allow for tools2 to be matched.

    The OP prakti reports this seems to work:

     [a-zA-Z0-9]?.*tools2