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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
59723625
Commit
59723625
authored
May 26, 2012
by
randx
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'lib_refactoring'
parents
8ceb9408
3272620f
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
87 additions
and
85 deletions
+87
-85
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+1
-1
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+1
-1
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+1
-1
app/models/commit.rb
app/models/commit.rb
+1
-1
app/models/key.rb
app/models/key.rb
+2
-2
app/models/merge_request.rb
app/models/merge_request.rb
+2
-2
app/models/project/repository_trait.rb
app/models/project/repository_trait.rb
+4
-4
app/models/protected_branch.rb
app/models/protected_branch.rb
+1
-1
app/models/users_project.rb
app/models/users_project.rb
+1
-1
config/environment.rb
config/environment.rb
+1
-1
config/initializers/gitlabhq/20_grit_ext.rb
config/initializers/gitlabhq/20_grit_ext.rb
+2
-2
lib/gitlab/encode.rb
lib/gitlab/encode.rb
+1
-1
lib/gitlab/git_host.rb
lib/gitlab/git_host.rb
+3
-3
lib/gitlab/gitolite.rb
lib/gitlab/gitolite.rb
+2
-2
lib/gitlab/logger.rb
lib/gitlab/logger.rb
+1
-1
lib/gitlab/merge.rb
lib/gitlab/merge.rb
+60
-0
lib/gitlab/satellite.rb
lib/gitlab/satellite.rb
+1
-1
lib/gitlab_merge.rb
lib/gitlab_merge.rb
+0
-58
lib/tasks/gitlab/enable_automerge.rake
lib/tasks/gitlab/enable_automerge.rake
+1
-1
spec/models/protected_branch_spec.rb
spec/models/protected_branch_spec.rb
+1
-1
No files found.
app/controllers/application_controller.rb
View file @
59723625
...
...
@@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery
helper_method
:abilities
,
:can?
rescue_from
Gitlab
hq
::
Gitolite
::
AccessDenied
do
|
exception
|
rescue_from
Gitlab
::
Gitolite
::
AccessDenied
do
|
exception
|
render
"errors/gitolite"
,
:layout
=>
"error"
end
...
...
app/controllers/projects_controller.rb
View file @
59723625
...
...
@@ -45,7 +45,7 @@ class ProjectsController < ApplicationController
format
.
js
end
end
rescue
Gitlab
hq
::
Gitolite
::
AccessDenied
rescue
Gitlab
::
Gitolite
::
AccessDenied
render
:js
=>
"location.href = '
#{
errors_githost_path
}
'"
and
return
rescue
StandardError
=>
ex
@project
.
errors
.
add
(
:base
,
"Cant save project. Please try again later"
)
...
...
app/helpers/application_helper.rb
View file @
59723625
...
...
@@ -143,6 +143,6 @@ module ApplicationHelper
end
def
string_to_utf8
str
Gitlab
hq
::
Encode
.
utf8
str
Gitlab
::
Encode
.
utf8
str
end
end
app/models/commit.rb
View file @
59723625
class
Commit
include
ActiveModel
::
Conversion
include
Gitlab
hq
::
Encode
include
Gitlab
::
Encode
extend
ActiveModel
::
Naming
attr_accessor
:commit
...
...
app/models/key.rb
View file @
59723625
...
...
@@ -38,14 +38,14 @@ class Key < ActiveRecord::Base
end
def
update_repository
Gitlab
hq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
Gitlab
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
update_keys
(
identifier
,
key
)
c
.
update_projects
(
projects
)
end
end
def
repository_delete_key
Gitlab
hq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
Gitlab
::
GitHost
.
system
.
new
.
configure
do
|
c
|
#delete key file is there is no identically deploy keys
if
!
is_deploy_key
||
Key
.
where
(
:identifier
=>
identifier
).
count
()
==
0
c
.
delete_key
(
identifier
)
...
...
app/models/merge_request.rb
View file @
59723625
...
...
@@ -82,7 +82,7 @@ class MergeRequest < ActiveRecord::Base
end
def
check_if_can_be_merged
self
.
state
=
if
GitlabMerge
.
new
(
self
,
self
.
author
).
can_be_merged?
self
.
state
=
if
Gitlab
::
Merge
.
new
(
self
,
self
.
author
).
can_be_merged?
CAN_BE_MERGED
else
CANNOT_BE_MERGED
...
...
@@ -184,7 +184,7 @@ class MergeRequest < ActiveRecord::Base
end
def
automerge!
(
current_user
)
if
GitlabMerge
.
new
(
self
,
current_user
).
merge
if
Gitlab
::
Merge
.
new
(
self
,
current_user
).
merge
self
.
merge!
(
current_user
.
id
)
true
end
...
...
app/models/project/repository_trait.rb
View file @
59723625
...
...
@@ -38,7 +38,7 @@ module Project::RepositoryTrait
end
def
satellite
@satellite
||=
Gitlab
hq
::
Satellite
.
new
(
self
)
@satellite
||=
Gitlab
::
Satellite
.
new
(
self
)
end
def
write_hook
(
name
,
content
)
...
...
@@ -65,7 +65,7 @@ module Project::RepositoryTrait
end
def
url_to_repo
Gitlab
hq
::
GitHost
.
url_to_repo
(
path
)
Gitlab
::
GitHost
.
url_to_repo
(
path
)
end
def
path_to_repo
...
...
@@ -73,13 +73,13 @@ module Project::RepositoryTrait
end
def
update_repository
Gitlab
hq
::
GitHost
.
system
.
update_project
(
path
,
self
)
Gitlab
::
GitHost
.
system
.
update_project
(
path
,
self
)
write_hooks
if
File
.
exists?
(
path_to_repo
)
end
def
destroy_repository
Gitlab
hq
::
GitHost
.
system
.
destroy_project
(
self
)
Gitlab
::
GitHost
.
system
.
destroy_project
(
self
)
end
def
repo_exists?
...
...
app/models/protected_branch.rb
View file @
59723625
...
...
@@ -7,7 +7,7 @@ class ProtectedBranch < ActiveRecord::Base
after_destroy
:update_repository
def
update_repository
Gitlab
hq
::
GitHost
.
system
.
update_project
(
project
.
path
,
project
)
Gitlab
::
GitHost
.
system
.
update_project
(
project
.
path
,
project
)
end
def
commit
...
...
app/models/users_project.rb
View file @
59723625
...
...
@@ -58,7 +58,7 @@ class UsersProject < ActiveRecord::Base
end
def
update_repository
Gitlab
hq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
Gitlab
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
update_project
(
project
.
path
,
project
)
end
end
...
...
config/environment.rb
View file @
59723625
...
...
@@ -4,4 +4,4 @@ require File.expand_path('../application', __FILE__)
# Initialize the rails application
Gitlab
::
Application
.
initialize!
require
File
.
join
(
Rails
.
root
,
"lib"
,
"gitlab
hq
"
,
"git_host"
)
require
File
.
join
(
Rails
.
root
,
"lib"
,
"gitlab"
,
"git_host"
)
config/initializers/gitlabhq/20_grit_ext.rb
View file @
59723625
...
...
@@ -15,11 +15,11 @@ end
Grit
::
Diff
.
class_eval
do
def
old_path
Gitlab
hq
::
Encode
.
utf8
a_path
Gitlab
::
Encode
.
utf8
a_path
end
def
new_path
Gitlab
hq
::
Encode
.
utf8
b_path
Gitlab
::
Encode
.
utf8
b_path
end
end
...
...
lib/gitlab
hq
/encode.rb
→
lib/gitlab/encode.rb
View file @
59723625
module
Gitlab
hq
module
Gitlab
module
Encode
extend
self
...
...
lib/gitlab
hq
/git_host.rb
→
lib/gitlab/git_host.rb
View file @
59723625
require
File
.
join
(
Rails
.
root
,
"lib"
,
"gitlab
hq
"
,
"gitolite"
)
require
File
.
join
(
Rails
.
root
,
"lib"
,
"gitlab"
,
"gitolite"
)
module
Gitlab
hq
module
Gitlab
class
GitHost
def
self
.
system
Gitlab
hq
::
Gitolite
Gitlab
::
Gitolite
end
def
self
.
admin_uri
...
...
lib/gitlab
hq
/gitolite.rb
→
lib/gitlab/gitolite.rb
View file @
59723625
...
...
@@ -2,7 +2,7 @@ require 'gitolite'
require
'timeout'
require
'fileutils'
module
Gitlab
hq
module
Gitlab
class
Gitolite
class
AccessDenied
<
StandardError
;
end
...
...
@@ -46,7 +46,7 @@ module Gitlabhq
end
end
rescue
Exception
=>
ex
Gitlab
hq
::
Logger
.
error
(
ex
.
message
)
Gitlab
::
Logger
.
error
(
ex
.
message
)
raise
Gitolite
::
AccessDenied
.
new
(
"gitolite timeout"
)
end
...
...
lib/gitlab
hq
/logger.rb
→
lib/gitlab/logger.rb
View file @
59723625
module
Gitlab
hq
module
Gitlab
class
Logger
def
self
.
error
(
message
)
@@logger
||=
::
Logger
.
new
(
File
.
join
(
Rails
.
root
,
"log/githost.log"
))
...
...
lib/gitlab/merge.rb
0 → 100644
View file @
59723625
module
Gitlab
class
Merge
attr_accessor
:project
,
:merge_request
,
:user
def
initialize
(
merge_request
,
user
)
self
.
user
=
user
self
.
merge_request
=
merge_request
self
.
project
=
merge_request
.
project
end
def
can_be_merged?
result
=
false
process
do
|
repo
,
output
|
result
=
!
(
output
=~
/CONFLICT/
)
end
result
end
def
merge
process
do
|
repo
,
output
|
if
output
=~
/CONFLICT/
false
else
repo
.
git
.
push
({},
"origin"
,
merge_request
.
target_branch
)
true
end
end
end
def
process
Grit
::
Git
.
with_timeout
(
30
.
seconds
)
do
lock_file
=
File
.
join
(
Rails
.
root
,
"tmp"
,
"merge_repo_
#{
project
.
path
}
.lock"
)
File
.
open
(
lock_file
,
"w+"
)
do
|
f
|
f
.
flock
(
File
::
LOCK_EX
)
unless
project
.
satellite
.
exists?
raise
"You should run: rake gitlab:app:enable_automerge"
end
project
.
satellite
.
clear
Dir
.
chdir
(
project
.
satellite
.
path
)
do
merge_repo
=
Grit
::
Repo
.
new
(
'.'
)
merge_repo
.
git
.
sh
"git reset --hard"
merge_repo
.
git
.
sh
"git fetch origin"
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
)
yield
(
merge_repo
,
output
)
end
end
end
rescue
Grit
::
Git
::
GitTimeout
return
false
end
end
end
lib/gitlab
hq
/satellite.rb
→
lib/gitlab/satellite.rb
View file @
59723625
module
Gitlab
hq
module
Gitlab
class
Satellite
PARKING_BRANCH
=
"__parking_branch"
...
...
lib/gitlab_merge.rb
deleted
100644 → 0
View file @
8ceb9408
class
GitlabMerge
attr_accessor
:project
,
:merge_request
,
:user
def
initialize
(
merge_request
,
user
)
self
.
user
=
user
self
.
merge_request
=
merge_request
self
.
project
=
merge_request
.
project
end
def
can_be_merged?
result
=
false
process
do
|
repo
,
output
|
result
=
!
(
output
=~
/CONFLICT/
)
end
result
end
def
merge
process
do
|
repo
,
output
|
if
output
=~
/CONFLICT/
false
else
repo
.
git
.
push
({},
"origin"
,
merge_request
.
target_branch
)
true
end
end
end
def
process
Grit
::
Git
.
with_timeout
(
30
.
seconds
)
do
lock_file
=
File
.
join
(
Rails
.
root
,
"tmp"
,
"merge_repo_
#{
project
.
path
}
.lock"
)
File
.
open
(
lock_file
,
"w+"
)
do
|
f
|
f
.
flock
(
File
::
LOCK_EX
)
unless
project
.
satellite
.
exists?
raise
"You should run: rake gitlab:app:enable_automerge"
end
project
.
satellite
.
clear
Dir
.
chdir
(
project
.
satellite
.
path
)
do
merge_repo
=
Grit
::
Repo
.
new
(
'.'
)
merge_repo
.
git
.
sh
"git reset --hard"
merge_repo
.
git
.
sh
"git fetch origin"
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
)
yield
(
merge_repo
,
output
)
end
end
end
rescue
Grit
::
Git
::
GitTimeout
return
false
end
end
lib/tasks/gitlab/enable_automerge.rake
View file @
59723625
...
...
@@ -2,7 +2,7 @@ namespace :gitlab do
namespace
:app
do
desc
"GITLAB | Enable auto merge"
task
:enable_automerge
=>
:environment
do
Gitlab
hq
::
GitHost
.
system
.
new
.
configure
do
|
git
|
Gitlab
::
GitHost
.
system
.
new
.
configure
do
|
git
|
git
.
admin_all_repo
end
...
...
spec/models/protected_branch_spec.rb
View file @
59723625
...
...
@@ -43,7 +43,7 @@ describe ProtectedBranch do
subject
{
ProtectedBranch
.
new
(
:project
=>
project
)
}
it
"updates the branch's project repo permissions"
do
Gitlab
hq
::
GitHost
.
should_receive
(
:system
).
and_return
(
gitolite
)
Gitlab
::
GitHost
.
should_receive
(
:system
).
and_return
(
gitolite
)
gitolite
.
should_receive
(
:update_project
).
with
(
project
.
path
,
project
)
subject
.
update_repository
...
...
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