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
5ec1ad8b
Commit
5ec1ad8b
authored
Oct 21, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1743 from riyad/fix-merging-bugs
Fix merging bugs
parents
51ef5b92
d4e36640
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
34 deletions
+74
-34
app/models/merge_request.rb
app/models/merge_request.rb
+3
-2
lib/gitlab/merge.rb
lib/gitlab/merge.rb
+71
-32
No files found.
app/models/merge_request.rb
View file @
5ec1ad8b
...
@@ -135,7 +135,8 @@ class MergeRequest < ActiveRecord::Base
...
@@ -135,7 +135,8 @@ class MergeRequest < ActiveRecord::Base
end
end
def
mark_as_unmergable
def
mark_as_unmergable
self
.
update_attributes
state:
CANNOT_BE_MERGED
self
.
state
=
CANNOT_BE_MERGED
self
.
save
end
end
def
reloaded_commits
def
reloaded_commits
...
@@ -166,7 +167,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -166,7 +167,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
automerge!
(
current_user
)
def
automerge!
(
current_user
)
if
Gitlab
::
Merge
.
new
(
self
,
current_user
).
merge
&&
self
.
unmerged_commits
.
empty?
if
Gitlab
::
Merge
.
new
(
self
,
current_user
).
merge
!
&&
self
.
unmerged_commits
.
empty?
self
.
merge!
(
current_user
.
id
)
self
.
merge!
(
current_user
.
id
)
true
true
end
end
...
...
lib/gitlab/merge.rb
View file @
5ec1ad8b
module
Gitlab
module
Gitlab
class
Merge
class
Merge
attr_accessor
:
project
,
:merge_reques
t
,
:user
attr_accessor
:
merge_request
,
:projec
t
,
:user
def
initialize
(
merge_request
,
user
)
def
initialize
(
merge_request
,
user
)
self
.
user
=
user
@merge_request
=
merge_request
self
.
merge_request
=
merge_reques
t
@project
=
merge_request
.
projec
t
self
.
project
=
merge_request
.
project
@user
=
user
end
end
def
can_be_merged?
def
can_be_merged?
result
=
false
in_locked_and_timed_satellite
do
|
merge_repo
|
process
do
|
repo
,
output
|
merge_in_satellite!
(
merge_repo
)
result
=
!
(
output
=~
/CONFLICT/
)
end
end
result
end
end
def
merge
# Merges the source branch into the target branch in the satellite and
process
do
|
repo
,
output
|
# pushes it back to Gitolite.
if
output
=~
/CONFLICT/
# It also removes the source branch if requested in the merge request.
false
#
else
# Returns false if the merge produced conflicts
!!
repo
.
git
.
push
({},
"origin"
,
merge_request
.
target_branch
)
# Returns false if pushing from the satallite to Gitolite failed or was rejected
# Returns true otherwise
def
merge!
in_locked_and_timed_satellite
do
|
merge_repo
|
if
merge_in_satellite!
(
merge_repo
)
# push merge back to Gitolite
# will raise CommandFailed when push fails
merge_repo
.
git
.
push
({
raise:
true
},
:origin
,
merge_request
.
target_branch
)
# remove source branch
if
merge_request
.
should_remove_source_branch
&&
!
project
.
root_ref?
(
merge_request
.
source_branch
)
# will raise CommandFailed when push fails
merge_repo
.
git
.
push
({
raise:
true
},
:origin
,
":
#{
merge_request
.
source_branch
}
"
)
end
# merge, push and branch removal successful
true
end
end
end
end
rescue
Grit
::
Git
::
CommandFailed
false
end
end
def
process
private
# * Sets a 30s timeout for Git
# * Locks the satellite repo
# * Yields the prepared satallite repo
def
in_locked_and_timed_satellite
Grit
::
Git
.
with_timeout
(
30
.
seconds
)
do
Grit
::
Git
.
with_timeout
(
30
.
seconds
)
do
lock_file
=
Rails
.
root
.
join
(
"tmp"
,
"
#{
project
.
path
}
.lock"
)
lock_file
=
Rails
.
root
.
join
(
"tmp"
,
"
#{
project
.
path
}
.lock"
)
...
@@ -37,29 +58,47 @@ module Gitlab
...
@@ -37,29 +58,47 @@ module Gitlab
raise
"Satellite doesn't exist"
raise
"Satellite doesn't exist"
end
end
project
.
satellite
.
clear
Dir
.
chdir
(
project
.
satellite
.
path
)
do
Dir
.
chdir
(
project
.
satellite
.
path
)
do
merge_repo
=
Grit
::
Repo
.
new
(
'.'
)
repo
=
Grit
::
Repo
.
new
(
'.'
)
merge_repo
.
git
.
sh
"git reset --hard"
merge_repo
.
git
.
sh
"git fetch origin"
return
yield
repo
merge_repo
.
git
.
sh
"git config user.name
\"
#{
user
.
name
}
\"
"
merge_repo
.
git
.
sh
"git config user.email
\"
#{
user
.
email
}
\"
"
merge_repo
.
git
.
sh
"git checkout -b
#{
merge_request
.
target_branch
}
origin/
#{
merge_request
.
target_branch
}
"
output
=
merge_repo
.
git
.
pull
({},
"--no-ff"
,
"origin"
,
merge_request
.
source_branch
)
#remove source-branch
if
merge_request
.
should_remove_source_branch
&&
!
project
.
root_ref?
(
merge_request
.
source_branch
)
merge_repo
.
git
.
sh
"git push origin :
#{
merge_request
.
source_branch
}
"
end
yield
(
merge_repo
,
output
)
end
end
end
end
end
end
rescue
Grit
::
Git
::
GitTimeout
rescue
Grit
::
Git
::
GitTimeout
return
false
return
false
end
end
# Merges the source_branch into the target_branch in the satellite.
#
# Note: it will clear out the satellite before doing anything
#
# Returns false if the merge produced conflicts
# Returns true otherwise
def
merge_in_satellite!
(
repo
)
prepare_satelite!
(
repo
)
# 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
}
"
)
# merge the source branch from Gitolite into the satellite
# will raise CommandFailed when merge fails
repo
.
git
.
pull
({
no_ff:
true
,
raise:
true
},
:origin
,
merge_request
.
source_branch
)
rescue
Grit
::
Git
::
CommandFailed
false
end
# * Clears the satellite
# * Updates the satellite from Gitolite
# * Sets up Git variables for the user
def
prepare_satelite!
(
repo
)
project
.
satellite
.
clear
repo
.
git
.
reset
(
hard:
true
)
repo
.
git
.
fetch
({},
:origin
)
repo
.
git
.
config
({},
"user.name"
,
user
.
name
)
repo
.
git
.
config
({},
"user.email"
,
user
.
email
)
end
end
end
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