2020-01-24 13:09:00 -05:00
|
|
|
concern :gitactionable do
|
|
|
|
scope(controller: :git_http) do
|
|
|
|
get '/info/refs', action: :info_refs
|
|
|
|
post '/git-upload-pack', action: :git_upload_pack
|
|
|
|
post '/git-receive-pack', action: :git_receive_pack
|
|
|
|
end
|
|
|
|
end
|
2016-11-07 10:14:34 -05:00
|
|
|
|
2020-01-24 13:09:00 -05:00
|
|
|
concern :lfsable do
|
|
|
|
# Git LFS API (metadata)
|
|
|
|
scope(path: 'info/lfs/objects', controller: :lfs_api) do
|
|
|
|
post :batch
|
|
|
|
post '/', action: :deprecated
|
|
|
|
get '/*oid', action: :deprecated
|
|
|
|
end
|
2016-11-07 10:14:34 -05:00
|
|
|
|
2020-01-24 13:09:00 -05:00
|
|
|
scope(path: 'info/lfs') do
|
|
|
|
resources :lfs_locks, controller: :lfs_locks_api, path: 'locks' do
|
|
|
|
post :unlock, on: :member
|
|
|
|
post :verify, on: :collection
|
2018-02-07 08:00:53 -05:00
|
|
|
end
|
2020-01-24 13:09:00 -05:00
|
|
|
end
|
2018-02-07 08:00:53 -05:00
|
|
|
|
2020-01-24 13:09:00 -05:00
|
|
|
# GitLab LFS object storage
|
|
|
|
scope(path: 'gitlab-lfs/objects/*oid', controller: :lfs_storage, constraints: { oid: /[a-f0-9]{64}/ }) do
|
|
|
|
get '/', action: :download
|
2016-11-07 10:14:34 -05:00
|
|
|
|
2020-01-24 13:09:00 -05:00
|
|
|
scope constraints: { size: /[0-9]+/ } do
|
|
|
|
put '/*size/authorize', action: :upload_authorize
|
|
|
|
put '/*size', action: :upload_finalize
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-04 19:07:49 -05:00
|
|
|
# Git route for personal and project snippets
|
|
|
|
scope(path: ':namespace_id/:repository_id',
|
|
|
|
format: nil,
|
|
|
|
constraints: { namespace_id: Gitlab::PathRegex.personal_and_project_snippets_path_regex, repository_id: /\d+\.git/ },
|
|
|
|
module: :repositories) do
|
|
|
|
concerns :gitactionable
|
|
|
|
end
|
|
|
|
|
2020-01-24 13:09:00 -05:00
|
|
|
scope(path: '*namespace_id/:repository_id',
|
|
|
|
format: nil,
|
|
|
|
constraints: { namespace_id: Gitlab::PathRegex.full_namespace_route_regex }) do
|
|
|
|
scope(constraints: { repository_id: Gitlab::PathRegex.project_git_route_regex }) do
|
|
|
|
scope(module: :repositories) do
|
|
|
|
concerns :gitactionable
|
|
|
|
concerns :lfsable
|
2016-11-07 10:14:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-23 21:53:06 -04:00
|
|
|
# Redirect /group/project.wiki.git to the project wiki
|
2020-01-24 13:09:00 -05:00
|
|
|
scope(format: true, constraints: { repository_id: Gitlab::PathRegex.project_wiki_git_route_regex, format: :git }) do
|
2019-07-23 21:53:06 -04:00
|
|
|
wiki_redirect = redirect do |params, request|
|
2020-01-24 13:09:00 -05:00
|
|
|
project_id = params[:repository_id].delete_suffix('.wiki')
|
2019-07-23 21:53:06 -04:00
|
|
|
path = [params[:namespace_id], project_id, 'wikis'].join('/')
|
|
|
|
path << "?#{request.query_string}" unless request.query_string.blank?
|
|
|
|
path
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/', to: wiki_redirect
|
|
|
|
end
|
|
|
|
|
2016-11-14 09:55:31 -05:00
|
|
|
# Redirect /group/project/info/refs to /group/project.git/info/refs
|
2020-01-24 13:09:00 -05:00
|
|
|
scope(constraints: { repository_id: Gitlab::PathRegex.project_route_regex }) do
|
2016-11-14 09:55:31 -05:00
|
|
|
# Allow /info/refs, /info/refs?service=git-upload-pack, and
|
|
|
|
# /info/refs?service=git-receive-pack, but nothing else.
|
|
|
|
#
|
|
|
|
git_http_handshake = lambda do |request|
|
2019-11-08 10:06:21 -05:00
|
|
|
::Constraints::ProjectUrlConstrainer.new.matches?(request, existence_check: false) &&
|
2016-11-14 09:55:31 -05:00
|
|
|
(request.query_string.blank? ||
|
|
|
|
request.query_string.match(/\Aservice=git-(upload|receive)-pack\z/))
|
|
|
|
end
|
2016-11-07 10:14:34 -05:00
|
|
|
|
2016-11-14 09:55:31 -05:00
|
|
|
ref_redirect = redirect do |params, request|
|
2020-01-24 13:09:00 -05:00
|
|
|
path = "#{params[:namespace_id]}/#{params[:repository_id]}.git/info/refs"
|
2016-11-14 09:55:31 -05:00
|
|
|
path << "?#{request.query_string}" unless request.query_string.blank?
|
|
|
|
path
|
|
|
|
end
|
2016-11-07 10:14:34 -05:00
|
|
|
|
2016-11-14 09:55:31 -05:00
|
|
|
get '/info/refs', constraints: git_http_handshake, to: ref_redirect
|
|
|
|
end
|
|
|
|
end
|