2012-05-02 10:18:07 +01:00
|
|
|
class Projects::Git::TreesController < Projects::Git::BaseController
|
2014-03-11 07:39:25 +00:00
|
|
|
before_filter -> {redirect_to @project if params[:treeish] == @project.default_branch and params[:path].blank?}, only: :show
|
2014-01-21 04:51:49 +00:00
|
|
|
skip_before_filter :set_branch_and_tree, :set_treeish_and_path, only: :archive
|
2014-03-11 07:39:25 +00:00
|
|
|
before_filter -> { raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) }, only: [:branch, :destroy]
|
2013-07-11 14:03:02 +01:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
skip_authorize_resource :project, only: [:destroy, :restore_branch, :create]
|
2014-03-11 07:39:25 +00:00
|
|
|
before_filter -> { authorize!(:write, @project) }, only: [:destroy, :restore_branch, :create]
|
2011-04-04 12:28:33 +01:00
|
|
|
|
2012-07-17 09:02:56 +01:00
|
|
|
def show
|
2013-07-23 11:07:39 +01:00
|
|
|
unless request.xhr?
|
|
|
|
render('empty') and return if @project.is_empty?
|
|
|
|
@tree = @tree / @path if @path.present?
|
2014-01-21 04:51:49 +00:00
|
|
|
@commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, max_count: 1).first
|
2013-07-23 11:07:39 +01:00
|
|
|
raise Grit::NoSuchPathError unless @commit
|
|
|
|
end
|
2011-03-10 12:39:24 +00:00
|
|
|
end
|
2012-04-17 11:18:03 +01:00
|
|
|
|
|
|
|
def archive
|
2013-01-31 17:26:41 +00:00
|
|
|
format, @treeish = params[:format], params[:treeish]
|
2013-02-14 12:46:25 +00:00
|
|
|
if (@treeish =~ /^#{@project.name}-/) && !(@treeish =~ /[\s]+/) && (format =~ /^(zip|tar\.gz)$/)
|
|
|
|
@treeish = @treeish.gsub(/^#{@project.name}-/, '')
|
2012-09-20 12:21:54 +01:00
|
|
|
@commit = @project.repo.commits(@treeish, 1).first
|
2012-09-19 20:29:36 +01:00
|
|
|
end
|
2012-07-17 09:02:56 +01:00
|
|
|
raise Grit::NoSuchPathError unless @commit
|
2014-05-02 21:38:28 +01:00
|
|
|
tag = @project.repo.tags.find{ |t| t.name == @treeish }
|
|
|
|
sha1 = @project.get_project_tag_sha1(tag, format) if tag
|
|
|
|
sha1 ||= @project.build_scripts.by_active.by_treeish(@treeish).first.try(:sha1)
|
|
|
|
if sha1.present?
|
2013-02-14 21:49:18 +00:00
|
|
|
redirect_to "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}"
|
2013-02-14 12:46:25 +00:00
|
|
|
else
|
2013-02-14 21:49:18 +00:00
|
|
|
archive = @project.archive_by_treeish_and_format @treeish, format
|
2014-01-21 04:51:49 +00:00
|
|
|
send_file archive[:path], disposition: 'attachment', type: "application/#{format == 'zip' ? 'zip' : 'x-tar-gz'}", filename: archive[:fullname]
|
2013-02-14 12:46:25 +00:00
|
|
|
end
|
2012-04-17 11:18:03 +01:00
|
|
|
end
|
2012-09-20 12:10:52 +01:00
|
|
|
|
2013-02-12 16:35:14 +00:00
|
|
|
def tags
|
2013-07-23 11:07:39 +01:00
|
|
|
if request.xhr?
|
|
|
|
@refs = @project.repo.tags.select{ |t| t.commit }.sort_by(&:name).reverse
|
|
|
|
render :refs_list
|
2013-10-02 15:21:16 +01:00
|
|
|
else
|
|
|
|
respond_to do |format|
|
2014-01-21 04:51:49 +00:00
|
|
|
format.json { render nothing: true, status: 422 }
|
2013-10-02 15:21:16 +01:00
|
|
|
format.html
|
|
|
|
end
|
2013-07-23 11:07:39 +01:00
|
|
|
end
|
2013-02-12 16:35:14 +00:00
|
|
|
end
|
|
|
|
|
2013-07-12 15:21:46 +01:00
|
|
|
def restore_branch
|
2013-07-23 14:29:41 +01:00
|
|
|
status = @project.create_branch(@treeish, params[:sha], current_user) ? 200 : 422
|
2014-01-21 04:51:49 +00:00
|
|
|
render nothing: true, status: status
|
2013-07-12 15:21:46 +01:00
|
|
|
end
|
|
|
|
|
2013-07-22 12:27:14 +01:00
|
|
|
def create
|
2013-07-22 15:21:12 +01:00
|
|
|
status = @project.create_branch(params[:new_ref], params[:from_ref], current_user) ? 200 : 422
|
2014-01-21 04:51:49 +00:00
|
|
|
render nothing: true, status: status
|
2013-07-12 15:21:46 +01:00
|
|
|
end
|
|
|
|
|
2013-07-11 11:34:44 +01:00
|
|
|
def destroy
|
2013-07-19 11:22:29 +01:00
|
|
|
status = @branch && @project.delete_branch(@branch, current_user) ? 200 : 422
|
2014-01-21 04:51:49 +00:00
|
|
|
render nothing: true, status: status
|
2013-02-12 16:35:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def branches
|
2013-07-23 11:07:39 +01:00
|
|
|
if request.xhr?
|
|
|
|
@refs = @project.repo.branches.sort_by(&:name)
|
|
|
|
render :refs_list
|
2013-10-02 15:21:16 +01:00
|
|
|
else
|
|
|
|
respond_to do |format|
|
2014-01-21 04:51:49 +00:00
|
|
|
format.json { render nothing: true, status: 422 }
|
2013-10-02 15:21:16 +01:00
|
|
|
format.html
|
|
|
|
end
|
2013-07-23 11:07:39 +01:00
|
|
|
end
|
2013-02-12 16:35:14 +00:00
|
|
|
end
|
|
|
|
|
2012-01-30 20:39:34 +00:00
|
|
|
end
|