Project -> update repo only on create and destroy. Fixtures Updated with namespaces. Fixed moving repo

This commit is contained in:
Dmitriy Zaporozhets 2012-11-21 08:54:05 +03:00
parent cc52eed981
commit 70bf7f6e19
11 changed files with 45 additions and 31 deletions

View file

@ -36,7 +36,7 @@ class ProjectsController < ProjectResourceController
def update
namespace_id = params[:project].delete(:namespace_id)
if namespace_id
if namespace_id.present? and namespace_id.to_i != project.namespace_id
namespace = Namespace.find(namespace_id)
project.transfer(namespace)
end

View file

@ -27,6 +27,7 @@ class Namespace < ActiveRecord::Base
after_create :ensure_dir_exist
after_update :move_dir
after_destroy :rm_dir
scope :root, where('type IS NULL')
@ -52,4 +53,9 @@ class Namespace < ActiveRecord::Base
new_path = File.join(Gitlab.config.git_base_path, path)
system("mv #{old_path} #{new_path}")
end
def rm_dir
dir_path = File.join(Gitlab.config.git_base_path, path)
system("rm -rf #{dir_path}")
end
end

View file

@ -254,6 +254,10 @@ class Project < ActiveRecord::Base
old_dir = old_namespace.try(:path) || ''
new_dir = new_namespace.try(:path) || ''
old_repo = File.join(old_dir, self.path)
git_host.move_repository(old_repo, self.path_with_namespace, self)
Gitlab::ProjectMover.new(self, old_dir, new_dir).execute
save!

View file

@ -1,8 +1,11 @@
class ProjectObserver < ActiveRecord::Observer
def after_save(project)
def after_create(project)
project.update_repository
end
def after_save(project)
end
def after_destroy(project)
log_info("Project \"#{project.name}\" was removed")

View file

@ -4,7 +4,7 @@
%title
GitLab
:css
.header h1 {color: #BBBBBB !important; font: bold 32px Helvetica, Arial, sans-serif; margin: 0; padding: 0; line-height: 40px;}
.header h1 {color: #BBBBBB !important; font: bold 22px Helvetica, Arial, sans-serif; margin: 0; padding: 0; line-height: 32px;}
.header p {color: #c6c6c6; font: normal 12px Helvetica, Arial, sans-serif; margin: 0; padding: 0; line-height: 18px;}
.content h2 {color:#646464 !important; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; }
.content p {color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif;}

View file

@ -13,15 +13,15 @@
%legend Advanced settings:
.control-group
= f.label :path do
Path
Repository
.controls
= text_field_tag :ppath, @project.path_to_repo, class: "xlarge", disabled: true
= text_field_tag :ppath, @project.path_to_repo, class: "xxlarge", readonly: true
.control-group
= f.label :namespace_id do
%span Namespace
.controls
= f.select :namespace_id, namespaces_options(@project.namespace_id), {}, {class: 'chosen'}
= f.select :namespace_id, namespaces_options(@project.namespace_id), {prompt: 'Choose a project namespace'}, {class: 'chosen'}
&nbsp;
%span.cred Be careful. Changing project namespace can have unintended side effects

View file

@ -1,22 +1,11 @@
unless User.count > 0
admin = User.create(
email: "admin@local.host",
User.seed(:id, [
{
id: 1,
name: "Administrator",
email: "admin@local.host",
username: 'root',
password: "5iveL!fe",
password_confirmation: "5iveL!fe"
)
admin.projects_limit = 10000
admin.admin = true
admin.save!
if admin.valid?
puts %q[
Administrator account created:
login.........admin@local.host
password......5iveL!fe
]
end
end
password_confirmation: "5iveL!fe",
admin: true,
}
])

View file

@ -1,5 +1,5 @@
Project.seed(:id, [
{ id: 1, name: "Underscore.js", path: "underscore", owner_id: 1 },
{ id: 1, name: "Underscore.js", path: "underscore", owner_id: 1, namespace_id: 1 },
{ id: 2, name: "Diaspora", path: "diaspora", owner_id: 1 },
{ id: 3, name: "Ruby on Rails", path: "rails", owner_id: 1 }
])

View file

@ -1,7 +1,7 @@
root = Gitlab.config.git_base_path
projects = [
{ path: 'underscore.git', git: 'https://github.com/documentcloud/underscore.git' },
{ path: 'root/underscore.git', git: 'https://github.com/documentcloud/underscore.git' },
{ path: 'diaspora.git', git: 'https://github.com/diaspora/diaspora.git' },
{ path: 'rails.git', git: 'https://github.com/rails/rails.git' },
]
@ -13,9 +13,10 @@ projects.each do |project|
next if File.exists?(project_path)
cmds = [
"cd #{root} && sudo -u git -H git clone --bare #{project[:git]}",
"cd #{root} && sudo -u git -H git clone --bare #{project[:git]} ./#{project[:path]}",
"sudo cp ./lib/hooks/post-receive #{project_path}/hooks/post-receive",
"sudo chown git:git #{project_path}/hooks/post-receive"
"sudo chown git:git -R #{project_path}",
"sudo chmod 770 -R #{project_path}",
]
cmds.each do |cmd|

View file

@ -26,6 +26,13 @@ module Gitlab
config.update_project!(project.path, project)
end
def move_repository(old_repo, new_repo, project)
config.apply do |config|
config.clean_repo(old_repo)
config.update_project(new_repo, project)
end
end
def remove_repository project
config.destroy_project!(project)
end

View file

@ -83,7 +83,11 @@ module Gitlab
def destroy_project(project)
FileUtils.rm_rf(project.path_to_repo)
conf.rm_repo(project.path)
conf.rm_repo(project.path_with_namespace)
end
def clean_repo repo_name
conf.rm_repo(repo_name)
end
def destroy_project!(project)