Commit 70bf7f6e191c0e99ad03e1eec2ecbe2aae53fa09

Authored by Dmitriy Zaporozhets
1 parent cc52eed9

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

…ces. Fixed moving repo
app/controllers/projects_controller.rb
... ... @@ -36,7 +36,7 @@ class ProjectsController < ProjectResourceController
36 36 def update
37 37 namespace_id = params[:project].delete(:namespace_id)
38 38  
39   - if namespace_id
  39 + if namespace_id.present? and namespace_id.to_i != project.namespace_id
40 40 namespace = Namespace.find(namespace_id)
41 41 project.transfer(namespace)
42 42 end
... ...
app/models/namespace.rb
... ... @@ -27,6 +27,7 @@ class Namespace < ActiveRecord::Base
27 27  
28 28 after_create :ensure_dir_exist
29 29 after_update :move_dir
  30 + after_destroy :rm_dir
30 31  
31 32 scope :root, where('type IS NULL')
32 33  
... ... @@ -52,4 +53,9 @@ class Namespace < ActiveRecord::Base
52 53 new_path = File.join(Gitlab.config.git_base_path, path)
53 54 system("mv #{old_path} #{new_path}")
54 55 end
  56 +
  57 + def rm_dir
  58 + dir_path = File.join(Gitlab.config.git_base_path, path)
  59 + system("rm -rf #{dir_path}")
  60 + end
55 61 end
... ...
app/models/project.rb
... ... @@ -254,6 +254,10 @@ class Project < ActiveRecord::Base
254 254 old_dir = old_namespace.try(:path) || ''
255 255 new_dir = new_namespace.try(:path) || ''
256 256  
  257 + old_repo = File.join(old_dir, self.path)
  258 +
  259 + git_host.move_repository(old_repo, self.path_with_namespace, self)
  260 +
257 261 Gitlab::ProjectMover.new(self, old_dir, new_dir).execute
258 262  
259 263 save!
... ...
app/observers/project_observer.rb
1 1 class ProjectObserver < ActiveRecord::Observer
2   - def after_save(project)
  2 + def after_create(project)
3 3 project.update_repository
4 4 end
5 5  
  6 + def after_save(project)
  7 + end
  8 +
