diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/extracts_path.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index 6e4ed01e079..3f420553d42 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -55,12 +55,16 @@ module ExtractsPath valid_refs = @project.repository.ref_names valid_refs.select! { |v| id.start_with?("#{v}/") } - if valid_refs.length != 1 + if valid_refs.length == 0 # No exact ref match, so just try our best pair = id.match(/([^\/]+)(.*)/).captures else + # There is a distinct possibility that multiple refs prefix the ID. + # Use the longest match to maximize the chance that we have the + # right ref. + best_match = valid_refs.max_by(&:length) # 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(best_match)[1..-1] end end |