fix situation when valid ref is a part of path
should take 1st match
ensure ref name is encoded
Merge pull request #230 from vognev/fix-ref-name-in-path

fix situation when valid ref is a part of path