diff --git a/README.mkd b/README.mkd
index 945b9cf82..21cd4c937 100755
--- a/README.mkd
+++ b/README.mkd
@@ -96,7 +96,7 @@ root directory:
**(6)** It is best to set several plugin variables BEFORE you run the db:migrate\_plugins task in step 7. In particular it is important
-that the *httpServer*, *gitServer*, *gitUser*, *gitRepositoryBasePath*, *gitoliteIdentityFile* and *gitoliteIdentityPublicKeyFile*
+that the *httpServer*, *gitServer*, *gitUser*, *gitRepositoryBasePath*, *gitoliteIdentityFile*, *gitoliteIdentityPublicKeyFile* and *gitoliteGeneratedConfigFilename*
variables are set correctly. To adjust these variables, open an editor and edit [redmine_rails_root]/vendor/plugins/redmine_git_hosting/init.rb file.
Starting on line 22 you will see the settings definitions you should edit.
@@ -120,6 +120,9 @@ Since gitolite always uses repositories/ as the default place for repositories y
If you followed the above directions you will not need to modify the *gitoliteIdentityFile* or *gitoliteIdentityPublicKeyFile* variables -- these specify
the path to the private/public key files for accessing the gitolite admin repository.
+Each time the plug-in need to update the gitolite configuration, it will replace all the content of the gitolite.conf file.
+So if you have a pre-existing gitolite configuration, you might want to change the *gitoliteGeneratedConfigFilename* to an other file name and include it in your original gitolite.conf.
+
These variables can be modified at a later time in the Administration => Plugins => Redmine Git Hosting Plugin configuration page. However to ensure
that the database migration from your existing repositories goes smoothly it is best to modify these variables now.
diff --git a/app/views/settings/_redmine_git_hosting.html.erb b/app/views/settings/_redmine_git_hosting.html.erb
index c6b1e7760..8990d7d64 100644
--- a/app/views/settings/_redmine_git_hosting.html.erb
+++ b/app/views/settings/_redmine_git_hosting.html.erb
@@ -42,6 +42,16 @@
<%= text_field_tag("settings[gitoliteIdentityPublicKeyFile]", @settings['gitoliteIdentityPublicKeyFile'], :size => 60) %>
+
+ <%= text_field_tag("settings[gitoliteGeneratedConfigFilename]", @settings['gitoliteGeneratedConfigFilename'], :size => 60) %>
+
+
+
+ <%= text_field_tag("settings[gitoliteAdminUser]", @settings['gitoliteAdminUser'], :size => 60) %>
+
+
<%= text_field_tag("settings[gitRepositoryBasePath]", @settings['gitRepositoryBasePath'], :size => 60) %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 2ce8a4693..ead3d8e4b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -6,6 +6,8 @@ label_git_user: Git Username label_gitolite_identity_public_key_file: Gitolite SSH Identity File (Public Key) label_gitolite_identity_file: Gitolite SSH Identity File (Private Key) + label_gitolite_admin_user: Gitolite user id (for gitolite-admin repo) + label_gitolite_generated_config_filename: Generated Gitolite Config Filename label_git_repository_base_path: Git Repository Base Path (Relative to git user home) field_git_daemon: Git Daemon diff --git a/init.rb b/init.rb index 5567c40f2..89bb3c45b 100755 --- a/init.rb +++ b/init.rb @@ -19,6 +19,8 @@ 'gitRepositoryBasePath' => 'repositories/', 'gitoliteIdentityFile' => RAILS_ROOT + '/.ssh/gitolite_admin_id_rsa', 'gitoliteIdentityPublicKeyFile' => RAILS_ROOT + '/.ssh/gitolite_admin_id_rsa.pub', + 'gitoliteAdminUser' => 'gitoliteadm', + 'gitoliteGeneratedConfigFilename' => 'gitolite.conf', 'allProjectsUseGit' => 'false', 'deleteGitRepositories' => 'false', 'gitRepositoriesShowUrl' => 'true', diff --git a/lib/git_hosting.rb b/lib/git_hosting.rb index 8bcea3432..bdd17b31d 100755 --- a/lib/git_hosting.rb +++ b/lib/git_hosting.rb @@ -291,12 +291,12 @@ def self.clone_or_pull_gitolite_admin # clone/pull from admin repo local_dir = get_tmp_dir() if File.exists? "#{local_dir}/gitolite-admin" - logger.info "Fethcing changes for #{local_dir}/gitolite-admin" + logger.info "Fetching changes for #{local_dir}/gitolite-admin" %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' fetch] %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' merge FETCH_HEAD] else logger.info "Cloning gitolite-admin repository" - %x[env GIT_SSH=#{gitolite_ssh()} git clone #{git_user}@#{Setting.plugin_redmine_git_hosting['gitServer']}:gitolite-admin.git #{local_dir}/gitolite-admin] + %x[env GIT_SSH=#{gitolite_ssh()} git clone #{git_user}@#{Setting.plugin_redmine_git_hosting['gitServer']}:gitolite-admin.git #{local_dir}/gitolite-admin 2>&1] end %x[chmod 700 "#{local_dir}/gitolite-admin" ] # Make sure we have our hooks setup @@ -304,6 +304,7 @@ def self.clone_or_pull_gitolite_admin end def self.move_repository(old_name, new_name) + logger.info "move_repository '#{old_name}' -> '#{new_name}'" old_path = File.join(Setting.plugin_redmine_git_hosting['gitRepositoryBasePath'], "#{old_name}.git") new_path = File.join(Setting.plugin_redmine_git_hosting['gitRepositoryBasePath'], "#{new_name}.git") @@ -320,7 +321,7 @@ def self.move_repository(old_name, new_name) clone_or_pull_gitolite_admin # rename in conf file - conf = GitoliteConfig.new(File.join(local_dir, 'gitolite-admin', 'conf', 'gitolite.conf')) + conf = GitoliteConfig.new(File.join(local_dir, 'gitolite-admin', 'conf', Setting.plugin_redmine_git_hosting['gitoliteGeneratedConfigFilename'])) conf.rename_repo( old_name, new_name ) conf.save @@ -332,7 +333,7 @@ def self.move_repository(old_name, new_name) # commit / push changes to gitolite admin repo %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' add keydir/*] - %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' add conf/gitolite.conf] + %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' add conf/#{Setting.plugin_redmine_git_hosting['gitoliteGeneratedConfigFilename']}] %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' config user.email '#{Setting.mail_from}'] %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' config user.name 'Redmine'] %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' commit -a -m 'updated by Redmine' ] @@ -376,7 +377,7 @@ def self.update_repositories(projects, is_repo_delete) local_dir = get_tmp_dir() - conf = GitoliteConfig.new(File.join(local_dir, 'gitolite-admin', 'conf', 'gitolite.conf')) + conf = GitoliteConfig.new(File.join(local_dir, 'gitolite-admin', 'conf', Setting.plugin_redmine_git_hosting['gitoliteGeneratedConfigFilename'])) orig_repos = conf.all_repos new_repos = [] new_projects = [] @@ -454,7 +455,7 @@ def self.update_repositories(projects, is_repo_delete) if changed %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' add keydir/*] - %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' add conf/gitolite.conf] + %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' add conf/#{Setting.plugin_redmine_git_hosting['gitoliteGeneratedConfigFilename']}] %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' config user.email '#{Setting.mail_from}'] %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' config user.name 'Redmine'] %x[env GIT_SSH=#{gitolite_ssh()} git --git-dir='#{local_dir}/gitolite-admin/.git' --work-tree='#{local_dir}/gitolite-admin' commit -a -m 'updated by Redmine' ] diff --git a/lib/gitolite_conf.rb b/lib/gitolite_conf.rb index 1a57a3e88..8612461d3 100755 --- a/lib/gitolite_conf.rb +++ b/lib/gitolite_conf.rb @@ -54,8 +54,14 @@ def all_repos private def load - @original_content = [] + GitHosting.logger.info "Loading from #{@path}" @repositories = ActiveSupport::OrderedHash.new + if !File.readable?(@path) + @original_content = "" + return + end + + @original_content = [] cur_repo_name = nil File.open(@path).each_line do |line| @original_content << line @@ -88,7 +94,15 @@ def content # any permission anyway, this isn't really a security risk. # If no users are defined, this ensures the repo actually # gets created, hence it's necessary. - admin_user = @repositories["gitolite-admin"].rights["RW+".to_sym][0] + admin_user = Setting.plugin_redmine_git_hosting['gitoliteAdminUser'] + + if @repository != nil + admin_repo = @repository["gitolite-admin"]; + if admin_repo != nil + admin_user = admin_repo.rights["RW+".to_sym][0] + end + end + @repositories.each do |repo, rights| content << "repo\t#{repo}" has_users=false