BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
46516411
Commit
46516411
authored
Feb 24, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'web_editor_branch' into 'master'
Web Editor: save to new branch Implements #1931 See merge request !1523
parents
428df28c
53e40414
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
92 additions
and
12 deletions
+92
-12
CHANGELOG
CHANGELOG
+1
-0
blob_controller.rb
app/controllers/projects/blob_controller.rb
+23
-3
create_service.rb
app/services/files/create_service.rb
+2
-1
update_service.rb
app/services/files/update_service.rb
+2
-1
edit.html.haml
app/views/projects/blob/edit.html.haml
+7
-0
new.html.haml
app/views/projects/blob/new.html.haml
+7
-0
web_editor.md
doc/workflow/web_editor.md
+2
-2
edit_file.png
doc/workflow/web_editor/edit_file.png
+0
-0
new_file.png
doc/workflow/web_editor/new_file.png
+0
-0
browse_files.feature
features/project/source/browse_files.feature
+22
-0
browse_files.rb
features/steps/project/source/browse_files.rb
+14
-1
edit_file_action.rb
lib/gitlab/satellite/files/edit_file_action.rb
+4
-2
new_file_action.rb
lib/gitlab/satellite/files/new_file_action.rb
+8
-2
No files found.
CHANGELOG
View file @
46516411
...
@@ -7,6 +7,7 @@ v 7.9.0 (unreleased)
...
@@ -7,6 +7,7 @@ v 7.9.0 (unreleased)
- Improve UI for commits, issues and merge request lists
- Improve UI for commits, issues and merge request lists
- Fix commit comments on first line of diff not rendering in Merge Request Discussion view.
- Fix commit comments on first line of diff not rendering in Merge Request Discussion view.
- Improve trigger merge request hook when source project branch has been updated (Kirill Zaitsev)
- Improve trigger merge request hook when source project branch has been updated (Kirill Zaitsev)
- Save web edit in new branch
v 7.8.0
v 7.8.0
- Fix access control and protection against XSS for note attachments and other uploads.
- Fix access control and protection against XSS for note attachments and other uploads.
...
...
app/controllers/projects/blob_controller.rb
View file @
46516411
# 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 @
46516411
...
@@ -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 @
46516411
...
@@ -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 @
46516411
...
@@ -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 @
46516411
...
@@ -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
)
...
...
doc/workflow/web_editor.md
View file @
46516411
...
@@ -10,7 +10,7 @@ to create the first file and open it in the web editor.
...
@@ -10,7 +10,7 @@ to create the first file and open it in the web editor.
![
web editor 1
](
web_editor/empty_project.png
)
![
web editor 1
](
web_editor/empty_project.png
)
Fill in a file name, some content, a commit message and press the commit button.
Fill in a file name, some content, a commit message
, branch name
and press the commit button.
The file will be saved to the repository.
The file will be saved to the repository.
![
web editor 2
](
web_editor/new_file.png
)
![
web editor 2
](
web_editor/new_file.png
)
...
@@ -21,6 +21,6 @@ viewing the file.
...
@@ -21,6 +21,6 @@ viewing the file.
![
web editor 3
](
web_editor/show_file.png
)
![
web editor 3
](
web_editor/show_file.png
)
Editing a file is almost the same as creating a new file,
Editing a file is almost the same as creating a new file,
with as addition the ability to preview your changes in a separate tab.
with as addition the ability to preview your changes in a separate tab.
Also you can save your change to another branch by filling out field
`branch`
![
web editor 3
](
web_editor/edit_file.png
)
![
web editor 3
](
web_editor/edit_file.png
)
doc/workflow/web_editor/edit_file.png
View replaced file @
428df28c
View file @
46516411
97.3 KB
|
W:
|
H:
87 KB
|
W:
|
H:
2-up
Swipe
Onion skin
doc/workflow/web_editor/new_file.png
View replaced file @
428df28c
View file @
46516411
98.2 KB
|
W:
|
H:
83.5 KB
|
W:
|
H:
2-up
Swipe
Onion skin
features/project/source/browse_files.feature
View file @
46516411
...
@@ -34,6 +34,17 @@ Feature: Project Source Browse Files
...
@@ -34,6 +34,17 @@ Feature: Project Source Browse Files
Then
I am redirected to the new file
Then
I am redirected to the new file
And
I should see its new content
And
I should see its new content
@javascript
Scenario
:
I
can create and commit file and specify new branch
Given
I click on
"new file"
link in repo
And
I edit code
And
I fill the new file name
And
I fill the commit message
And
I fill the new branch name
And
I click on
"Commit Changes"
Then
I am redirected to the new file on new branch
And
I should see its new content
@javascript
@tricky
@javascript
@tricky
Scenario
:
I
can create file in empty repo
Scenario
:
I
can create file in empty repo
Given
I own an empty project
Given
I own an empty project
...
@@ -83,6 +94,17 @@ Feature: Project Source Browse Files
...
@@ -83,6 +94,17 @@ Feature: Project Source Browse Files
Then
I am redirected to the
".gitignore"
Then
I am redirected to the
".gitignore"
And
I should see its new content
And
I should see its new content
@javascript
Scenario
:
I
can edit and commit file to new branch
Given
I click on
".gitignore"
file in repo
And
I click button
"Edit"
And
I edit code
And
I fill the commit message
And
I fill the new branch name
And
I click on
"Commit Changes"
Then
I am redirected to the
".gitignore"
on new branch
And
I should see its new content
@javascript
@wip
@javascript
@wip
Scenario
:
If I don't change the content of the file I see an error message
Scenario
:
If I don't change the content of the file I see an error message
Given
I click on
".gitignore"
file in repo
Given
I click on
".gitignore"
file in repo
...
...
features/steps/project/source/browse_files.rb
View file @
46516411
...
@@ -69,6 +69,10 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
...
@@ -69,6 +69,10 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
fill_in
:file_name
,
with:
new_file_name
fill_in
:file_name
,
with:
new_file_name
end
end
step
'I fill the new branch name'
do
fill_in
:new_branch
,
with:
'new_branch_name'
end
step
'I fill the new file name with an illegal name'
do
step
'I fill the new file name with an illegal name'
do
fill_in
:file_name
,
with:
'.git'
fill_in
:file_name
,
with:
'.git'
end
end
...
@@ -148,6 +152,10 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
...
@@ -148,6 +152,10 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
expect
(
current_path
).
to
eq
(
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
'master/.gitignore'
))
expect
(
current_path
).
to
eq
(
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
'master/.gitignore'
))
end
end
step
'I am redirected to the ".gitignore" on new branch'
do
expect
(
current_path
).
to
eq
(
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
'new_branch_name/.gitignore'
))
end
step
'I am redirected to the permalink URL'
do
step
'I am redirected to the permalink URL'
do
expect
(
current_path
).
to
(
expect
(
current_path
).
to
(
eq
(
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
eq
(
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
...
@@ -161,6 +169,11 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
...
@@ -161,6 +169,11 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
@project
.
namespace
,
@project
,
'master/'
+
new_file_name
))
@project
.
namespace
,
@project
,
'master/'
+
new_file_name
))
end
end
step
'I am redirected to the new file on new branch'
do
expect
(
current_path
).
to
eq
(
namespace_project_blob_path
(
@project
.
namespace
,
@project
,
'new_branch_name/'
+
new_file_name
))
end
step
"I don't see the permalink link"
do
step
"I don't see the permalink link"
do
expect
(
page
).
not_to
have_link
(
'permalink'
)
expect
(
page
).
not_to
have_link
(
'permalink'
)
end
end
...
@@ -177,7 +190,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
...
@@ -177,7 +190,7 @@ class Spinach::Features::ProjectSourceBrowseFiles < Spinach::FeatureSteps
click_link
'add a file'
click_link
'add a file'
# Remove pre-receive hook so we can push without auth
# Remove pre-receive hook so we can push without auth
FileUtils
.
rm
(
File
.
join
(
@project
.
repository
.
path
,
'hooks'
,
'pre-receive'
))
FileUtils
.
rm
_f
(
File
.
join
(
@project
.
repository
.
path
,
'hooks'
,
'pre-receive'
))
end
end
private
private
...
...
lib/gitlab/satellite/files/edit_file_action.rb
View file @
46516411
...
@@ -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 @
46516411
...
@@ -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