Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
gitlab-ce
Commits
df6750d3
Commit
df6750d3
authored
Dec 08, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Default target branch to patch-n when editing file in protected branch
parent
792f2bbe
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
7 deletions
+33
-7
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+10
-2
app/helpers/branches_helper.rb
app/helpers/branches_helper.rb
+1
-1
app/helpers/tree_helper.rb
app/helpers/tree_helper.rb
+10
-3
app/models/repository.rb
app/models/repository.rb
+11
-0
app/views/shared/_new_commit_form.html.haml
app/views/shared/_new_commit_form.html.haml
+1
-1
No files found.
app/controllers/projects/blob_controller.rb
View file @
df6750d3
...
@@ -162,12 +162,20 @@ class Projects::BlobController < Projects::ApplicationController
...
@@ -162,12 +162,20 @@ class Projects::BlobController < Projects::ApplicationController
end
end
def
sanitized_new_branch_name
def
sanitized_new_branch_name
@new_branch
||=
sanitize
(
strip_tags
(
params
[
:new_branch
]))
sanitize
(
strip_tags
(
params
[
:new_branch
]))
end
end
def
editor_variables
def
editor_variables
@current_branch
=
@ref
@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
=
@file_path
=
if
action_name
.
to_s
==
'create'
if
action_name
.
to_s
==
'create'
...
...
app/helpers/branches_helper.rb
View file @
df6750d3
...
@@ -11,7 +11,7 @@ module BranchesHelper
...
@@ -11,7 +11,7 @@ module BranchesHelper
def
can_push_branch?
(
project
,
branch_name
)
def
can_push_branch?
(
project
,
branch_name
)
return
false
unless
project
.
repository
.
branch_names
.
include?
(
branch_name
)
return
false
unless
project
.
repository
.
branch_names
.
include?
(
branch_name
)
::
Gitlab
::
GitAccess
.
new
(
current_user
,
project
).
can_push_to_branch?
(
branch_name
)
::
Gitlab
::
GitAccess
.
new
(
current_user
,
project
).
can_push_to_branch?
(
branch_name
)
end
end
end
end
app/helpers/tree_helper.rb
View file @
df6750d3
...
@@ -48,10 +48,17 @@ module TreeHelper
...
@@ -48,10 +48,17 @@ module TreeHelper
def
allowed_tree_edit?
(
project
=
nil
,
ref
=
nil
)
def
allowed_tree_edit?
(
project
=
nil
,
ref
=
nil
)
project
||=
@project
project
||=
@project
ref
||=
@ref
can?
(
current_user
,
:push_code
,
project
)
return
false
unless
project
.
repository
.
branch_names
.
include?
(
ref
)
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
end
def
can_delete_or_replace?
(
blob
)
def
can_delete_or_replace?
(
blob
)
...
...
app/models/repository.rb
View file @
df6750d3
...
@@ -329,6 +329,17 @@ class Repository
...
@@ -329,6 +329,17 @@ class Repository
commit
(
sha
)
commit
(
sha
)
end
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
# Remove archives older than 2 hours
def
branches_sorted_by
(
value
)
def
branches_sorted_by
(
value
)
case
value
case
value
...
...
app/views/shared/_new_commit_form.html.haml
View file @
df6750d3
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
.form-group.branch
.form-group.branch
=
label_tag
'new_branch'
,
'Target branch'
,
class:
'control-label'
=
label_tag
'new_branch'
,
'Target branch'
,
class:
'control-label'
.col-sm-10
.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
.form-group.js-create-merge-request-form-group
.col-sm-offset-2.col-sm-10
.col-sm-offset-2.col-sm-10
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment