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
71a844cd
Commit
71a844cd
authored
Feb 14, 2015
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Web Editor: save to new branch
parent
7561b1c2
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
9 deletions
+53
-9
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+23
-3
app/services/files/create_service.rb
app/services/files/create_service.rb
+2
-1
app/services/files/update_service.rb
app/services/files/update_service.rb
+2
-1
app/views/projects/blob/edit.html.haml
app/views/projects/blob/edit.html.haml
+7
-0
app/views/projects/blob/new.html.haml
app/views/projects/blob/new.html.haml
+7
-0
lib/gitlab/satellite/files/edit_file_action.rb
lib/gitlab/satellite/files/edit_file_action.rb
+4
-2
lib/gitlab/satellite/files/new_file_action.rb
lib/gitlab/satellite/files/new_file_action.rb
+8
-2
No files found.
app/controllers/projects/blob_controller.rb
View file @
71a844cd
# Controller for viewing a file's blame
# Controller for viewing a file's blame
class
Projects::BlobController
<
Projects
::
ApplicationController
class
Projects::BlobController
<
Projects
::
ApplicationController
include
ExtractsPath
include
ExtractsPath
include
ActionView
::
Helpers
::
SanitizeHelper
# Raised when given an invalid file path
# Raised when given an invalid file path
class
InvalidPathError
<
StandardError
;
end
class
InvalidPathError
<
StandardError
;
end
...
@@ -21,11 +22,18 @@ class Projects::BlobController < Projects::ApplicationController
...
@@ -21,11 +22,18 @@ class Projects::BlobController < Projects::ApplicationController
def
create
def
create
file_path
=
File
.
join
(
@path
,
File
.
basename
(
params
[
:file_name
]))
file_path
=
File
.
join
(
@path
,
File
.
basename
(
params
[
:file_name
]))
result
=
Files
::
CreateService
.
new
(
@project
,
current_user
,
params
,
@ref
,
file_path
).
execute
result
=
Files
::
CreateService
.
new
(
@project
,
current_user
,
params
.
merge
(
new_branch:
sanitized_new_branch_name
),
@ref
,
file_path
).
execute
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
flash
[
:notice
]
=
"Your changes have been successfully committed"
flash
[
:notice
]
=
"Your changes have been successfully committed"
redirect_to
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
File
.
join
(
@ref
,
file_path
))
ref
=
sanitized_new_branch_name
.
presence
||
@ref
redirect_to
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
File
.
join
(
ref
,
file_path
))
else
else
flash
[
:alert
]
=
result
[
:message
]
flash
[
:alert
]
=
result
[
:message
]
render
:new
render
:new
...
@@ -41,7 +49,13 @@ class Projects::BlobController < Projects::ApplicationController
...
@@ -41,7 +49,13 @@ class Projects::BlobController < Projects::ApplicationController
def
update
def
update
result
=
Files
::
UpdateService
.
result
=
Files
::
UpdateService
.
new
(
@project
,
current_user
,
params
,
@ref
,
@path
).
execute
new
(
@project
,
current_user
,
params
.
merge
(
new_branch:
sanitized_new_branch_name
),
@ref
,
@path
).
execute
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
flash
[
:notice
]
=
"Your changes have been successfully committed"
flash
[
:notice
]
=
"Your changes have been successfully committed"
...
@@ -131,6 +145,8 @@ class Projects::BlobController < Projects::ApplicationController
...
@@ -131,6 +145,8 @@ class Projects::BlobController < Projects::ApplicationController
if
from_merge_request
if
from_merge_request
diffs_namespace_project_merge_request_path
(
from_merge_request
.
target_project
.
namespace
,
from_merge_request
.
target_project
,
from_merge_request
)
+
diffs_namespace_project_merge_request_path
(
from_merge_request
.
target_project
.
namespace
,
from_merge_request
.
target_project
,
from_merge_request
)
+
"#file-path-
#{
hexdigest
(
@path
)
}
"
"#file-path-
#{
hexdigest
(
@path
)
}
"
elsif
sanitized_new_branch_name
.
present?
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
File
.
join
(
sanitized_new_branch_name
,
@path
))
else
else
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
@id
)
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
@id
)
end
end
...
@@ -140,4 +156,8 @@ class Projects::BlobController < Projects::ApplicationController
...
@@ -140,4 +156,8 @@ class Projects::BlobController < Projects::ApplicationController
# If blob edit was initiated from merge request page
# If blob edit was initiated from merge request page
@from_merge_request
||=
MergeRequest
.
find_by
(
id:
params
[
:from_merge_request_id
])
@from_merge_request
||=
MergeRequest
.
find_by
(
id:
params
[
:from_merge_request_id
])
end
end
def
sanitized_new_branch_name
@new_branch
||=
sanitize
(
strip_tags
(
params
[
:new_branch
]))
end
end
end
app/services/files/create_service.rb
View file @
71a844cd
...
@@ -38,7 +38,8 @@ module Files
...
@@ -38,7 +38,8 @@ module Files
created_successfully
=
new_file_action
.
commit!
(
created_successfully
=
new_file_action
.
commit!
(
params
[
:content
],
params
[
:content
],
params
[
:commit_message
],
params
[
:commit_message
],
params
[
:encoding
]
params
[
:encoding
],
params
[
:new_branch
]
)
)
if
created_successfully
if
created_successfully
...
...
app/services/files/update_service.rb
View file @
71a844cd
...
@@ -23,7 +23,8 @@ module Files
...
@@ -23,7 +23,8 @@ module Files
edit_file_action
.
commit!
(
edit_file_action
.
commit!
(
params
[
:content
],
params
[
:content
],
params
[
:commit_message
],
params
[
:commit_message
],
params
[
:encoding
]
params
[
:encoding
],
params
[
:new_branch
]
)
)
success
success
...
...
app/views/projects/blob/edit.html.haml
View file @
71a844cd
...
@@ -14,6 +14,13 @@
...
@@ -14,6 +14,13 @@
=
render
'projects/blob/editor'
,
ref:
@ref
,
path:
@path
,
blob_data:
@blob
.
data
=
render
'projects/blob/editor'
,
ref:
@ref
,
path:
@path
,
blob_data:
@blob
.
data
=
render
'shared/commit_message_container'
,
params:
params
,
=
render
'shared/commit_message_container'
,
params:
params
,
placeholder:
"Update
#{
@blob
.
name
}
"
placeholder:
"Update
#{
@blob
.
name
}
"
.form-group.branch
=
label_tag
'branch'
,
class:
'control-label'
do
Branch
.col-sm-10
=
text_field_tag
'new_branch'
,
@ref
,
class:
"form-control"
=
hidden_field_tag
'last_commit'
,
@last_commit
=
hidden_field_tag
'last_commit'
,
@last_commit
=
hidden_field_tag
'content'
,
''
,
id:
"file-content"
=
hidden_field_tag
'content'
,
''
,
id:
"file-content"
=
hidden_field_tag
'from_merge_request_id'
,
params
[
:from_merge_request_id
]
=
hidden_field_tag
'from_merge_request_id'
,
params
[
:from_merge_request_id
]
...
...
app/views/projects/blob/new.html.haml
View file @
71a844cd
...
@@ -4,6 +4,13 @@
...
@@ -4,6 +4,13 @@
=
render
'projects/blob/editor'
,
ref:
@ref
=
render
'projects/blob/editor'
,
ref:
@ref
=
render
'shared/commit_message_container'
,
params:
params
,
=
render
'shared/commit_message_container'
,
params:
params
,
placeholder:
'Add new file'
placeholder:
'Add new file'
.form-group.branch
=
label_tag
'branch'
,
class:
'control-label'
do
Branch
.col-sm-10
=
text_field_tag
'new_branch'
,
@ref
,
class:
"form-control"
=
hidden_field_tag
'content'
,
''
,
id:
'file-content'
=
hidden_field_tag
'content'
,
''
,
id:
'file-content'
=
render
'projects/commit_button'
,
ref:
@ref
,
=
render
'projects/commit_button'
,
ref:
@ref
,
cancel_path:
namespace_project_tree_path
(
@project
.
namespace
,
@project
,
@id
)
cancel_path:
namespace_project_tree_path
(
@project
.
namespace
,
@project
,
@id
)
...
...
lib/gitlab/satellite/files/edit_file_action.rb
View file @
71a844cd
...
@@ -10,7 +10,7 @@ module Gitlab
...
@@ -10,7 +10,7 @@ module Gitlab
# Returns false if committing the change fails
# Returns false if committing the change fails
# Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns true otherwise
# Returns true otherwise
def
commit!
(
content
,
commit_message
,
encoding
)
def
commit!
(
content
,
commit_message
,
encoding
,
new_branch
=
nil
)
in_locked_and_timed_satellite
do
|
repo
|
in_locked_and_timed_satellite
do
|
repo
|
prepare_satellite!
(
repo
)
prepare_satellite!
(
repo
)
...
@@ -42,10 +42,12 @@ module Gitlab
...
@@ -42,10 +42,12 @@ module Gitlab
end
end
target_branch
=
new_branch
.
present?
?
"
#{
ref
}
:
#{
new_branch
}
"
:
ref
# push commit back to bare repo
# push commit back to bare repo
# will raise CommandFailed when push fails
# will raise CommandFailed when push fails
begin
begin
repo
.
git
.
push
({
raise:
true
,
timeout:
true
},
:origin
,
ref
)
repo
.
git
.
push
({
raise:
true
,
timeout:
true
},
:origin
,
target_branch
)
rescue
Grit
::
Git
::
CommandFailed
=>
ex
rescue
Grit
::
Git
::
CommandFailed
=>
ex
log_and_raise
(
PushFailed
,
ex
.
message
)
log_and_raise
(
PushFailed
,
ex
.
message
)
end
end
...
...
lib/gitlab/satellite/files/new_file_action.rb
View file @
71a844cd
...
@@ -9,7 +9,7 @@ module Gitlab
...
@@ -9,7 +9,7 @@ module Gitlab
# Returns false if committing the change fails
# Returns false if committing the change fails
# Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns true otherwise
# Returns true otherwise
def
commit!
(
content
,
commit_message
,
encoding
)
def
commit!
(
content
,
commit_message
,
encoding
,
new_branch
=
nil
)
in_locked_and_timed_satellite
do
|
repo
|
in_locked_and_timed_satellite
do
|
repo
|
prepare_satellite!
(
repo
)
prepare_satellite!
(
repo
)
...
@@ -45,9 +45,15 @@ module Gitlab
...
@@ -45,9 +45,15 @@ module Gitlab
# will raise CommandFailed when commit fails
# will raise CommandFailed when commit fails
repo
.
git
.
commit
(
raise:
true
,
timeout:
true
,
a:
true
,
m:
commit_message
)
repo
.
git
.
commit
(
raise:
true
,
timeout:
true
,
a:
true
,
m:
commit_message
)
target_branch
=
if
new_branch
.
present?
&&
!
@project
.
empty_repo?
"
#{
ref
}
:
#{
new_branch
}
"
else
"
#{
current_ref
}
:
#{
ref
}
"
end
# push commit back to bare repo
# push commit back to bare repo
# will raise CommandFailed when push fails
# will raise CommandFailed when push fails
repo
.
git
.
push
({
raise:
true
,
timeout:
true
},
:origin
,
"
#{
current_ref
}
:
#{
ref
}
"
)
repo
.
git
.
push
({
raise:
true
,
timeout:
true
},
:origin
,
target_branch
)
# everything worked
# everything worked
true
true
...
...
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