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
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
Hide 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
...
@@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery
protect_from_forgery
helper_method
:abilities
,
:can?
helper_method
:abilities
,
:can?
rescue_from
Gitlab
hq
::
Gitolite
::
AccessDenied
do
|
exception
|
rescue_from
Gitlab
::
Gitolite
::
AccessDenied
do
|
exception
|
render
"errors/gitolite"
,
:layout
=>
"error"
render
"errors/gitolite"
,
:layout
=>
"error"
end
end
...
...
app/controllers/projects_controller.rb
View file @
59723625
...
@@ -45,7 +45,7 @@ class ProjectsController < ApplicationController
...
@@ -45,7 +45,7 @@ class ProjectsController < ApplicationController
format
.
js
format
.
js
end
end
end
end
rescue
Gitlab
hq
::
Gitolite
::
AccessDenied
rescue
Gitlab
::
Gitolite
::
AccessDenied
render
:js
=>
"location.href = '
#{
errors_githost_path
}
'"
and
return
render
:js
=>
"location.href = '
#{
errors_githost_path
}
'"
and
return
rescue
StandardError
=>
ex
rescue
StandardError
=>
ex
@project
.
errors
.
add
(
:base
,
"Cant save project. Please try again later"
)
@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
...
@@ -143,6 +143,6 @@ module ApplicationHelper
end
end
def
string_to_utf8
str
def
string_to_utf8
str
Gitlab
hq
::
Encode
.
utf8
str
Gitlab
::
Encode
.
utf8
str
end
end
end
end
app/models/commit.rb
View file @
59723625
class
Commit
class
Commit
include
ActiveModel
::
Conversion
include
ActiveModel
::
Conversion
include
Gitlab
hq
::
Encode
include
Gitlab
::
Encode
extend
ActiveModel
::
Naming
extend
ActiveModel
::
Naming
attr_accessor
:commit
attr_accessor
:commit
...
...
app/models/key.rb
View file @
59723625
...
@@ -38,14 +38,14 @@ class Key < ActiveRecord::Base
...
@@ -38,14 +38,14 @@ class Key < ActiveRecord::Base
end
end
def
update_repository
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_keys
(
identifier
,
key
)
c
.
update_projects
(
projects
)
c
.
update_projects
(
projects
)
end
end
end
end
def
repository_delete_key
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
#delete key file is there is no identically deploy keys
if
!
is_deploy_key
||
Key
.
where
(
:identifier
=>
identifier
).
count
()
==
0
if
!
is_deploy_key
||
Key
.
where
(
:identifier
=>
identifier
).
count
()
==
0
c
.
delete_key
(
identifier
)
c
.
delete_key
(
identifier
)
...
...
app/models/merge_request.rb
View file @
59723625
...
@@ -82,7 +82,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -82,7 +82,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
check_if_can_be_merged
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
CAN_BE_MERGED
else
else
CANNOT_BE_MERGED
CANNOT_BE_MERGED
...
@@ -184,7 +184,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -184,7 +184,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
automerge!
(
current_user
)
def
automerge!
(
current_user
)
if
GitlabMerge
.
new
(
self
,
current_user
).
merge
if
Gitlab
::
Merge
.
new
(
self
,
current_user
).
merge
self
.
merge!
(
current_user
.
id
)
self
.
merge!
(
current_user
.
id
)
true
true
end
end
...
...
app/models/project/repository_trait.rb
View file @
59723625
...
@@ -38,7 +38,7 @@ module Project::RepositoryTrait
...
@@ -38,7 +38,7 @@ module Project::RepositoryTrait
end
end
def
satellite
def
satellite
@satellite
||=
Gitlab
hq
::
Satellite
.
new
(
self
)
@satellite
||=
Gitlab
::
Satellite
.
new
(
self
)
end
end
def
write_hook
(
name
,
content
)
def
write_hook
(
name
,
content
)
...
@@ -65,7 +65,7 @@ module Project::RepositoryTrait
...
@@ -65,7 +65,7 @@ module Project::RepositoryTrait
end
end
def
url_to_repo
def
url_to_repo
Gitlab
hq
::
GitHost
.
url_to_repo
(
path
)
Gitlab
::
GitHost
.
url_to_repo
(
path
)
end
end
def
path_to_repo
def
path_to_repo
...
@@ -73,13 +73,13 @@ module Project::RepositoryTrait
...
@@ -73,13 +73,13 @@ module Project::RepositoryTrait
end
end
def
update_repository
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
)
write_hooks
if
File
.
exists?
(
path_to_repo
)
end
end
def
destroy_repository
def
destroy_repository
Gitlab
hq
::
GitHost
.
system
.
destroy_project
(
self
)
Gitlab
::
GitHost
.
system
.
destroy_project
(
self
)
end
end
def
repo_exists?
def
repo_exists?
...
...
app/models/protected_branch.rb
View file @
59723625
...
@@ -7,7 +7,7 @@ class ProtectedBranch < ActiveRecord::Base
...
@@ -7,7 +7,7 @@ class ProtectedBranch < ActiveRecord::Base
after_destroy
:update_repository
after_destroy
:update_repository
def
update_repository
def
update_repository
Gitlab
hq
::
GitHost
.
system
.
update_project
(
project
.
path
,
project
)
Gitlab
::
GitHost
.
system
.
update_project
(
project
.
path
,
project
)
end
end
def
commit
def
commit
...
...
app/models/users_project.rb
View file @
59723625
...
@@ -58,7 +58,7 @@ class UsersProject < ActiveRecord::Base
...
@@ -58,7 +58,7 @@ class UsersProject < ActiveRecord::Base
end
end
def
update_repository
def
update_repository
Gitlab
hq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
Gitlab
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
update_project
(
project
.
path
,
project
)
c
.
update_project
(
project
.
path
,
project
)
end
end
end
end
...
...
config/environment.rb
View file @
59723625
...
@@ -4,4 +4,4 @@ require File.expand_path('../application', __FILE__)
...
@@ -4,4 +4,4 @@ require File.expand_path('../application', __FILE__)
# Initialize the rails application
# Initialize the rails application
Gitlab
::
Application
.
initialize!
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
...
@@ -15,11 +15,11 @@ end
Grit
::
Diff
.
class_eval
do
Grit
::
Diff
.
class_eval
do
def
old_path
def
old_path
Gitlab
hq
::
Encode
.
utf8
a_path
Gitlab
::
Encode
.
utf8
a_path
end
end
def
new_path
def
new_path
Gitlab
hq
::
Encode
.
utf8
b_path
Gitlab
::
Encode
.
utf8
b_path
end
end
end
end
...
...
lib/gitlab
hq
/encode.rb
→
lib/gitlab/encode.rb
View file @
59723625
module
Gitlab
hq
module
Gitlab
module
Encode
module
Encode
extend
self
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
class
GitHost
def
self
.
system
def
self
.
system
Gitlab
hq
::
Gitolite
Gitlab
::
Gitolite
end
end
def
self
.
admin_uri
def
self
.
admin_uri
...
...
lib/gitlab
hq
/gitolite.rb
→
lib/gitlab/gitolite.rb
View file @
59723625
...
@@ -2,7 +2,7 @@ require 'gitolite'
...
@@ -2,7 +2,7 @@ require 'gitolite'
require
'timeout'
require
'timeout'
require
'fileutils'
require
'fileutils'
module
Gitlab
hq
module
Gitlab
class
Gitolite
class
Gitolite
class
AccessDenied
<
StandardError
;
end
class
AccessDenied
<
StandardError
;
end
...
@@ -46,7 +46,7 @@ module Gitlabhq
...
@@ -46,7 +46,7 @@ module Gitlabhq
end
end
end
end
rescue
Exception
=>
ex
rescue
Exception
=>
ex
Gitlab
hq
::
Logger
.
error
(
ex
.
message
)
Gitlab
::
Logger
.
error
(
ex
.
message
)
raise
Gitolite
::
AccessDenied
.
new
(
"gitolite timeout"
)
raise
Gitolite
::
AccessDenied
.
new
(
"gitolite timeout"
)
end
end
...
...
lib/gitlab
hq
/logger.rb
→
lib/gitlab/logger.rb
View file @
59723625
module
Gitlab
hq
module
Gitlab
class
Logger
class
Logger
def
self
.
error
(
message
)
def
self
.
error
(
message
)
@@logger
||=
::
Logger
.
new
(
File
.
join
(
Rails
.
root
,
"log/githost.log"
))
@@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
class
Satellite
PARKING_BRANCH
=
"__parking_branch"
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
...
@@ -2,7 +2,7 @@ namespace :gitlab do
namespace
:app
do
namespace
:app
do
desc
"GITLAB | Enable auto merge"
desc
"GITLAB | Enable auto merge"
task
:enable_automerge
=>
:environment
do
task
:enable_automerge
=>
:environment
do
Gitlab
hq
::
GitHost
.
system
.
new
.
configure
do
|
git
|
Gitlab
::
GitHost
.
system
.
new
.
configure
do
|
git
|
git
.
admin_all_repo
git
.
admin_all_repo
end
end
...
...
spec/models/protected_branch_spec.rb
View file @
59723625
...
@@ -43,7 +43,7 @@ describe ProtectedBranch do
...
@@ -43,7 +43,7 @@ describe ProtectedBranch do
subject
{
ProtectedBranch
.
new
(
:project
=>
project
)
}
subject
{
ProtectedBranch
.
new
(
:project
=>
project
)
}
it
"updates the branch's project repo permissions"
do
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
)
gitolite
.
should_receive
(
:update_project
).
with
(
project
.
path
,
project
)
subject
.
update_repository
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