summaryrefslogtreecommitdiff
path: root/app/controllers/projects
diff options
context:
space:
mode:
authorJames Ramsay <james@jramsay.com.au>2018-02-19 15:41:04 -0500
committerJames Ramsay <james@jramsay.com.au>2018-04-06 08:45:17 -0400
commit07f517d441ab8782286b4a59d56a630393d75e16 (patch)
treed388461feb28fbed2b5c6f52303c7eb7b0f633e3 /app/controllers/projects
parent0b1b9c409d3adbf4517351dbb9037ed053f73e67 (diff)
downloadgitlab-ce-07f517d441ab8782286b4a59d56a630393d75e16.tar.gz
Add new repository archive route
Repository archives are always named `<project>-<ref>-<sha>` even if the ref is a commit. A consequence of always including the sha even for tags is that packaging a release is more difficult because both the ref and sha must be known by the packager. - add `<project>/-/archive/<ref>/<filename>.<format>` route using the `-` separator to prevent namespace collisions. If the filename is `<project>-<ref>` or the ref is a sha, the sha will be omitted, otherwise the default filename will be used. - deprecate previous archive route `repository/<ref>/archive`
Diffstat (limited to 'app/controllers/projects')
-rw-r--r--app/controllers/projects/repositories_controller.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/controllers/projects/repositories_controller.rb b/app/controllers/projects/repositories_controller.rb
index d5af0341d18..a6167e9dc6c 100644
--- a/app/controllers/projects/repositories_controller.rb
+++ b/app/controllers/projects/repositories_controller.rb
@@ -1,6 +1,9 @@
class Projects::RepositoriesController < Projects::ApplicationController
+ include ExtractsPath
+
# Authorize
before_action :require_non_empty_project, except: :create
+ before_action :assign_archive_vars, only: :archive
before_action :authorize_download_code!
before_action :authorize_admin_project!, only: :create
@@ -11,9 +14,21 @@ class Projects::RepositoriesController < Projects::ApplicationController
end
def archive
- send_git_archive @repository, ref: params[:ref], format: params[:format]
+ append_sha = params[:append_sha]
+
+ shortname = "#{@project.path}-#{@ref.tr('/', '-')}"
+ append_sha = false if @filename == shortname
+
+ send_git_archive @repository, ref: @ref, format: params[:format], append_sha: append_sha
rescue => ex
logger.error("#{self.class.name}: #{ex}")
return git_not_found!
end
+
+ def assign_archive_vars
+ @id = params[:id]
+ @ref, @filename = extract_ref(@id)
+ rescue InvalidPathError
+ render_404
+ end
end