Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom gitolite config file #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions app/views/settings/_redmine_git_hosting.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
<%= text_field_tag("settings[gitoliteIdentityPublicKeyFile]", @settings['gitoliteIdentityPublicKeyFile'], :size => 60) %>
<br />
</p>
<p>
<label><%= l(:label_gitolite_generated_config_filename)%></label>
<%= text_field_tag("settings[gitoliteGeneratedConfigFilename]", @settings['gitoliteGeneratedConfigFilename'], :size => 60) %>
<br />
</p>
<p>
<label><%= l(:label_gitolite_admin_user)%></label>
<%= text_field_tag("settings[gitoliteAdminUser]", @settings['gitoliteAdminUser'], :size => 60) %>
<br />
</p>
<p>
<label><%= l(:label_git_repository_base_path)%></label>
<%= text_field_tag("settings[gitRepositoryBasePath]", @settings['gitRepositoryBasePath'], :size => 60) %>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 7 additions & 6 deletions lib/git_hosting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,20 @@ 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
GitAdapterHooks.check_hooks_installed
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")

Expand All @@ -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

Expand All @@ -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' ]
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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' ]
Expand Down
18 changes: 16 additions & 2 deletions lib/gitolite_conf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down