summaryrefslogtreecommitdiff
path: root/lib/api/helpers/internal_helpers.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/helpers/internal_helpers.rb')
-rw-r--r--lib/api/helpers/internal_helpers.rb34
1 files changed, 19 insertions, 15 deletions
diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb
index 69b53ea6c2f..12b0a053e79 100644
--- a/lib/api/helpers/internal_helpers.rb
+++ b/lib/api/helpers/internal_helpers.rb
@@ -31,8 +31,7 @@ module API
def access_checker_for(actor, protocol)
access_checker_klass.new(actor.key_or_user, container, protocol,
authentication_abilities: ssh_authentication_abilities,
- namespace_path: namespace_path,
- repository_path: project_path,
+ repository_path: repository_path,
redirected_path: redirected_path)
end
@@ -71,18 +70,22 @@ module API
false
end
- def project_path
- project&.path || project_path_match[:project_path]
- end
-
- def namespace_path
- project&.namespace&.full_path || project_path_match[:namespace_path]
- end
-
private
- def project_path_match
- @project_path_match ||= params[:project].match(Gitlab::PathRegex.full_project_git_path_regex) || {}
+ def repository_path
+ if container
+ "#{container.full_path}.git"
+ elsif params[:project]
+ # When the project doesn't exist, we still need to pass on the path
+ # to support auto-creation in `GitAccessProject`.
+ #
+ # For consistency with the Git HTTP controllers, we normalize the path
+ # to remove a leading slash and ensure a trailing `.git`.
+ #
+ # NOTE: For GitLab Shell, `params[:project]` is the full repository path
+ # from the SSH command, with an optional trailing `.git`.
+ "#{params[:project].delete_prefix('/').delete_suffix('.git')}.git"
+ end
end
# rubocop:disable Gitlab/ModuleWithInstanceVariables
@@ -96,7 +99,7 @@ module API
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
- # Project id to pass between components that don't share/don't have
+ # Repository id to pass between components that don't share/don't have
# access to the same filesystem mounts
def gl_repository
repo_type.identifier_for_container(container)
@@ -106,8 +109,9 @@ module API
repository.full_path
end
- # Return the repository depending on whether we want the wiki or the
- # regular repository
+ # Return the repository for the detected type and container
+ #
+ # @returns [Repository]
def repository
@repository ||= repo_type.repository_for(container)
end