2013-07-16 15:19:07 -04:00
|
|
|
class Projects::BranchesController < Projects::ApplicationController
|
2014-11-13 10:20:43 -05:00
|
|
|
include ActionView::Helpers::SanitizeHelper
|
2013-07-16 15:19:07 -04:00
|
|
|
# Authorize
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :authorize_download_code!
|
|
|
|
before_action :authorize_push_code!, only: [:create, :destroy]
|
2013-07-16 15:19:07 -04:00
|
|
|
|
|
|
|
def index
|
2014-05-23 07:25:55 -04:00
|
|
|
@sort = params[:sort] || 'name'
|
|
|
|
@branches = @repository.branches_sorted_by(@sort)
|
2015-03-12 18:37:00 -04:00
|
|
|
@branches = Kaminari.paginate_array(@branches).page(params[:page]).per(PER_PAGE)
|
2013-07-16 15:19:07 -04:00
|
|
|
end
|
|
|
|
|
2013-08-05 10:59:58 -04:00
|
|
|
def recent
|
|
|
|
@branches = @repository.recent_branches
|
|
|
|
end
|
|
|
|
|
2013-07-16 15:19:07 -04:00
|
|
|
def create
|
2014-11-13 10:20:43 -05:00
|
|
|
branch_name = sanitize(strip_tags(params[:branch_name]))
|
|
|
|
ref = sanitize(strip_tags(params[:ref]))
|
2014-09-21 04:29:52 -04:00
|
|
|
result = CreateBranchService.new(project, current_user).
|
2014-11-13 10:20:43 -05:00
|
|
|
execute(branch_name, ref)
|
2014-10-30 11:28:59 -04:00
|
|
|
|
2014-07-27 10:40:00 -04:00
|
|
|
if result[:status] == :success
|
|
|
|
@branch = result[:branch]
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_tree_path(@project.namespace, @project,
|
|
|
|
@branch.name)
|
2014-07-27 10:40:00 -04:00
|
|
|
else
|
|
|
|
@error = result[:message]
|
|
|
|
render action: 'new'
|
|
|
|
end
|
2013-07-16 15:19:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2014-09-21 04:29:52 -04:00
|
|
|
DeleteBranchService.new(project, current_user).execute(params[:id])
|
2014-05-23 14:26:31 -04:00
|
|
|
@branch_name = params[:id]
|
2013-07-16 15:19:07 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
2015-01-24 13:02:58 -05:00
|
|
|
format.html do
|
|
|
|
redirect_to namespace_project_branches_path(@project.namespace,
|
|
|
|
@project)
|
|
|
|
end
|
2014-05-17 05:36:39 -04:00
|
|
|
format.js
|
2013-07-16 15:19:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|