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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
986697a9
Commit
986697a9
authored
Nov 11, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Create/Update file context and lib
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
c77d957b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
6 additions
and
17 deletions
+6
-17
app/contexts/files/create_context.rb
app/contexts/files/create_context.rb
+2
-3
app/contexts/files/update_context.rb
app/contexts/files/update_context.rb
+1
-2
lib/gitlab/satellite/files/edit_file_action.rb
lib/gitlab/satellite/files/edit_file_action.rb
+1
-3
lib/gitlab/satellite/files/file_action.rb
lib/gitlab/satellite/files/file_action.rb
+0
-7
lib/gitlab/satellite/files/new_file_action.rb
lib/gitlab/satellite/files/new_file_action.rb
+2
-2
No files found.
app/contexts/files/create_context.rb
View file @
986697a9
...
@@ -33,11 +33,10 @@ module Files
...
@@ -33,11 +33,10 @@ module Files
return
error
(
"Your changes could not be commited, because file with such name exists"
)
return
error
(
"Your changes could not be commited, because file with such name exists"
)
end
end
new_file_action
=
Gitlab
::
Satellite
::
NewFileAction
.
new
(
current_user
,
project
,
ref
,
path
)
new_file_action
=
Gitlab
::
Satellite
::
NewFileAction
.
new
(
current_user
,
project
,
ref
,
file_
path
)
created_successfully
=
new_file_action
.
commit!
(
created_successfully
=
new_file_action
.
commit!
(
params
[
:content
],
params
[
:content
],
params
[
:commit_message
],
params
[
:commit_message
]
file_name
,
)
)
if
created_successfully
if
created_successfully
...
...
app/contexts/files/update_context.rb
View file @
986697a9
...
@@ -24,8 +24,7 @@ module Files
...
@@ -24,8 +24,7 @@ module Files
new_file_action
=
Gitlab
::
Satellite
::
EditFileAction
.
new
(
current_user
,
project
,
ref
,
path
)
new_file_action
=
Gitlab
::
Satellite
::
EditFileAction
.
new
(
current_user
,
project
,
ref
,
path
)
created_successfully
=
new_file_action
.
commit!
(
created_successfully
=
new_file_action
.
commit!
(
params
[
:content
],
params
[
:content
],
params
[
:commit_message
],
params
[
:commit_message
]
params
[
:last_commit
]
)
)
if
created_successfully
if
created_successfully
...
...
lib/gitlab/satellite/files/edit_file_action.rb
View file @
986697a9
...
@@ -10,9 +10,7 @@ module Gitlab
...
@@ -10,9 +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 Gitolite failed or was rejected
# Returns false if pushing from the satellite to Gitolite failed or was rejected
# Returns true otherwise
# Returns true otherwise
def
commit!
(
content
,
commit_message
,
last_commit
)
def
commit!
(
content
,
commit_message
)
return
false
unless
can_edit?
(
last_commit
)
in_locked_and_timed_satellite
do
|
repo
|
in_locked_and_timed_satellite
do
|
repo
|
prepare_satellite!
(
repo
)
prepare_satellite!
(
repo
)
...
...
lib/gitlab/satellite/files/file_action.rb
View file @
986697a9
...
@@ -8,13 +8,6 @@ module Gitlab
...
@@ -8,13 +8,6 @@ module Gitlab
@file_path
=
file_path
@file_path
=
file_path
@ref
=
ref
@ref
=
ref
end
end
protected
def
can_edit?
(
last_commit
)
current_last_commit
=
Gitlab
::
Git
::
Commit
.
last_for_path
(
@project
.
repository
,
ref
,
file_path
).
sha
last_commit
==
current_last_commit
end
end
end
end
end
end
end
lib/gitlab/satellite/files/new_file_action.rb
View file @
986697a9
...
@@ -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 Gitolite failed or was rejected
# Returns false if pushing from the satellite to Gitolite failed or was rejected
# Returns true otherwise
# Returns true otherwise
def
commit!
(
content
,
commit_message
,
file_name
)
def
commit!
(
content
,
commit_message
)
in_locked_and_timed_satellite
do
|
repo
|
in_locked_and_timed_satellite
do
|
repo
|
prepare_satellite!
(
repo
)
prepare_satellite!
(
repo
)
...
@@ -17,7 +17,7 @@ module Gitlab
...
@@ -17,7 +17,7 @@ module Gitlab
repo
.
git
.
checkout
({
raise:
true
,
timeout:
true
,
b:
true
},
ref
,
"origin/
#{
ref
}
"
)
repo
.
git
.
checkout
({
raise:
true
,
timeout:
true
,
b:
true
},
ref
,
"origin/
#{
ref
}
"
)
# update the file in the satellite's working dir
# update the file in the satellite's working dir
file_path_in_satellite
=
File
.
join
(
repo
.
working_dir
,
file_path
||
''
,
file_name
)
file_path_in_satellite
=
File
.
join
(
repo
.
working_dir
,
file_path
)
File
.
open
(
file_path_in_satellite
,
'w'
)
{
|
f
|
f
.
write
(
content
)
}
File
.
open
(
file_path_in_satellite
,
'w'
)
{
|
f
|
f
.
write
(
content
)
}
# add new file
# add new file
...
...
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