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
iv
gitlab-ce
Commits
2a6f522c
Commit
2a6f522c
authored
Jul 15, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement merge from forks without satellites
parent
2be3c949
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
62 additions
and
22 deletions
+62
-22
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+2
-1
app/models/merge_request.rb
app/models/merge_request.rb
+12
-7
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+4
-2
app/models/repository.rb
app/models/repository.rb
+21
-2
app/services/compare_service.rb
app/services/compare_service.rb
+18
-1
app/services/merge_requests/auto_merge_service.rb
app/services/merge_requests/auto_merge_service.rb
+3
-7
app/views/projects/merge_requests/_new_submit.html.haml
app/views/projects/merge_requests/_new_submit.html.haml
+2
-2
No files found.
app/controllers/projects/merge_requests_controller.rb
View file @
2a6f522c
...
...
@@ -149,7 +149,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
return
access_denied!
unless
@merge_request
.
can_be_merged_by?
(
current_user
)
if
@merge_request
.
automergeable?
AutoMergeWorker
.
perform_async
(
@merge_request
.
id
,
current_user
.
id
,
params
)
#AutoMergeWorker.perform_async(@merge_request.id, current_user.id, params)
@merge_request
.
automerge!
(
current_user
,
params
[
:commit_message
])
@status
=
true
else
@status
=
false
...
...
app/models/merge_request.rb
View file @
2a6f522c
...
...
@@ -206,11 +206,7 @@ class MergeRequest < ActiveRecord::Base
def
check_if_can_be_merged
can_be_merged
=
if
for_fork?
raise
'Implement me'
else
project
.
repository
.
can_be_merged?
(
source_branch
,
target_branch
)
end
project
.
repository
.
can_be_merged?
(
source_sha
,
target_branch
)
if
can_be_merged
mark_as_mergeable
...
...
@@ -274,14 +270,14 @@ class MergeRequest < ActiveRecord::Base
#
# see "git diff"
def
to_diff
(
current_user
)
raise
'Implement me'
target_project
.
repository
.
diff_text
(
target_branch
,
source_sha
)
end
# Returns the commit as a series of email patches.
#
# see "git format-patch"
def
to_patch
(
current_user
)
raise
'Implement me'
target_project
.
repository
.
format_patch
(
target_branch
,
source_sha
)
end
def
hook_attrs
...
...
@@ -432,4 +428,13 @@ class MergeRequest < ActiveRecord::Base
"Open"
end
end
def
target_sha
@target_sha
||=
target_project
.
repository
.
commit
(
target_branch
).
sha
end
def
source_sha
commits
.
first
.
sha
end
end
app/models/merge_request_diff.rb
View file @
2a6f522c
...
...
@@ -160,10 +160,12 @@ class MergeRequestDiff < ActiveRecord::Base
private
def
compare_result
source_sha
=
merge_request
.
source_project
.
commit
(
source_branch
).
sha
@compare_result
||=
CompareService
.
new
.
execute
(
merge_request
.
author
,
merge_request
.
source
_project
,
merge_request
.
source_branch
,
merge_request
.
target
_project
,
source_sha
,
merge_request
.
target_project
,
merge_request
.
target_branch
,
)
...
...
app/models/repository.rb
View file @
2a6f522c
...
...
@@ -422,15 +422,34 @@ class Repository
}
end
def
can_be_merged?
(
source_
branch
,
target_branch
)
def
can_be_merged?
(
source_
sha
,
target_branch
)
our_commit
=
rugged
.
branches
[
target_branch
].
target
their_commit
=
rugged
.
branches
[
source_branch
].
target
their_commit
=
rugged
.
lookup
(
source_sha
)
if
our_commit
&&
their_commit
!
rugged
.
merge_commits
(
our_commit
,
their_commit
).
conflicts?
end
end
def
merge
(
source_sha
,
target_branch
,
options
=
{})
our_commit
=
rugged
.
branches
[
target_branch
].
target
their_commit
=
rugged
.
lookup
(
source_sha
)
raise
"Invalid merge target"
if
our_commit
.
nil?
raise
"Invalid merge source"
if
their_commit
.
nil?
merge_index
=
rugged
.
merge_commits
(
our_commit
,
their_commit
)
return
false
if
merge_index
.
conflicts?
actual_options
=
options
.
merge
(
parents:
[
our_commit
,
their_commit
],
tree:
merge_index
.
write_tree
(
rugged
),
update_ref:
"refs/heads/
#{
target_branch
}
"
)
Rugged
::
Commit
.
create
(
rugged
,
actual_options
)
end
def
search_files
(
query
,
ref
)
offset
=
2
args
=
%W(git grep -i -n --before-context
#{
offset
}
--after-context
#{
offset
}
#{
query
}
#{
ref
||
root_ref
}
)
...
...
app/services/compare_service.rb
View file @
2a6f522c
require
'securerandom'
# Compare 2 branches for one repo or between repositories
# and return Gitlab::CompareResult object that responds to commits and diffs
class
CompareService
...
...
@@ -12,7 +14,22 @@ class CompareService
)
)
else
raise
'Implement me'
random_string
=
SecureRandom
.
hex
target_project
.
repository
.
fetch_ref
(
source_project
.
repository
.
path_to_repo
,
"refs/heads/
#{
source_branch
}
"
,
"refs/tmp/
#{
random_string
}
/head"
)
source_sha
=
source_project
.
commit
(
source_branch
).
sha
Gitlab
::
CompareResult
.
new
(
Gitlab
::
Git
::
Compare
.
new
(
target_project
.
repository
.
raw_repository
,
target_branch
,
source_sha
,
)
)
end
end
end
app/services/merge_requests/auto_merge_service.rb
View file @
2a6f522c
...
...
@@ -31,12 +31,8 @@ module MergeRequests
end
def
merge!
if
merge_request
.
for_fork?
raise
'Implement me'
else
if
sha
=
commit
after_commit
(
sha
,
merge_request
.
target_branch
)
end
if
sha
=
commit
after_commit
(
sha
,
merge_request
.
target_branch
)
end
end
...
...
@@ -49,7 +45,7 @@ module MergeRequests
committer:
committer
}
repository
.
merge
(
merge_request
.
source_
branch
,
merge_request
.
target_branch
,
options
)
repository
.
merge
(
merge_request
.
source_
sha
,
merge_request
.
target_branch
,
options
)
end
def
after_commit
(
sha
,
branch
)
...
...
app/views/projects/merge_requests/_new_submit.html.haml
View file @
2a6f522c
...
...
@@ -24,7 +24,7 @@
=
icon
(
'history'
)
Commits
%span
.badge
=
@commits
.
size
%li
.diffs-tab
%li
.diffs-tab
.active
=
link_to
url_for
(
params
),
data:
{
target:
'#diffs'
,
action:
'diffs'
,
toggle:
'tab'
}
do
=
icon
(
'list-alt'
)
Changes
...
...
@@ -33,7 +33,7 @@
.tab-content
#commits
.commits.tab-pane
=
render
"projects/commits/commits"
,
project:
@project
#diffs
.diffs.tab-pane
#diffs
.diffs.tab-pane
.active
-
if
@diffs
.
present?
=
render
"projects/diffs/diffs"
,
diffs:
@diffs
,
project:
@project
-
elsif
@commits
.
size
>
MergeRequestDiff
::
COMMITS_SAFE_SIZE
...
...
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