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
Léo-Paul Géneau
gitlab-ce
Commits
55779b00
Commit
55779b00
authored
Oct 26, 2012
by
Riyad Preukschas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename Gitlab::FileEditor to Gitlab::Satellite::EditFileAction
parent
8c89beb6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
61 deletions
+46
-61
app/controllers/tree_controller.rb
app/controllers/tree_controller.rb
+1
-1
lib/gitlab/file_editor.rb
lib/gitlab/file_editor.rb
+0
-58
lib/gitlab/satellite/edit_file_action.rb
lib/gitlab/satellite/edit_file_action.rb
+43
-0
lib/gitlab/satellite/merge_action.rb
lib/gitlab/satellite/merge_action.rb
+2
-2
No files found.
app/controllers/tree_controller.rb
View file @
55779b00
...
@@ -26,7 +26,7 @@ class TreeController < ProjectResourceController
...
@@ -26,7 +26,7 @@ class TreeController < ProjectResourceController
end
end
def
update
def
update
file_editor
=
Gitlab
::
FileEditor
.
new
(
current_user
,
@project
,
@ref
)
file_editor
=
Gitlab
::
Satellite
::
EditFileAction
.
new
(
current_user
,
@project
,
@ref
)
update_status
=
file_editor
.
update
(
update_status
=
file_editor
.
update
(
@path
,
@path
,
params
[
:content
],
params
[
:content
],
...
...
lib/gitlab/file_editor.rb
deleted
100644 → 0
View file @
8c89beb6
module
Gitlab
# GitLab file editor
#
# It gives you ability to make changes to files
# & commit this changes from GitLab UI.
class
FileEditor
attr_accessor
:user
,
:project
,
:ref
def
initialize
(
user
,
project
,
ref
)
self
.
user
=
user
self
.
project
=
project
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
.
last_commit_for
(
ref
,
path
).
sha
last_commit
==
current_last_commit
end
end
end
lib/gitlab/satellite/edit_file_action.rb
0 → 100644
View file @
55779b00
module
Gitlab
module
Satellite
# GitLab file editor
#
# It gives you ability to make changes to files
# & commit this changes from GitLab UI.
class
EditFileAction
<
Action
attr_accessor
:ref
def
initialize
(
user
,
project
,
ref
)
super
user
,
project
@ref
=
ref
end
def
update
(
path
,
content
,
commit_message
,
last_commit
)
return
false
unless
can_edit?
(
path
,
last_commit
)
in_locked_and_timed_satellite
do
|
repo
|
prepare_satellite!
(
repo
)
repo
.
git
.
sh
"git checkout -b
#{
ref
}
origin/
#{
ref
}
"
File
.
open
(
path
,
'w'
){
|
f
|
f
.
write
(
content
)}
repo
.
git
.
sh
"git add ."
repo
.
git
.
sh
"git commit -am '
#{
commit_message
}
'"
output
=
repo
.
git
.
sh
"git push origin
#{
ref
}
"
# everything worked
true
end
rescue
Grit
::
Git
::
CommandFailed
=>
ex
Gitlab
::
GitLogger
.
error
(
ex
.
message
)
false
end
protected
def
can_edit?
(
path
,
last_commit
)
current_last_commit
=
@project
.
last_commit_for
(
ref
,
path
).
sha
last_commit
==
current_last_commit
end
end
end
end
lib/gitlab/satellite/merge_action.rb
View file @
55779b00
...
@@ -55,11 +55,11 @@ module Gitlab
...
@@ -55,11 +55,11 @@ module Gitlab
prepare_satellite!
(
repo
)
prepare_satellite!
(
repo
)
# create target branch in satellite at the corresponding commit from Gitolite
# create target branch in satellite at the corresponding commit from Gitolite
repo
.
git
.
checkout
({
b:
true
},
merge_request
.
target_branch
,
"origin/
#{
merge_request
.
target_branch
}
"
)
repo
.
git
.
checkout
({
raise:
true
,
b:
true
},
merge_request
.
target_branch
,
"origin/
#{
merge_request
.
target_branch
}
"
)
# merge the source branch from Gitolite into the satellite
# merge the source branch from Gitolite into the satellite
# will raise CommandFailed when merge fails
# will raise CommandFailed when merge fails
repo
.
git
.
pull
({
no_ff:
true
,
raise
:
true
},
:origin
,
merge_request
.
source_branch
)
repo
.
git
.
pull
({
raise:
true
,
no_ff
:
true
},
:origin
,
merge_request
.
source_branch
)
rescue
Grit
::
Git
::
CommandFailed
=>
ex
rescue
Grit
::
Git
::
CommandFailed
=>
ex
Gitlab
::
GitLogger
.
error
(
ex
.
message
)
Gitlab
::
GitLogger
.
error
(
ex
.
message
)
false
false
...
...
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