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
bdc65809
Commit
bdc65809
authored
Dec 05, 2011
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refcatoring. cleaning after gitosis
parent
8134fe0e
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
58 additions
and
124 deletions
+58
-124
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+2
-2
app/controllers/errors_controller.rb
app/controllers/errors_controller.rb
+2
-2
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+2
-2
app/models/key.rb
app/models/key.rb
+6
-6
app/models/project.rb
app/models/project.rb
+7
-7
app/models/repository.rb
app/models/repository.rb
+4
-8
app/models/users_project.rb
app/models/users_project.rb
+3
-3
config/routes.rb
config/routes.rb
+1
-1
lib/gitlabhq/git_host.rb
lib/gitlabhq/git_host.rb
+9
-6
lib/gitlabhq/gitosis.rb
lib/gitlabhq/gitosis.rb
+0
-76
lib/tasks/gitolite_rebuild.rake
lib/tasks/gitolite_rebuild.rake
+11
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+5
-5
spec/monkeypatch.rb
spec/monkeypatch.rb
+6
-6
No files found.
app/controllers/application_controller.rb
View file @
bdc65809
...
@@ -3,8 +3,8 @@ class ApplicationController < ActionController::Base
...
@@ -3,8 +3,8 @@ class ApplicationController < ActionController::Base
protect_from_forgery
protect_from_forgery
helper_method
:abilities
,
:can?
helper_method
:abilities
,
:can?
rescue_from
Gitlabhq
::
Gito
sis
::
AccessDenied
,
Gitlabhq
::
Gito
lite
::
AccessDenied
do
|
exception
|
rescue_from
Gitlabhq
::
Gitolite
::
AccessDenied
do
|
exception
|
render
:file
=>
File
.
join
(
Rails
.
root
,
"public"
,
"git
osis
_error"
),
:layout
=>
false
render
:file
=>
File
.
join
(
Rails
.
root
,
"public"
,
"git
host
_error"
),
:layout
=>
false
end
end
layout
:layout_by_resource
layout
:layout_by_resource
...
...
app/controllers/errors_controller.rb
View file @
bdc65809
class
ErrorsController
<
ApplicationController
class
ErrorsController
<
ApplicationController
def
git
osis
def
git
host
render
:file
=>
File
.
join
(
Rails
.
root
,
"public"
,
"git
osis
_error"
),
:layout
=>
false
render
:file
=>
File
.
join
(
Rails
.
root
,
"public"
,
"git
host
_error"
),
:layout
=>
false
end
end
end
end
app/controllers/projects_controller.rb
View file @
bdc65809
...
@@ -42,8 +42,8 @@ class ProjectsController < ApplicationController
...
@@ -42,8 +42,8 @@ class ProjectsController < ApplicationController
format
.
js
format
.
js
end
end
end
end
rescue
Gitlabhq
::
Gito
sis
::
AccessDenied
,
Gitlabhq
::
Gito
lite
::
AccessDenied
rescue
Gitlabhq
::
Gitolite
::
AccessDenied
render
:js
=>
"location.href = '
#{
errors_git
osis
_path
}
'"
and
return
render
:js
=>
"location.href = '
#{
errors_git
host
_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"
)
respond_to
do
|
format
|
respond_to
do
|
format
|
...
...
app/models/key.rb
View file @
bdc65809
...
@@ -11,29 +11,29 @@ class Key < ActiveRecord::Base
...
@@ -11,29 +11,29 @@ class Key < ActiveRecord::Base
:length
=>
{
:within
=>
0
..
5000
}
:length
=>
{
:within
=>
0
..
5000
}
before_save
:set_identifier
before_save
:set_identifier
after_save
:update_
gitosis
after_save
:update_
repository
after_destroy
:
gitosis
_delete_key
after_destroy
:
repository
_delete_key
def
set_identifier
def
set_identifier
self
.
identifier
=
"
#{
user
.
identifier
}
_
#{
Time
.
now
.
to_i
}
"
self
.
identifier
=
"
#{
user
.
identifier
}
_
#{
Time
.
now
.
to_i
}
"
end
end
def
update_
gitosis
def
update_
repository
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
update_keys
(
identifier
,
key
)
c
.
update_keys
(
identifier
,
key
)
projects
.
each
do
|
project
|
projects
.
each
do
|
project
|
c
.
update_project
(
project
.
path
,
project
.
gitosis
_writers
)
c
.
update_project
(
project
.
path
,
project
.
repository
_writers
)
end
end
end
end
end
end
def
gitosis
_delete_key
def
repository
_delete_key
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
delete_key
(
identifier
)
c
.
delete_key
(
identifier
)
projects
.
each
do
|
project
|
projects
.
each
do
|
project
|
c
.
update_project
(
project
.
path
,
project
.
gitosis
_writers
)
c
.
update_project
(
project
.
path
,
project
.
repository
_writers
)
end
end
end
end
end
end
...
...
app/models/project.rb
View file @
bdc65809
...
@@ -40,8 +40,8 @@ class Project < ActiveRecord::Base
...
@@ -40,8 +40,8 @@ class Project < ActiveRecord::Base
validate
:check_limit
validate
:check_limit
validate
:repo_name
validate
:repo_name
after_destroy
:destroy_
gitosis_project
after_destroy
:destroy_
repository
after_save
:update_
gitosis_project
after_save
:update_
repository
attr_protected
:private_flag
,
:owner_id
attr_protected
:private_flag
,
:owner_id
...
@@ -54,8 +54,8 @@ class Project < ActiveRecord::Base
...
@@ -54,8 +54,8 @@ class Project < ActiveRecord::Base
delegate
:repo
,
delegate
:repo
,
:url_to_repo
,
:url_to_repo
,
:path_to_repo
,
:path_to_repo
,
:update_
gitosis_project
,
:update_
repository
,
:destroy_
gitosis_project
,
:destroy_
repository
,
:tags
,
:tags
,
:repo_exists?
,
:repo_exists?
,
:commit
,
:commit
,
...
@@ -113,7 +113,7 @@ class Project < ActiveRecord::Base
...
@@ -113,7 +113,7 @@ class Project < ActiveRecord::Base
@writers
||=
users_projects
.
includes
(
:user
).
where
(
:write
=>
true
).
map
(
&
:user
)
@writers
||=
users_projects
.
includes
(
:user
).
where
(
:write
=>
true
).
map
(
&
:user
)
end
end
def
gitosis
_writers
def
repository
_writers
keys
=
Key
.
joins
({
:user
=>
:users_projects
}).
where
(
"users_projects.project_id = ? AND users_projects.write = ?"
,
id
,
true
)
keys
=
Key
.
joins
({
:user
=>
:users_projects
}).
where
(
"users_projects.project_id = ? AND users_projects.write = ?"
,
id
,
true
)
keys
.
map
(
&
:identifier
)
keys
.
map
(
&
:identifier
)
end
end
...
@@ -184,8 +184,8 @@ class Project < ActiveRecord::Base
...
@@ -184,8 +184,8 @@ class Project < ActiveRecord::Base
end
end
def
repo_name
def
repo_name
if
path
==
"gito
sis-admin"
&&
path
==
"gito
lite-admin"
if
path
==
"gitolite-admin"
errors
.
add
(
:path
,
" like 'gito
sis
-admin' is not allowed"
)
errors
.
add
(
:path
,
" like 'gito
lite
-admin' is not allowed"
)
end
end
end
end
...
...
app/models/repository.rb
View file @
bdc65809
...
@@ -24,24 +24,20 @@ class Repository
...
@@ -24,24 +24,20 @@ class Repository
end
end
def
url_to_repo
def
url_to_repo
if
!
GIT_HOST
[
"port"
]
or
GIT_HOST
[
"port"
]
==
22
Gitlabhq
::
GitHost
.
url_to_repo
(
path
)
"
#{
GIT_HOST
[
"git_user"
]
}
@
#{
GIT_HOST
[
"host"
]
}
:
#{
path
}
.git"
else
"ssh://
#{
GIT_HOST
[
"git_user"
]
}
@
#{
GIT_HOST
[
"host"
]
}
:
#{
GIT_HOST
[
"port"
]
}
/
#{
path
}
.git"
end
end
end
def
path_to_repo
def
path_to_repo
GIT_HOST
[
"base_path"
]
+
path
+
".git"
GIT_HOST
[
"base_path"
]
+
path
+
".git"
end
end
def
update_
gitosis_project
def
update_
repository
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
update_project
(
path
,
project
.
gitosis
_writers
)
c
.
update_project
(
path
,
project
.
repository
_writers
)
end
end
end
end
def
destroy_
gitosis_project
def
destroy_
repository
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
Gitlabhq
::
GitHost
.
system
.
new
.
configure
do
|
c
|
c
.
destroy_project
(
@project
)
c
.
destroy_project
(
@project
)
end
end
...
...
app/models/users_project.rb
View file @
bdc65809
...
@@ -4,7 +4,7 @@ class UsersProject < ActiveRecord::Base
...
@@ -4,7 +4,7 @@ class UsersProject < ActiveRecord::Base
attr_protected
:project_id
,
:project
attr_protected
:project_id
,
:project
after_commit
:update_
gitosis_project
after_commit
:update_
repository
validates_uniqueness_of
:user_id
,
:scope
=>
[
:project_id
]
validates_uniqueness_of
:user_id
,
:scope
=>
[
:project_id
]
validates_presence_of
:user_id
validates_presence_of
:user_id
...
@@ -13,9 +13,9 @@ class UsersProject < ActiveRecord::Base
...
@@ -13,9 +13,9 @@ class UsersProject < ActiveRecord::Base
delegate
:name
,
:email
,
:to
=>
:user
,
:prefix
=>
true
delegate
:name
,
:email
,
:to
=>
:user
,
:prefix
=>
true
def
update_
gitosis_project
def
update_
repository
Gitosis
.
new
.
configure
do
|
c
|
Gitosis
.
new
.
configure
do
|
c
|
c
.
update_project
(
project
.
path
,
project
.
gitosis_writers
)
c
.
update_project
(
project
.
path
,
project
.
repository
)
end
end
end
end
...
...
config/routes.rb
View file @
bdc65809
...
@@ -14,7 +14,7 @@ Gitlab::Application.routes.draw do
...
@@ -14,7 +14,7 @@ Gitlab::Application.routes.draw do
root
:to
=>
"users#index"
root
:to
=>
"users#index"
end
end
get
"errors/git
osis
"
get
"errors/git
host
"
get
"profile/password"
,
:to
=>
"profile#password"
get
"profile/password"
,
:to
=>
"profile#password"
put
"profile/password"
,
:to
=>
"profile#password_update"
put
"profile/password"
,
:to
=>
"profile#password_update"
put
"profile/reset_private_token"
,
:to
=>
"profile#reset_private_token"
put
"profile/reset_private_token"
,
:to
=>
"profile#reset_private_token"
...
...
lib/gitlabhq/git_host.rb
View file @
bdc65809
require
File
.
join
(
Rails
.
root
,
"lib"
,
"gitlabhq"
,
"gitolite"
)
require
File
.
join
(
Rails
.
root
,
"lib"
,
"gitlabhq"
,
"gitolite"
)
require
File
.
join
(
Rails
.
root
,
"lib"
,
"gitlabhq"
,
"gitosis"
)
module
Gitlabhq
module
Gitlabhq
class
GitHost
class
GitHost
def
self
.
system
def
self
.
system
if
GIT_HOST
[
"system"
]
==
"gitosis"
Gitlabhq
::
Gitolite
Gitlabhq
::
Gitosis
else
Gitlabhq
::
Gitolite
end
end
end
def
self
.
admin_uri
def
self
.
admin_uri
GIT_HOST
[
"admin_uri"
]
GIT_HOST
[
"admin_uri"
]
end
end
def
self
.
url_to_repo
(
path
)
if
!
GIT_HOST
[
"port"
]
or
GIT_HOST
[
"port"
]
==
22
"
#{
GIT_HOST
[
"git_user"
]
}
@
#{
GIT_HOST
[
"host"
]
}
:
#{
path
}
.git"
else
"ssh://
#{
GIT_HOST
[
"git_user"
]
}
@
#{
GIT_HOST
[
"host"
]
}
:
#{
GIT_HOST
[
"port"
]
}
/
#{
path
}
.git"
end
end
end
end
end
end
lib/gitlabhq/gitosis.rb
deleted
100644 → 0
View file @
8134fe0e
require
'inifile'
require
'timeout'
require
'fileutils'
module
Gitlabhq
class
Gitosis
class
AccessDenied
<
StandardError
;
end
def
pull
# create tmp dir
@local_dir
=
File
.
join
(
Dir
.
tmpdir
,
"gitlabhq-gitosis-
#{
Time
.
now
.
to_i
}
"
)
Dir
.
mkdir
@local_dir
`git clone
#{
GitHost
.
admin_uri
}
#{
@local_dir
}
/gitosis`
end
def
push
Dir
.
chdir
(
File
.
join
(
@local_dir
,
"gitosis"
))
`git add -A`
`git commit -am "Gitlab"`
`git push`
Dir
.
chdir
(
Rails
.
root
)
FileUtils
.
rm_rf
(
@local_dir
)
end
def
configure
status
=
Timeout
::
timeout
(
20
)
do
File
.
open
(
File
.
join
(
Dir
.
tmpdir
,
"gitlabhq-gitosis.lock"
),
"w+"
)
do
|
f
|
begin
f
.
flock
(
File
::
LOCK_EX
)
pull
yield
(
self
)
push
ensure
f
.
flock
(
File
::
LOCK_UN
)
end
end
end
rescue
Exception
=>
ex
raise
Gitosis
::
AccessDenied
.
new
(
"gitosis timeout"
)
end
def
destroy_project
(
project
)
`sudo -u git rm -rf
#{
project
.
path_to_repo
}
`
conf
=
IniFile
.
new
(
File
.
join
(
@local_dir
,
'gitosis'
,
'gitosis.conf'
))
conf
.
delete_section
(
"group
#{
project
.
path
}
"
)
conf
.
write
end
#update or create
def
update_keys
(
user
,
key
)
File
.
open
(
File
.
join
(
@local_dir
,
'gitosis/keydir'
,
"
#{
user
}
.pub"
),
'w'
)
{
|
f
|
f
.
write
(
key
.
gsub
(
/\n/
,
''
))
}
end
def
delete_key
(
user
)
File
.
unlink
(
File
.
join
(
@local_dir
,
'gitosis/keydir'
,
"
#{
user
}
.pub"
))
`cd
#{
File
.
join
(
@local_dir
,
'gitosis'
)
}
; git rm keydir/
#{
user
}
.pub`
end
#update or create
def
update_project
(
repo_name
,
name_writers
)
# write config file
conf
=
IniFile
.
new
(
File
.
join
(
@local_dir
,
'gitosis'
,
'gitosis.conf'
))
conf
[
"group
#{
repo_name
}
"
][
'writable'
]
=
repo_name
conf
[
"group
#{
repo_name
}
"
][
'members'
]
=
name_writers
.
join
(
' '
)
conf
.
write
end
end
end
lib/tasks/gitolite_rebuild.rake
0 → 100644
View file @
bdc65809
desc
"Rebuild each project at gitolite config"
task
:gitolite_rebuild
=>
:environment
do
puts
"Starting..."
Project
.
find_each
(
:batch_size
=>
100
)
do
|
project
|
puts
puts
"===
#{
project
.
name
}
"
project
.
update_repository
puts
end
puts
"Done"
end
spec/models/project_spec.rb
View file @
bdc65809
...
@@ -18,12 +18,12 @@ describe Project do
...
@@ -18,12 +18,12 @@ describe Project do
describe
"Respond to"
do
describe
"Respond to"
do
it
{
should
respond_to
(
:readers
)
}
it
{
should
respond_to
(
:readers
)
}
it
{
should
respond_to
(
:writers
)
}
it
{
should
respond_to
(
:writers
)
}
it
{
should
respond_to
(
:
gitosis
_writers
)
}
it
{
should
respond_to
(
:
repository
_writers
)
}
it
{
should
respond_to
(
:admins
)
}
it
{
should
respond_to
(
:admins
)
}
it
{
should
respond_to
(
:add_access
)
}
it
{
should
respond_to
(
:add_access
)
}
it
{
should
respond_to
(
:reset_access
)
}
it
{
should
respond_to
(
:reset_access
)
}
it
{
should
respond_to
(
:update_
gitosis_project
)
}
it
{
should
respond_to
(
:update_
repository
)
}
it
{
should
respond_to
(
:destroy_
gitosis_project
)
}
it
{
should
respond_to
(
:destroy_
repository
)
}
it
{
should
respond_to
(
:public?
)
}
it
{
should
respond_to
(
:public?
)
}
it
{
should
respond_to
(
:private?
)
}
it
{
should
respond_to
(
:private?
)
}
it
{
should
respond_to
(
:url_to_repo
)
}
it
{
should
respond_to
(
:url_to_repo
)
}
...
@@ -35,9 +35,9 @@ describe Project do
...
@@ -35,9 +35,9 @@ describe Project do
it
{
should
respond_to
(
:commit
)
}
it
{
should
respond_to
(
:commit
)
}
end
end
it
"should not allow 'gito
sis
-admin' as repo name"
do
it
"should not allow 'gito
lite
-admin' as repo name"
do
should
allow_value
(
"blah"
).
for
(
:path
)
should
allow_value
(
"blah"
).
for
(
:path
)
should_not
allow_value
(
"gito
sis
-admin"
).
for
(
:path
)
should_not
allow_value
(
"gito
lite
-admin"
).
for
(
:path
)
end
end
it
"should return valid url to repo"
do
it
"should return valid url to repo"
do
...
...
spec/monkeypatch.rb
View file @
bdc65809
# Stubbing Project <-> git
osis
path
# Stubbing Project <-> git
host
path
# create project using Factory only
# create project using Factory only
class
Project
class
Project
def
update_
gitosis_project
def
update_
repository
true
true
end
end
def
update_
gitosis
def
update_
repository
true
true
end
end
...
@@ -15,17 +15,17 @@ class Project
...
@@ -15,17 +15,17 @@ class Project
end
end
class
Key
class
Key
def
update_
gitosis
def
update_
repository
true
true
end
end
def
gitosis
_delete_key
def
repository
_delete_key
true
true
end
end
end
end
class
UsersProject
class
UsersProject
def
update_
gitosis_project
def
update_
repository
true
true
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