6 9 def after_destroy(project)
7 10 log_info("Project \"#{project.name}\" was removed")
8 11  
... ...
app/views/layouts/notify.html.haml
... ... @@ -4,7 +4,7 @@
4 4 %title
5 5 GitLab
6 6 :css
7   - .header h1 {color: #BBBBBB !important; font: bold 32px Helvetica, Arial, sans-serif; margin: 0; padding: 0; line-height: 40px;}
  7 + .header h1 {color: #BBBBBB !important; font: bold 22px Helvetica, Arial, sans-serif; margin: 0; padding: 0; line-height: 32px;}
8 8 .header p {color: #c6c6c6; font: normal 12px Helvetica, Arial, sans-serif; margin: 0; padding: 0; line-height: 18px;}
9 9 .content h2 {color:#646464 !important; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; }
10 10 .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 35 %p{style: "font-size: 11px; color:#7d7a7a; margin: 0; padding: 0; font-family: Helvetica, Arial, sans-serif;"}
36 36 You're receiving this notification because you are a member of the
37 37 - if @project
38   - #{@project.name}
  38 + #{@project.name}
39 39 project team.
... ...
app/views/projects/_form.html.haml
... ... @@ -13,15 +13,15 @@
13 13 %legend Advanced settings:
14 14 .control-group
15 15 = f.label :path do
16   - Path
  16 + Repository
17 17 .controls
18   - = text_field_tag :ppath, @project.path_to_repo, class: "xlarge", disabled: true
  18 + = text_field_tag :ppath, @project.path_to_repo, class: "xxlarge", readonly: true
19 19  
20 20 .control-group
21 21 = f.label :namespace_id do
22 22 %span Namespace
23 23 .controls
24   - = f.select :namespace_id, namespaces_options(@project.namespace_id), {}, {class: 'chosen'}
  24 + = f.select :namespace_id, namespaces_options(@project.namespace_id), {prompt: 'Choose a project namespace'}, {class: 'chosen'}
25 25 &nbsp;
26 26 %span.cred Be careful. Changing project namespace can have unintended side effects
27 27  
... ...
db/fixtures/development/001_admin.rb
1   -unless User.count > 0
2   - admin = User.create(
3   - email: "admin@local.host",
  1 +User.seed(:id, [
  2 + {
  3 + id: 1,
4 4 name: "Administrator",
  5 + email: "admin@local.host",
5 6 username: 'root',
6 7 password: "5iveL!fe",
7   - password_confirmation: "5iveL!fe"
8   - )
9   -
10   - admin.projects_limit = 10000
11   - admin.admin = true
12   - admin.save!
13   -
14   - if admin.valid?
15   - puts %q[
16   - Administrator account created:
17   -
18   - login.........admin@local.host
19   - password......5iveL!fe
20   - ]
21   - end
22   -end
  8 + password_confirmation: "5iveL!fe",
  9 + admin: true,
  10 + }
  11 +])
... ...
db/fixtures/development/002_project.rb
1 1 Project.seed(:id, [
2   - { id: 1, name: "Underscore.js", path: "underscore", owner_id: 1 },
  2 + { id: 1, name: "Underscore.js", path: "underscore", owner_id: 1, namespace_id: 1 },
3 3 { id: 2, name: "Diaspora", path: "diaspora", owner_id: 1 },
4 4 { id: 3, name: "Ruby on Rails", path: "rails", owner_id: 1 }
5 5 ])
... ...
db/fixtures/development/009_source_code.rb
1 1 root = Gitlab.config.git_base_path
2 2  
3 3 projects = [
4   - { path: 'underscore.git', git: 'https://github.com/documentcloud/underscore.git' },
  4 + { path: 'root/underscore.git', git: 'https://github.com/documentcloud/underscore.git' },
5 5 { path: 'diaspora.git', git: 'https://github.com/diaspora/diaspora.git' },
6 6 { path: 'rails.git', git: 'https://github.com/rails/rails.git' },
7 7 ]
... ... @@ -13,9 +13,10 @@ projects.each do |project|
13 13 next if File.exists?(project_path)
14 14  
15 15 cmds = [
16   - "cd #{root} && sudo -u git -H git clone --bare #{project[:git]}",
  16 + "cd #{root} && sudo -u git -H git clone --bare #{project[:git]} ./#{project[:path]}",
17 17 "sudo cp ./lib/hooks/post-receive #{project_path}/hooks/post-receive",
18   - "sudo chown git:git #{project_path}/hooks/post-receive"
  18 + "sudo chown git:git -R #{project_path}",
  19 + "sudo chmod 770 -R #{project_path}",
19 20 ]
20 21  
21 22 cmds.each do |cmd|
... ...
lib/gitlab/backend/gitolite.rb
... ... @@ -26,6 +26,13 @@ module Gitlab
26 26 config.update_project!(project.path, project)
27 27 end
28 28  
  29 + def move_repository(old_repo, new_repo, project)
  30 + config.apply do |config|
  31 + config.clean_repo(old_repo)
  32 + config.update_project(new_repo, project)
  33 + end
  34 + end
  35 +
29 36 def remove_repository project
30 37 config.destroy_project!(project)
31 38 end
... ...
lib/gitlab/backend/gitolite_config.rb
... ... @@ -83,7 +83,11 @@ module Gitlab
83 83  
84 84 def destroy_project(project)
85 85 FileUtils.rm_rf(project.path_to_repo)
86   - conf.rm_repo(project.path)
  86 + conf.rm_repo(project.path_with_namespace)
  87 + end
  88 +
  89 + def clean_repo repo_name
  90 + conf.rm_repo(repo_name)
87 91 end
88 92  
89 93 def destroy_project!(project)
... ...