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
6d928726
Commit
6d928726
authored
Nov 17, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better error handling.
parent
76d96363
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
14 deletions
+23
-14
app/services/projects/update_mirror_service.rb
app/services/projects/update_mirror_service.rb
+20
-10
app/workers/repository_update_mirror_worker.rb
app/workers/repository_update_mirror_worker.rb
+3
-4
No files found.
app/services/projects/update_mirror_service.rb
View file @
6d928726
module
Projects
module
Projects
class
UpdateMirrorService
<
BaseService
class
UpdateMirrorService
<
BaseService
class
FetchError
<
StandardError
;
end
class
Error
<
StandardError
;
end
class
UpdateError
<
Error
;
end
def
execute
def
execute
return
false
unless
project
.
mirror?
return
false
unless
project
.
mirror?
begin
unless
current_user
.
can?
(
:push_code_to_protected_branches
,
project
)
update_tags
do
return
error
(
"The mirror user is not allowed to push code to all branches on this project."
)
project
.
fetch_mirror
end
end
rescue
Gitlab
::
Shell
::
Error
=>
e
update_tags
do
raise
FetchError
,
e
.
message
project
.
fetch_mirror
end
end
update_branches
update_branches
true
success
rescue
Gitlab
::
Shell
::
Error
,
UpdateError
=>
e
error
(
e
.
message
)
end
end
private
private
...
@@ -29,13 +32,20 @@ module Projects
...
@@ -29,13 +32,20 @@ module Projects
local_branch
=
local_branches
[
name
]
local_branch
=
local_branches
[
name
]
if
local_branch
.
nil?
if
local_branch
.
nil?
CreateBranchService
.
new
(
project
,
current_user
).
execute
(
name
,
upstream_branch
.
target
)
result
=
CreateBranchService
.
new
(
project
,
current_user
).
execute
(
name
,
upstream_branch
.
target
)
if
result
[
:status
]
==
:error
raise
UpdateError
,
result
[
:message
]
end
elsif
local_branch
.
target
==
upstream_branch
.
target
elsif
local_branch
.
target
==
upstream_branch
.
target
# Already up to date
# Already up to date
elsif
repository
.
diverged_from_upstream?
(
name
)
elsif
repository
.
diverged_from_upstream?
(
name
)
# Cannot be updated
# Cannot be updated
else
else
repository
.
ff_merge
(
current_user
,
upstream_branch
.
target
,
name
)
begin
repository
.
ff_merge
(
current_user
,
upstream_branch
.
target
,
name
)
rescue
Repository
::
PreReceiveError
,
Repository
::
CommitError
=>
e
raise
UpdateError
,
e
.
message
end
end
end
end
end
end
end
...
...
app/workers/repository_update_mirror_worker.rb
View file @
6d928726
...
@@ -11,10 +11,9 @@ class RepositoryUpdateMirrorWorker
...
@@ -11,10 +11,9 @@ class RepositoryUpdateMirrorWorker
# TODO: Use actual user
# TODO: Use actual user
@current_user
=
User
.
last
@current_user
=
User
.
last
begin
result
=
Projects
::
UpdateMirrorService
.
new
(
@project
,
@current_user
).
execute
Projects
::
UpdateMirrorService
.
new
(
@project
,
@current_user
).
execute
if
result
[
:status
]
==
:error
rescue
Projects
::
UpdateMirrorService
::
FetchError
=>
e
project
.
update
(
import_error:
result
[
:message
])
project
.
update
(
import_error:
e
.
message
)
project
.
import_fail
project
.
import_fail
return
return
end
end
...
...
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