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