Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Privacy
Imprint
Contact
Login methods
Sign in
Toggle navigation
Menu
Open sidebar
projects.thm.de
GitLab
Commits
c8ba5c2d
Commit
c8ba5c2d
authored
Dec 25, 2012
by
Dmitriy Zaporozhets
Browse files
Fix routing issues when navigating over tree, commits etc
parent
49e73f8a
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/helpers/commits_helper.rb
View file @
c8ba5c2d
...
...
@@ -70,4 +70,12 @@ def commit_to_html commit
escape_javascript
(
render
'commits/commit'
,
commit:
commit
)
end
end
def
diff_line_content
(
line
)
if
line
.
blank?
" "
else
line
end
end
end
app/models/project.rb
View file @
c8ba5c2d
...
...
@@ -102,7 +102,7 @@ def find_with_namespace(id)
if
id
.
include?
(
"/"
)
id
=
id
.
split
(
"/"
)
namespace_id
=
Namespace
.
find_by_path
(
id
.
first
).
id
where
(
namespace_id:
namespace_id
).
find_by_path
(
id
.
last
)
where
(
namespace_id:
namespace_id
).
find_by_path
(
id
.
second
)
else
where
(
path:
id
,
namespace_id:
nil
).
last
end
...
...
app/views/commits/_text_file.html.haml
View file @
c8ba5c2d
...
...
@@ -15,7 +15,7 @@
-
if
@comments_allowed
=
render
"notes/per_line_note_link"
,
line_code:
line_code
%td
.new_line
=
link_to
raw
(
type
==
"old"
?
" "
:
line_new
)
,
"#
#{
line_code
}
"
,
id:
line_code
%td
.line_content
{
class:
"noteable_line #{type} #{line_code}"
,
"line_code"
=>
line_code
}=
raw
"
#{
line
}
"
%td
.line_content
{
class:
"noteable_line #{type} #{line_code}"
,
"line_code"
=>
line_code
}=
raw
diff_line_content
(
line
)
-
if
@comments_allowed
-
comments
=
@line_notes
.
select
{
|
n
|
n
.
line_code
==
line_code
}.
sort_by
(
&
:created_at
)
...
...
config/routes.rb
View file @
c8ba5c2d
...
...
@@ -112,7 +112,7 @@
#
# Project Area
#
resources
:projects
,
constraints:
{
id:
/[a-zA-Z.
\/
0-9_\-]+/
},
except:
[
:new
,
:create
,
:index
],
path:
"/"
do
resources
:projects
,
constraints:
{
id:
/[a-zA-Z.0-9_\-
\/
]+/
},
except:
[
:new
,
:create
,
:index
],
path:
"/"
do
member
do
get
"wall"
get
"graph"
...
...
@@ -190,12 +190,12 @@
end
end
resources
:tree
,
only:
[
:show
,
:edit
,
:update
],
constraints:
{
id:
/.+/
}
resources
:commit
,
only:
[
:show
],
constraints:
{
id:
/[[:alnum:]]{6,40}/
}
resources
:commits
,
only:
[
:show
],
constraints:
{
id:
/.+/
}
resources
:compare
,
only:
[
:index
,
:create
]
resources
:blame
,
only:
[
:show
],
constraints:
{
id:
/.+/
}
resources
:blob
,
only:
[
:show
],
constraints:
{
id:
/.+/
}
resources
:tree
,
only:
[
:show
,
:edit
,
:update
],
constraints:
{
id:
/.+/
}
match
"/compare/:from...:to"
=>
"compare#show"
,
as:
"compare"
,
:via
=>
[
:get
,
:post
],
constraints:
{
from:
/.+/
,
to:
/.+/
}
...
...
lib/extracts_path.rb
View file @
c8ba5c2d
...
...
@@ -33,6 +33,9 @@ class InvalidPathError < StandardError; end
# extract_ref("v2.0.0/README.md")
# # => ['v2.0.0', 'README.md']
#
# extract_ref('/gitlab/vagrant/tree/master/app/models/project.rb')
# # => ['master', 'app/models/project.rb']
#
# extract_ref('issues/1234/app/models/project.rb')
# # => ['issues/1234', 'app/models/project.rb']
#
...
...
@@ -47,6 +50,13 @@ def extract_ref(input)
return
pair
unless
@project
# Remove project, actions and all other staff from path
input
.
gsub!
(
"/
#{
@project
.
path_with_namespace
}
"
,
""
)
input
.
gsub!
(
/^\/(tree|commits|blame|blob)\//
,
""
)
# remove actions
input
.
gsub!
(
/\?.*$/
,
""
)
# remove stamps suffix
input
.
gsub!
(
/.atom$/
,
""
)
# remove rss feed
input
.
gsub!
(
/\/edit$/
,
""
)
# remove edit route part
if
input
.
match
(
/^([[:alnum:]]{40})(.+)/
)
# If the ref appears to be a SHA, we're done, just split the string
pair
=
$~
.
captures
...
...
@@ -98,7 +108,7 @@ def assign_ref_vars
request
.
format
=
:atom
end
@ref
,
@path
=
extract_ref
(
params
[
:id
]
)
@ref
,
@path
=
extract_ref
(
request
.
fullpath
)
@id
=
File
.
join
(
@ref
,
@path
)
...
...
spec/lib/extracts_path_spec.rb
View file @
c8ba5c2d
...
...
@@ -8,6 +8,7 @@
before
do
@project
=
project
project
.
stub
(
:ref_names
).
and_return
([
'master'
,
'foo/bar/baz'
,
'v1.0.0'
,
'v2.0.0'
])
project
.
stub
(
path_with_namespace:
'gitlab/gitlab-ci'
)
end
describe
'#extract_ref'
do
...
...
@@ -53,5 +54,24 @@
extract_ref
(
'stable/CHANGELOG'
).
should
==
[
'stable'
,
'CHANGELOG'
]
end
end
context
"with a fullpath"
do
it
"extracts a valid branch"
do
extract_ref
(
'/gitlab/gitlab-ci/tree/foo/bar/baz/CHANGELOG'
).
should
==
[
'foo/bar/baz'
,
'CHANGELOG'
]
end
it
"extracts a valid tag"
do
extract_ref
(
'/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG'
).
should
==
[
'v2.0.0'
,
'CHANGELOG'
]
end
it
"extracts a valid commit SHA"
do
extract_ref
(
'/gitlab/gitlab-ci/tree/f4b14494ef6abf3d144c28e4af0c20143383e062/CHANGELOG'
).
should
==
[
'f4b14494ef6abf3d144c28e4af0c20143383e062'
,
'CHANGELOG'
]
end
it
"extracts a timestamp"
do
extract_ref
(
'/gitlab/gitlab-ci/tree/v2.0.0/CHANGELOG?_=12354435'
).
should
==
[
'v2.0.0'
,
'CHANGELOG'
]
end
end
end
end
spec/tasks/gitlab/backup_rake_spec.rb
View file @
c8ba5c2d
...
...
@@ -3,6 +3,7 @@
describe
'gitlab:app namespace rake task'
do
before
:all
do
Rake
.
application
.
rake_require
"tasks/gitlab/task_helpers"
Rake
.
application
.
rake_require
"tasks/gitlab/backup"
# empty task as env is already loaded
Rake
::
Task
.
define_task
:environment
...
...
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