2013-06-23 12:47:22 -04:00
|
|
|
class Projects::RepositoriesController < Projects::ApplicationController
|
2018-02-19 15:41:04 -05:00
|
|
|
include ExtractsPath
|
|
|
|
|
2011-12-30 15:56:13 -05:00
|
|
|
# Authorize
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :require_non_empty_project, except: :create
|
2018-02-19 15:41:04 -05:00
|
|
|
before_action :assign_archive_vars, only: :archive
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :authorize_download_code!
|
|
|
|
before_action :authorize_admin_project!, only: :create
|
2014-11-29 17:50:25 -05:00
|
|
|
|
|
|
|
def create
|
|
|
|
@project.create_repository
|
|
|
|
|
2015-02-25 22:34:16 -05:00
|
|
|
redirect_to project_path(@project)
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
2011-12-30 15:56:13 -05:00
|
|
|
|
2012-02-07 18:00:49 -05:00
|
|
|
def archive
|
2018-02-19 15:41:04 -05:00
|
|
|
append_sha = params[:append_sha]
|
|
|
|
|
2018-04-08 08:47:54 -04:00
|
|
|
if @ref
|
|
|
|
shortname = "#{@project.path}-#{@ref.tr('/', '-')}"
|
|
|
|
append_sha = false if @filename == shortname
|
|
|
|
end
|
2018-02-19 15:41:04 -05:00
|
|
|
|
|
|
|
send_git_archive @repository, ref: @ref, format: params[:format], append_sha: append_sha
|
2015-10-08 11:12:00 -04:00
|
|
|
rescue => ex
|
|
|
|
logger.error("#{self.class.name}: #{ex}")
|
|
|
|
return git_not_found!
|
2012-02-07 18:00:49 -05:00
|
|
|
end
|
2018-02-19 15:41:04 -05:00
|
|
|
|
|
|
|
def assign_archive_vars
|
|
|
|
@id = params[:id]
|
2018-04-08 08:47:54 -04:00
|
|
|
|
|
|
|
return unless @id
|
|
|
|
|
2018-02-19 15:41:04 -05:00
|
|
|
@ref, @filename = extract_ref(@id)
|
|
|
|
rescue InvalidPathError
|
|
|
|
render_404
|
|
|
|
end
|
2011-12-30 15:56:13 -05:00
|
|
|
end
|