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
Boxiang Sun
gitlab-ce
Commits
78235edd
Commit
78235edd
authored
Oct 26, 2012
by
Riyad Preukschas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed Gitlab::Merge to Gitlab::Satellite::MergeAction
parent
847bba92
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
108 deletions
+85
-108
app/models/merge_request.rb
app/models/merge_request.rb
+2
-2
lib/gitlab/merge.rb
lib/gitlab/merge.rb
+0
-106
lib/gitlab/satellite/merge_action.rb
lib/gitlab/satellite/merge_action.rb
+83
-0
No files found.
app/models/merge_request.rb
View file @
78235edd
...
...
@@ -60,7 +60,7 @@ class MergeRequest < ActiveRecord::Base
end
def
check_if_can_be_merged
self
.
state
=
if
Gitlab
::
Merge
.
new
(
self
,
self
.
author
).
can_be_merged?
self
.
state
=
if
Gitlab
::
Satellite
::
MergeAction
.
new
(
self
,
self
.
author
).
can_be_merged?
CAN_BE_MERGED
else
CANNOT_BE_MERGED
...
...
@@ -167,7 +167,7 @@ class MergeRequest < ActiveRecord::Base
end
def
automerge!
(
current_user
)
if
Gitlab
::
Merge
.
new
(
self
,
current_user
).
merge!
&&
self
.
unmerged_commits
.
empty?
if
Gitlab
::
Satellite
::
MergeAction
.
new
(
self
,
current_user
).
merge!
&&
self
.
unmerged_commits
.
empty?
self
.
merge!
(
current_user
.
id
)
true
end
...
...
lib/gitlab/merge.rb
deleted
100644 → 0
View file @
847bba92
module
Gitlab
class
Merge
attr_accessor
:merge_request
,
:project
,
:user
def
initialize
(
merge_request
,
user
)
@merge_request
=
merge_request
@project
=
merge_request
.
project
@user
=
user
end
def
can_be_merged?
in_locked_and_timed_satellite
do
|
merge_repo
|
merge_in_satellite!
(
merge_repo
)
end
end
# Merges the source branch into the target branch in the satellite and
# pushes it back to Gitolite.
# It also removes the source branch if requested in the merge request.
#
# Returns false if the merge produced conflicts
# Returns false if pushing from the satellite 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
rescue
Grit
::
Git
::
CommandFailed
false
end
private
# * Sets a 30s timeout for Git
# * Locks the satellite repo
# * Yields the prepared satellite repo
def
in_locked_and_timed_satellite
Grit
::
Git
.
with_timeout
(
30
.
seconds
)
do
lock_file
=
Rails
.
root
.
join
(
"tmp"
,
"
#{
project
.
path
}
.lock"
)
File
.
open
(
lock_file
,
"w+"
)
do
|
f
|
f
.
flock
(
File
::
LOCK_EX
)
unless
project
.
satellite
.
exists?
raise
"Satellite doesn't exist"
end
Dir
.
chdir
(
project
.
satellite
.
path
)
do
repo
=
Grit
::
Repo
.
new
(
'.'
)
return
yield
repo
end
end
end
rescue
Errno
::
ENOMEM
=>
ex
Gitlab
::
GitLogger
.
error
(
ex
.
message
)
rescue
Grit
::
Git
::
GitTimeout
return
false
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_satellite!
(
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_satellite!
(
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
lib/gitlab/satellite/merge_action.rb
0 → 100644
View file @
78235edd
module
Gitlab
module
Satellite
class
MergeAction
<
Action
attr_accessor
:merge_request
,
:user
def
initialize
(
merge_request
,
user
)
super
merge_request
.
project
@merge_request
=
merge_request
@user
=
user
end
def
can_be_merged?
in_locked_and_timed_satellite
do
|
merge_repo
|
merge_in_satellite!
(
merge_repo
)
end
end
# Merges the source branch into the target branch in the satellite and
# pushes it back to Gitolite.
# It also removes the source branch if requested in the merge request.
#
# Returns false if the merge produced conflicts
# Returns false if pushing from the satellite 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
rescue
Grit
::
Git
::
CommandFailed
=>
ex
Gitlab
::
GitLogger
.
error
(
ex
.
message
)
false
end
private
# 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_satellite!
(
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
=>
ex
Gitlab
::
GitLogger
.
error
(
ex
.
message
)
false
end
# * Clears the satellite
# * Updates the satellite from Gitolite
# * Sets up Git variables for the user
def
prepare_satellite!
(
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
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