summaryrefslogtreecommitdiff
path: root/lib/extracts_path.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-06-21 08:26:37 -0700
committerStan Hu <stanhu@gmail.com>2015-07-01 07:01:59 -0700
commit9add3e6eb56bb8d8a9b8e4e105f7beec27e685d2 (patch)
treed0c34803d437a934aad6833d5b9733eda5192c45 /lib/extracts_path.rb
parent3603edcff4d18ae0341213d7151325dda04aa9b3 (diff)
downloadgitlab-ce-9add3e6eb56bb8d8a9b8e4e105f7beec27e685d2.tar.gz
Extract the longest-matching ref from a commit path when multiple matches occur
Closes #1839
Diffstat (limited to 'lib/extracts_path.rb')
-rw-r--r--lib/extracts_path.rb8
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