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
Jérome Perrin
gitlab-ce
Commits
511d07c4
Commit
511d07c4
authored
Apr 22, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #713 from gitlabhq/fast_automerge
Fast automerge
parents
71819dc3
e5f8397f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
11 deletions
+67
-11
app/models/project/hooks_trait.rb
app/models/project/hooks_trait.rb
+3
-0
app/models/project/repository_trait.rb
app/models/project/repository_trait.rb
+4
-0
lib/gitlab_merge.rb
lib/gitlab_merge.rb
+12
-11
lib/gitlabhq/satellite.rb
lib/gitlabhq/satellite.rb
+41
-0
lib/tasks/gitlab/enable_automerge.rake
lib/tasks/gitlab/enable_automerge.rake
+7
-0
No files found.
app/models/project/hooks_trait.rb
View file @
511d07c4
...
@@ -101,6 +101,9 @@ module Project::HooksTrait
...
@@ -101,6 +101,9 @@ module Project::HooksTrait
# Execute web hooks
# Execute web hooks
self
.
execute_web_hooks
(
oldrev
,
newrev
,
ref
,
user
)
self
.
execute_web_hooks
(
oldrev
,
newrev
,
ref
,
user
)
# Create satellite
self
.
satellite
.
create
unless
self
.
satellite
.
exists?
end
end
end
end
end
end
app/models/project/repository_trait.rb
View file @
511d07c4
...
@@ -37,6 +37,10 @@ module Project::RepositoryTrait
...
@@ -37,6 +37,10 @@ module Project::RepositoryTrait
end
end
end
end
def
satellite
@satellite
||=
Gitlabhq
::
Satellite
.
new
(
self
)
end
def
write_hook
(
name
,
content
)
def
write_hook
(
name
,
content
)
hook_file
=
File
.
join
(
path_to_repo
,
'hooks'
,
name
)
hook_file
=
File
.
join
(
path_to_repo
,
'hooks'
,
name
)
...
...
lib/gitlab_merge.rb
View file @
511d07c4
class
GitlabMerge
class
GitlabMerge
attr_accessor
:project
,
:merge_
path
,
:merge_
request
,
:user
attr_accessor
:project
,
:merge_request
,
:user
def
initialize
(
merge_request
,
user
)
def
initialize
(
merge_request
,
user
)
self
.
user
=
user
self
.
user
=
user
self
.
merge_request
=
merge_request
self
.
merge_request
=
merge_request
self
.
project
=
merge_request
.
project
self
.
project
=
merge_request
.
project
self
.
merge_path
=
File
.
join
(
Rails
.
root
,
"tmp"
,
"merge_repo"
,
project
.
path
,
merge_request
.
id
.
to_s
)
FileUtils
.
rm_rf
(
merge_path
)
FileUtils
.
mkdir_p
merge_path
end
end
def
can_be_merged?
def
can_be_merged?
p
ull
do
|
repo
,
output
|
p
rocess
do
|
repo
,
output
|
!
(
output
=~
/Automatic merge failed/
)
!
(
output
=~
/Automatic merge failed/
)
end
end
end
end
def
merge
def
merge
p
ull
do
|
repo
,
output
|
p
rocess
do
|
repo
,
output
|
if
output
=~
/Automatic merge failed/
if
output
=~
/Automatic merge failed/
false
false
else
else
...
@@ -27,19 +24,23 @@ class GitlabMerge
...
@@ -27,19 +24,23 @@ class GitlabMerge
end
end
end
end
def
p
ull
def
p
rocess
Grit
::
Git
.
with_timeout
(
30
.
seconds
)
do
Grit
::
Git
.
with_timeout
(
30
.
seconds
)
do
File
.
open
(
File
.
join
(
Rails
.
root
,
"tmp"
,
"merge_repo"
,
"
#{
project
.
path
}
.lock"
),
"w+"
)
do
|
f
|
File
.
open
(
File
.
join
(
Rails
.
root
,
"tmp"
,
"merge_repo"
,
"
#{
project
.
path
}
.lock"
),
"w+"
)
do
|
f
|
f
.
flock
(
File
::
LOCK_EX
)
f
.
flock
(
File
::
LOCK_EX
)
self
.
project
.
repo
.
git
.
clone
({
:branch
=>
merge_request
.
target_branch
},
project
.
url_to_repo
,
merge_path
)
unless
project
.
satellite
.
exists?
unless
File
.
exist?
(
self
.
merge_path
)
raise
"You should run: rake gitlab_enable_automerge"
raise
"Gitlab user do not have access to repo. You should run: rake gitlab_enable_automerge"
end
end
Dir
.
chdir
(
merge_path
)
do
project
.
satellite
.
clear
Dir
.
chdir
(
project
.
satellite
.
path
)
do
merge_repo
=
Grit
::
Repo
.
new
(
'.'
)
merge_repo
=
Grit
::
Repo
.
new
(
'.'
)
merge_repo
.
git
.
sh
"git fetch origin"
merge_repo
.
git
.
sh
"git config user.name
\"
#{
user
.
name
}
\"
"
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 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
)
output
=
merge_repo
.
git
.
pull
({},
"--no-ff"
,
"origin"
,
merge_request
.
source_branch
)
yield
(
merge_repo
,
output
)
yield
(
merge_repo
,
output
)
end
end
...
...
lib/gitlabhq/satellite.rb
0 → 100644
View file @
511d07c4
module
Gitlabhq
class
Satellite
PARKING_BRANCH
=
"__parking_branch"
attr_accessor
:project
def
initialize
project
self
.
project
=
project
end
def
create
`git clone
#{
project
.
url_to_repo
}
#{
path
}
`
end
def
path
File
.
join
(
Rails
.
root
,
"tmp"
,
"repo_satellites"
,
project
.
path
)
end
def
exists?
File
.
exists?
path
end
#will be deleted all branches except PARKING_BRANCH
def
clear
Dir
.
chdir
(
path
)
do
heads
=
Grit
::
Repo
.
new
(
"."
).
heads
.
map
{
|
head
|
head
.
name
}
if
heads
.
include?
PARKING_BRANCH
`git checkout
#{
PARKING_BRANCH
}
`
else
`git checkout -b
#{
PARKING_BRANCH
}
`
end
heads
.
delete
(
PARKING_BRANCH
)
heads
.
each
do
|
head
|
`git branch -D
#{
head
}
`
end
end
end
end
end
lib/tasks/gitlab/enable_automerge.rake
View file @
511d07c4
...
@@ -6,6 +6,13 @@ namespace :gitlab do
...
@@ -6,6 +6,13 @@ namespace :gitlab do
git
.
admin_all_repo
git
.
admin_all_repo
end
end
Project
.
find_each
do
|
project
|
if
project
.
repo_exists?
&&
!
project
.
satellite
.
exists?
puts
"Creating satellite for
#{
project
.
name
}
..."
.
green
project
.
satellite
.
create
end
end
puts
"Done!"
.
green
puts
"Done!"
.
green
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