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
42bdfd02
Commit
42bdfd02
authored
Oct 12, 2012
by
Valeriy Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WebEditor: base implementation
parent
0b3e9fd2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
10 deletions
+55
-10
tree_controller.rb
app/controllers/tree_controller.rb
+8
-2
edit.html.haml
app/views/tree/edit.html.haml
+7
-2
file_editor.rb
lib/gitlab/file_editor.rb
+38
-4
merge.rb
lib/gitlab/merge.rb
+2
-2
No files found.
app/controllers/tree_controller.rb
View file @
42bdfd02
...
...
@@ -26,8 +26,14 @@ class TreeController < ProjectResourceController
def
update
file_editor
=
Gitlab
::
FileEditor
.
new
(
current_user
,
@project
,
@ref
)
if
file_editor
.
can_edit?
(
@path
,
params
[
:last_commit
])
file_editor
.
update
(
@path
,
params
[
:content
])
update_status
=
file_editor
.
update
(
@path
,
params
[
:content
],
params
[
:commit_message
],
params
[
:last_commit
]
)
if
update_status
redirect_to
project_tree_path
(
@project
,
@id
),
:notice
=>
"File has been successfully changed"
else
flash
[
:notice
]
=
"You can't save file because it has been changed"
...
...
app/views/tree/edit.html.haml
View file @
42bdfd02
...
...
@@ -13,10 +13,15 @@
=
text_area_tag
'commit_message'
.form-actions
=
hidden_field_tag
'last_commit'
,
@last_commit
=
hidden_field_tag
'content'
=
submit
_tag
"Save"
,
class:
'btn save-btn'
=
hidden_field_tag
'content'
,
''
,
:id
=>
:file_content
=
button
_tag
"Save"
,
class:
'btn save-btn'
:javascript
var
editor
=
ace
.
edit
(
"editor"
);
editor
.
setTheme
(
"ace/theme/twilight"
);
editor
.
getSession
().
setMode
(
"ace/mode/javascript"
);
$
(
".save-btn"
).
click
(
function
(){
$
(
"#file_content"
).
val
(
editor
.
getValue
());
$
(
".form_editor form"
).
submit
();
});
lib/gitlab/file_editor.rb
View file @
42bdfd02
...
...
@@ -9,14 +9,48 @@ module Gitlab
self
.
ref
=
ref
end
def
update
(
path
,
content
,
commit_message
,
last_commit
)
return
false
unless
can_edit?
(
path
,
last_commit
)
Grit
::
Git
.
with_timeout
(
10
.
seconds
)
do
lock_file
=
Rails
.
root
.
join
(
"tmp"
,
"
#{
project
.
path
}
.lock"
)
File
.
open
(
lock_file
,
"w+"
)
do
|
f
|
f
.
flock
(
File
::
LOCK_EX
)
unless
project
.
satellite
.
exists?
raise
"Satellite doesn't exist"
end
project
.
satellite
.
clear
Dir
.
chdir
(
project
.
satellite
.
path
)
do
r
=
Grit
::
Repo
.
new
(
'.'
)
r
.
git
.
sh
"git reset --hard"
r
.
git
.
sh
"git fetch origin"
r
.
git
.
sh
"git config user.name
\"
#{
user
.
name
}
\"
"
r
.
git
.
sh
"git config user.email
\"
#{
user
.
email
}
\"
"
r
.
git
.
sh
"git checkout -b
#{
ref
}
origin/
#{
ref
}
"
File
.
open
(
path
,
'w'
){
|
f
|
f
.
write
(
content
)}
r
.
git
.
sh
"git add ."
r
.
git
.
sh
"git commit -am '
#{
commit_message
}
'"
output
=
r
.
git
.
sh
"git push origin
#{
ref
}
"
if
output
=~
/reject/
return
false
end
end
end
end
true
end
protected
def
can_edit?
(
path
,
last_commit
)
current_last_commit
=
@project
.
commits
(
ref
,
path
,
1
).
first
.
sha
last_commit
==
current_last_commit
end
def
update
(
path
,
content
)
true
end
end
end
lib/gitlab/merge.rb
View file @
42bdfd02
...
...
@@ -28,13 +28,13 @@ module Gitlab
def
process
Grit
::
Git
.
with_timeout
(
30
.
seconds
)
do
lock_file
=
Rails
.
root
.
join
(
"tmp"
,
"
merge_repo_
#{
project
.
path
}
.lock"
)
lock_file
=
Rails
.
root
.
join
(
"tmp"
,
"
#{
project
.
path
}
.lock"
)
File
.
open
(
lock_file
,
"w+"
)
do
|
f
|
f
.
flock
(
File
::
LOCK_EX
)
unless
project
.
satellite
.
exists?
raise
"
You should run: rake gitlab:app:enable_automerge
"
raise
"
Satellite doesn't exist
"
end
project
.
satellite
.
clear
...
...
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