Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
projects.thm.de
GitLab
Commits
9add3e6e
Commit
9add3e6e
authored
Jun 21, 2015
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract the longest-matching ref from a commit path when multiple matches occur
Closes #1839
parent
3603edcf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
4 deletions
+16
-4
CHANGELOG
CHANGELOG
+1
-0
lib/extracts_path.rb
lib/extracts_path.rb
+6
-2
spec/lib/extracts_path_spec.rb
spec/lib/extracts_path_spec.rb
+9
-2
No files found.
CHANGELOG
View file @
9add3e6e
...
...
@@ -10,6 +10,7 @@ v 7.13.0 (unreleased)
- Fix downloading of patches on public merge requests when user logged out (Stan Hu)
- The password for the default administrator (root) account has been changed from "5iveL!fe" to "password".
- Fix Error 500 when relative submodule resolves to a namespace that has a different name from its path (Stan Hu)
- Extract the longest-matching ref from a commit path when multiple matches occur (Stan Hu)
- Update maintenance documentation to explain no need to recompile asssets for omnibus installations (Stan Hu)
- Support commenting on diffs in side-by-side mode (Stan Hu)
- Fix JavaScript error when clicking on the comment button on a diff line that has a comment already (Stan Hu)
...
...
lib/extracts_path.rb
View file @
9add3e6e
...
...
@@ -55,12 +55,16 @@ def extract_ref(id)
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
...
...
spec/lib/extracts_path_spec.rb
View file @
9add3e6e
...
...
@@ -10,7 +10,8 @@
before
do
@project
=
project
repo
=
double
(
ref_names:
[
'master'
,
'foo/bar/baz'
,
'v1.0.0'
,
'v2.0.0'
])
repo
=
double
(
ref_names:
[
'master'
,
'foo/bar/baz'
,
'v1.0.0'
,
'v2.0.0'
,
'release/app'
,
'release/app/v1.0.0'
])
allow
(
project
).
to
receive
(
:repository
).
and_return
(
repo
)
allow
(
project
).
to
receive
(
:path_with_namespace
).
and_return
(
'gitlab/gitlab-ci'
)
...
...
@@ -54,11 +55,17 @@
it
"falls back to a primitive split for an invalid ref"
do
expect
(
extract_ref
(
'stable'
)).
to
eq
([
'stable'
,
''
])
end
it
"extracts the longest matching ref"
do
expect
(
extract_ref
(
'release/app/v1.0.0/README.md'
)).
to
eq
(
[
'release/app/v1.0.0'
,
'README.md'
])
end
end
context
"with a path"
do
it
"extracts a valid branch"
do
expect
(
extract_ref
(
'foo/bar/baz/CHANGELOG'
)).
to
eq
([
'foo/bar/baz'
,
'CHANGELOG'
])
expect
(
extract_ref
(
'foo/bar/baz/CHANGELOG'
)).
to
eq
(
[
'foo/bar/baz'
,
'CHANGELOG'
])
end
it
"extracts a valid tag"
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment