mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-19 09:36:47 +10:00
Default target branch to patch-n when editing file in protected branch
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user