Commit e25ddca0 authored by Valeriy Sizov's avatar Valeriy Sizov

Fix bug with branches whose name contains slash

parent 73d5e51a
...@@ -56,22 +56,22 @@ module ExtractsPath ...@@ -56,22 +56,22 @@ module ExtractsPath
# Append a trailing slash if we only get a ref and no file path # Append a trailing slash if we only get a ref and no file path
id = input id = input
id += '/' unless id.include?('/') id += '/' unless id.ends_with?('/')
valid_refs = @project.branches + @project.tags valid_refs = @project.branches + @project.tags
valid_refs.select! { |v| id.start_with?("#{v}/") } valid_refs.select! { |v| id.start_with?("#{v.name}/") }
if valid_refs.length != 1 if valid_refs.length != 1
# No exact ref match, so just try our best # No exact ref match, so just try our best
pair = id.match(/([^\/]+)(.*)/).captures pair = id.match(/([^\/]+)(.*)/).captures
else else
# Partition the string into the ref and the path, ignoring the empty first value # Partition the string into the ref and the path, ignoring the empty first value
pair = id.partition(valid_refs.first)[1..-1] pair = id.partition(valid_refs.first.name)[1..-1]
end end
end end
# Remove leading slash from path # Remove ending slashes from path
pair[1].gsub!(/^\//, '') pair[1].gsub!(/^\/|\/$/, '')
pair pair
end end
......
...@@ -7,8 +7,8 @@ describe ExtractsPath do ...@@ -7,8 +7,8 @@ describe ExtractsPath do
before do before do
@project = project @project = project
project.stub(:branches).and_return(['master', 'foo/bar/baz']) project.stub(:branches).and_return([stub(name: 'master'), stub(name: 'foo/bar/baz')])
project.stub(:tags).and_return(['v1.0.0', 'v2.0.0']) project.stub(:tags).and_return([stub(name: 'master'), stub(name: 'master')])
end end
describe '#extract_ref' do describe '#extract_ref' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment