Default target branch to patch-n when editing file in protected branch

This commit is contained in:
Douwe Maan
2015-12-08 16:42:10 +01:00
parent 792f2bbe0b
commit df6750d3d6
5 changed files with 33 additions and 7 deletions
+10 -2
View File
@@ -162,12 +162,20 @@ class Projects::BlobController < Projects::ApplicationController
end
def sanitized_new_branch_name
@new_branch ||= sanitize(strip_tags(params[:new_branch]))
sanitize(strip_tags(params[:new_branch]))
end
def editor_variables
@current_branch = @ref
@new_branch = params[:new_branch].present? ? sanitized_new_branch_name : @ref
@new_branch =
if params[:new_branch].present?
sanitized_new_branch_name
elsif ::Gitlab::GitAccess.new(current_user, @project).can_push_to_branch?(@ref)
@ref
else
@repository.next_patch_branch
end
@file_path =
if action_name.to_s == 'create'
+1 -1
View File
@@ -11,7 +11,7 @@ module BranchesHelper
def can_push_branch?(project, branch_name)
return false unless project.repository.branch_names.include?(branch_name)
::Gitlab::GitAccess.new(current_user, project).can_push_to_branch?(branch_name)
end
end
+10 -3
View File
@@ -48,10 +48,17 @@ module TreeHelper
def allowed_tree_edit?(project = nil, ref = nil)
project ||= @project
ref ||= @ref
return false unless project.repository.branch_names.include?(ref)
can?(current_user, :push_code, project)
end
::Gitlab::GitAccess.new(current_user, project).can_push_to_branch?(ref)
def tree_edit_branch(project = @project, ref = @ref)
if allowed_tree_edit?
if can_push_branch?(project, ref)
ref
else
project.repository.next_patch_branch
end
end
end
def can_delete_or_replace?(blob)
+11
View File
@@ -329,6 +329,17 @@ class Repository
commit(sha)
end
def next_patch_branch
patch_branch_ids = self.branch_names.map do |n|
result = n.match(/\Apatch-([0-9]+)\z/)
result[1].to_i if result
end.compact
highest_patch_branch_id = patch_branch_ids.max || 0
"patch-#{highest_patch_branch_id + 1}"
end
# Remove archives older than 2 hours
def branches_sorted_by(value)
case value
+1 -1
View File
@@ -4,7 +4,7 @@
.form-group.branch
= label_tag 'new_branch', 'Target branch', class: 'control-label'
.col-sm-10
= text_field_tag 'new_branch', @new_branch || @ref, required: true, class: "form-control js-new-branch"
= text_field_tag 'new_branch', @new_branch || tree_edit_branch, required: true, class: "form-control js-new-branch"
.form-group.js-create-merge-request-form-group
.col-sm-offset-2.col-sm-10