Commit 70bf7f6e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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

Project -> update repo only on create and destroy. Fixtures Updated with namespaces. Fixed moving repo
parent cc52eed9
...@@ -36,7 +36,7 @@ class ProjectsController < ProjectResourceController ...@@ -36,7 +36,7 @@ class ProjectsController < ProjectResourceController
def update def update
namespace_id = params[:project].delete(:namespace_id) 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) namespace = Namespace.find(namespace_id)
project.transfer(namespace) project.transfer(namespace)
end end
......
...@@ -27,6 +27,7 @@ class Namespace < ActiveRecord::Base ...@@ -27,6 +27,7 @@ class Namespace < ActiveRecord::Base
after_create :ensure_dir_exist after_create :ensure_dir_exist
after_update :move_dir after_update :move_dir
after_destroy :rm_dir
scope :root, where('type IS NULL') scope :root, where('type IS NULL')
...@@ -52,4 +53,9 @@ class Namespace < ActiveRecord::Base ...@@ -52,4 +53,9 @@ class Namespace < ActiveRecord::Base
new_path = File.join(Gitlab.config.git_base_path, path) new_path = File.join(Gitlab.config.git_base_path, path)
system("mv #{old_path} #{new_path}") system("mv #{old_path} #{new_path}")
end end
def rm_dir
dir_path = File.join(Gitlab.config.git_base_path, path)
system("rm -rf #{dir_path}")
end
end end
...@@ -254,6 +254,10 @@ class Project < ActiveRecord::Base ...@@ -254,6 +254,10 @@ class Project < ActiveRecord::Base
old_dir = old_namespace.try(:path) || '' old_dir = old_namespace.try(:path) || ''
new_dir = new_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 Gitlab::ProjectMover.new(self, old_dir, new_dir).execute
save! save!
......
class ProjectObserver < ActiveRecord::Observer class ProjectObserver < ActiveRecord::Observer
def after_save(project) def after_create(project)
project.update_repository project.update_repository
end end
def after_save(project)
end
def after_destroy(project) def after_destroy(project)
log_info("Project \"#{project.name}\" was removed") log_info("Project \"#{project.name}\" was removed")
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
%title %title
GitLab GitLab
:css :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;} .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 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;} .content p {color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif;}
...@@ -35,5 +35,5 @@ ...@@ -35,5 +35,5 @@
%p{style: "font-size: 11px; color:#7d7a7a; margin: 0; padding: 0; font-family: Helvetica, Arial, sans-serif;"} %p{style: "font-size: 11px; color:#7d7a7a; margin: 0; padding: 0; font-family: Helvetica, Arial, sans-serif;"}
You're receiving this notification because you are a member of the You're receiving this notification because you are a member of the
- if @project - if @project
#{@project.name} #{@project.name}
project team. project team.
...@@ -13,15 +13,15 @@ ...@@ -13,15 +13,15 @@
%legend Advanced settings: %legend Advanced settings:
.control-group .control-group
= f.label :path do = f.label :path do
Path Repository
.controls .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 .control-group
= f.label :namespace_id do = f.label :namespace_id do
%span Namespace %span Namespace
.controls .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; &nbsp;
%span.cred Be careful. Changing project namespace can have unintended side effects %span.cred Be careful. Changing project namespace can have unintended side effects
......
unless User.count > 0 User.seed(:id, [
admin = User.create( {
email: "admin@local.host", id: 1,
name: "Administrator", name: "Administrator",
email: "admin@local.host",
username: 'root', username: 'root',
password: "5iveL!fe", password: "5iveL!fe",
password_confirmation: "5iveL!fe" password_confirmation: "5iveL!fe",
) admin: true,
}
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
Project.seed(:id, [ 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: 2, name: "Diaspora", path: "diaspora", owner_id: 1 },
{ id: 3, name: "Ruby on Rails", path: "rails", owner_id: 1 } { id: 3, name: "Ruby on Rails", path: "rails", owner_id: 1 }
]) ])
root = Gitlab.config.git_base_path root = Gitlab.config.git_base_path
projects = [ 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: 'diaspora.git', git: 'https://github.com/diaspora/diaspora.git' },
{ path: 'rails.git', git: 'https://github.com/rails/rails.git' }, { path: 'rails.git', git: 'https://github.com/rails/rails.git' },
] ]
...@@ -13,9 +13,10 @@ projects.each do |project| ...@@ -13,9 +13,10 @@ projects.each do |project|
next if File.exists?(project_path) next if File.exists?(project_path)
cmds = [ 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 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| cmds.each do |cmd|
......
...@@ -26,6 +26,13 @@ module Gitlab ...@@ -26,6 +26,13 @@ module Gitlab
config.update_project!(project.path, project) config.update_project!(project.path, project)
end 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 def remove_repository project
config.destroy_project!(project) config.destroy_project!(project)
end end
......
...@@ -83,7 +83,11 @@ module Gitlab ...@@ -83,7 +83,11 @@ module Gitlab
def destroy_project(project) def destroy_project(project)
FileUtils.rm_rf(project.path_to_repo) 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 end
def destroy_project!(project) def destroy_project!(project)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment