Permalink
Browse files

update config after upon repository deletion when permenant deletion …

…flag is set, so repository gets removed in gitolite configs, and therefore isn't recreated
  • Loading branch information...
ericpaulbishop committed Apr 30, 2011
1 parent 4230a7f commit 3052a7c2a3bf32b55a7fe6f5f96feb858e5900b5
@@ -28,11 +28,13 @@ def after_create(object)
def after_save(object) ; update_repositories(object) ; end
def after_destroy(object)
- update_repositories(object)
if object.is_a?(Repository::Git)
+ GitHosting::update_repositories(object.project, true)
if Setting.plugin_redmine_git_hosting['deleteGitRepositories'] == "true"
%x[#{GitHosting::git_user_runner} 'rm -rf #{object.url}' ]
end
+ else
+ update_repositories(object)
end
end
@@ -41,11 +43,11 @@ def after_destroy(object)
def update_repositories(object)
case object
- when Repository::Git then GitHosting::update_repositories(object.project)
- when User then GitHosting::update_repositories(object.projects) unless is_login_save?(object)
- when GitolitePublicKey then GitHosting::update_repositories(object.user.projects)
- when Member then GitHosting::update_repositories(object.project)
- when Role then GitHosting::update_repositories(object.members.map(&:project).uniq.compact)
+ when Repository::Git then GitHosting::update_repositories(object.project, false)
+ when User then GitHosting::update_repositories(object.projects, false) unless is_login_save?(object)
+ when GitolitePublicKey then GitHosting::update_repositories(object.user.projects, false)
+ when Member then GitHosting::update_repositories(object.project, false)
+ when Role then GitHosting::update_repositories(object.members.map(&:project).uniq.compact, false)
end
end
View
@@ -103,7 +103,7 @@ def self.update_git_exec
end
- def self.update_repositories(projects)
+ def self.update_repositories(projects, is_repo_delete)
projects = (projects.is_a?(Array) ? projects : [projects])
if(defined?(@recursionCheck))
@@ -153,55 +153,66 @@ def self.update_repositories(projects)
projects.select{|p| p.repository.is_a?(Repository::Git)}.each do |project|
- #check whether we're adding a new repo
repo_name = repository_name(project)
- if orig_repos[ repo_name ] == nil
- changed = true
- add_route_for_project(project)
- new_repos.push repo_name
- end
-
- # fetch users
- users = project.member_principals.map(&:user).compact.uniq
- write_users = users.select{ |user| user.allowed_to?( :commit_access, project ) }
- read_users = users.select{ |user| user.allowed_to?( :view_changesets, project ) && !user.allowed_to?( :commit_access, project ) }
- # write key files
- users.map{|u| u.gitolite_public_keys.active}.flatten.compact.uniq.each do |key|
- filename = File.join(local_dir, 'gitolite/keydir',"#{key.identifier}.pub")
- unless File.exists? filename
- File.open(filename, 'w') {|f| f.write(key.key.gsub(/\n/,'')) }
+ #check for delete -- if delete we can just
+ #delete repo, and ignore updating users/public keys
+ if is_repo_delete
+ if Setting.plugin_redmine_git_hosting['deleteGitRepositories'] == "true"
+ conf.delete_repo(repo_name)
+ end
+ else
+ #check whether we're adding a new repo
+ if orig_repos[ repo_name ] == nil
changed = true
+ add_route_for_project(project)
+ new_repos.push repo_name
end
- end
- # delete inactives
- users.map{|u| u.gitolite_public_keys.inactive}.flatten.compact.uniq.each do |key|
- filename = File.join(local_dir, 'gitolite/keydir',"#{key.identifier}.pub")
- if File.exists? filename
- File.unlink(filename) rescue nil
- changed = true
+
+ # fetch users
+ users = project.member_principals.map(&:user).compact.uniq
+ write_users = users.select{ |user| user.allowed_to?( :commit_access, project ) }
+ read_users = users.select{ |user| user.allowed_to?( :view_changesets, project ) && !user.allowed_to?( :commit_access, project ) }
+
+ # write key files
+ users.map{|u| u.gitolite_public_keys.active}.flatten.compact.uniq.each do |key|
+ filename = File.join(local_dir, 'gitolite/keydir',"#{key.identifier}.pub")
+ unless File.exists? filename
+ File.open(filename, 'w') {|f| f.write(key.key.gsub(/\n/,'')) }
+ changed = true
+ end
end
- end
- # update users
- read_user_keys = []
- write_user_keys = []
- read_users.map{|u| u.gitolite_public_keys.active}.flatten.compact.uniq.each do |key|
- read_user_keys.push key.identifier
- end
- write_users.map{|u| u.gitolite_public_keys.active}.flatten.compact.uniq.each do |key|
- write_user_keys.push key.identifier
- end
+
+ # delete inactives
+ users.map{|u| u.gitolite_public_keys.inactive}.flatten.compact.uniq.each do |key|
+ filename = File.join(local_dir, 'gitolite/keydir',"#{key.identifier}.pub")
+ if File.exists? filename
+ File.unlink(filename) rescue nil
+ changed = true
+ end
+ end
- #git daemon
- if (project.repository.git_daemon == 1 || project.repository.git_daemon == nil ) && project.is_public
- read_user_keys.push "daemon"
- end
+ # update users
+ read_user_keys = []
+ write_user_keys = []
+ read_users.map{|u| u.gitolite_public_keys.active}.flatten.compact.uniq.each do |key|
+ read_user_keys.push key.identifier
+ end
+ write_users.map{|u| u.gitolite_public_keys.active}.flatten.compact.uniq.each do |key|
+ write_user_keys.push key.identifier
+ end
+
+ #git daemon
+ if (project.repository.git_daemon == 1 || project.repository.git_daemon == nil ) && project.is_public
+ read_user_keys.push "daemon"
+ end
- conf.set_read_user repo_name, read_user_keys
- conf.set_write_user repo_name, write_user_keys
+ conf.set_read_user repo_name, read_user_keys
+ conf.set_write_user repo_name, write_user_keys
+ end
end
if conf.changed?
@@ -18,8 +18,6 @@ def edit_with_scm_settings
end
edit_without_scm_settings
-
- GitHosting::update_repositories(@project)
end
def self.included(base)
View
@@ -28,6 +28,10 @@ def set_read_user repo_name, users
repository(repo_name).set "R", users
end
+ def delete_repo repo_name
+ @repositories.delete(repo_name)
+ end
+
def changed?
@original_content != content
end
View
@@ -1,13 +1,13 @@
namespace :gitolite do
- desc "update gitolite repositories"
- task :update_repositories => [:environment] do
- projects = Project.active
- puts "Updating repositories for projects #{projects.join(' ')}"
- GitHosting.update_repositories(projects)
- end
- desc "fetch commits from gitolite repositories"
- task :fetch_changes => [:environment] do
- Repository.fetch_changesets
- end
+ desc "update gitolite repositories"
+ task :update_repositories => [:environment] do
+ projects = Project.active
+ puts "Updating repositories for projects #{projects.join(' ')}"
+ GitHosting.update_repositories(projects, false)
+ end
+ desc "fetch commits from gitolite repositories"
+ task :fetch_changes => [:environment] do
+ Repository.fetch_changesets
+ end
-end
+end

0 comments on commit 3052a7c

Please sign in to comment.