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
ba327e69
Commit
ba327e69
authored
Aug 04, 2016
by
Sean McGivern
Committed by
Fatih Acet
Aug 12, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move resolving code to ResolveService
parent
ac9229a3
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
30 deletions
+40
-30
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+1
-1
app/models/repository.rb
app/models/repository.rb
+8
-0
app/services/merge_requests/resolve_service.rb
app/services/merge_requests/resolve_service.rb
+31
-0
lib/gitlab/conflict/file.rb
lib/gitlab/conflict/file.rb
+0
-8
lib/gitlab/conflict/file_collection.rb
lib/gitlab/conflict/file_collection.rb
+0
-21
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
ba327e69
...
...
@@ -150,7 +150,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def
resolve_conflicts
begin
Gitlab
::
Conflict
::
FileCollection
.
new
(
@merge_request
).
resolve_conflicts!
(
params
,
user:
current_user
)
MergeRequests
::
ResolveService
.
new
(
project
,
current_user
,
params
).
execute
(
@merge_request
)
head
:ok
rescue
Gitlab
::
Conflict
::
File
::
MissingResolution
=>
e
...
...
app/models/repository.rb
View file @
ba327e69
...
...
@@ -869,6 +869,14 @@ class Repository
end
end
def
resolve_conflicts
(
user
,
branch
,
params
)
commit_with_hooks
(
user
,
branch
)
do
committer
=
user_to_committer
(
user
)
Rugged
::
Commit
.
create
(
rugged
,
params
.
merge
(
author:
committer
,
committer:
committer
))
end
end
def
check_revert_content
(
commit
,
base_branch
)
source_sha
=
find_branch
(
base_branch
).
target
.
sha
args
=
[
commit
.
id
,
source_sha
]
...
...
app/services/merge_requests/resolve_service.rb
0 → 100644
View file @
ba327e69
module
MergeRequests
class
ResolveService
<
MergeRequests
::
BaseService
attr_accessor
:conflicts
,
:rugged
,
:merge_index
def
execute
(
merge_request
)
@conflicts
=
merge_request
.
conflicts
@rugged
=
project
.
repository
.
rugged
@merge_index
=
conflicts
.
merge_index
conflicts
.
files
.
each
do
|
file
|
write_resolved_file_to_index
(
file
,
params
[
:sections
])
end
commit_params
=
{
message:
params
[
:commit_message
]
||
conflicts
.
default_commit_message
,
parents:
[
conflicts
.
our_commit
,
conflicts
.
their_commit
].
map
(
&
:oid
),
tree:
merge_index
.
write_tree
(
rugged
)
}
project
.
repository
.
resolve_conflicts
(
current_user
,
merge_request
.
source_branch
,
commit_params
)
end
def
write_resolved_file_to_index
(
file
,
resolutions
)
new_file
=
file
.
resolve_lines
(
resolutions
).
map
(
&
:text
).
join
(
"
\n
"
)
our_path
=
file
.
our_path
merge_index
.
add
(
path:
our_path
,
oid:
rugged
.
write
(
new_file
,
:blob
),
mode:
file
.
our_mode
)
merge_index
.
conflict_remove
(
our_path
)
end
end
end
lib/gitlab/conflict/file.rb
View file @
ba327e69
...
...
@@ -28,14 +28,6 @@ module Gitlab
parent_file:
self
)
end
def
resolve!
(
resolution
,
index
:,
rugged
:)
new_file
=
resolve_lines
(
resolution
).
map
(
&
:text
).
join
(
"
\n
"
)
oid
=
rugged
.
write
(
new_file
,
:blob
)
index
.
add
(
path:
our_path
,
oid:
oid
,
mode:
our_mode
)
index
.
conflict_remove
(
our_path
)
end
def
resolve_lines
(
resolution
)
section_id
=
nil
...
...
lib/gitlab/conflict/file_collection.rb
View file @
ba327e69
...
...
@@ -20,27 +20,6 @@ module Gitlab
@merge_index
||=
repository
.
rugged
.
merge_commits
(
our_commit
,
their_commit
)
end
def
resolve_conflicts!
(
params
,
user
:)
resolutions
=
params
[
:sections
]
commit_message
=
params
[
:commit_message
]
||
default_commit_message
rugged
=
repository
.
rugged
committer
=
repository
.
user_to_committer
(
user
)
files
.
each
do
|
file
|
file
.
resolve!
(
resolutions
,
index:
merge_index
,
rugged:
rugged
)
end
new_tree
=
merge_index
.
write_tree
(
rugged
)
Rugged
::
Commit
.
create
(
rugged
,
author:
committer
,
committer:
committer
,
tree:
new_tree
,
message:
commit_message
,
parents:
[
our_commit
,
their_commit
].
map
(
&
:oid
),
update_ref:
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
merge_request
.
source_branch
)
end
def
files
@files
||=
merge_index
.
conflicts
.
map
do
|
conflict
|
raise
ConflictSideMissing
unless
conflict
[
:theirs
]
&&
conflict
[
:ours
]
...
...
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