2013-07-16 15:19:07 -04:00
|
|
|
class Projects::BranchesController < Projects::ApplicationController
|
|
|
|
# Authorize
|
|
|
|
before_filter :authorize_read_project!
|
|
|
|
before_filter :require_non_empty_project
|
|
|
|
|
2014-10-13 15:31:49 -04:00
|
|
|
before_filter :authorize_download_code!
|
|
|
|
before_filter :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)
|
|
|
|
@branches = Kaminari.paginate_array(@branches).page(params[:page]).per(30)
|
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-09-21 04:29:52 -04:00
|
|
|
result = CreateBranchService.new(project, current_user).
|
|
|
|
execute(params[:branch_name], params[:ref])
|
2014-07-27 10:40:00 -04:00
|
|
|
if result[:status] == :success
|
|
|
|
@branch = result[:branch]
|
|
|
|
redirect_to project_tree_path(@project, @branch.name)
|
|
|
|
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|
|
2013-07-16 17:09:23 -04:00
|
|
|
format.html { redirect_to project_branches_path(@project) }
|
2014-05-17 05:36:39 -04:00
|
|
|
format.js
|
2013-07-16 15:19:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|