diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c05e777 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +repos diff --git a/README.md b/README.md index 60f595e..7c49d82 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,17 @@ Some extra tips: * On Ubuntu, the `www-data` user's $HOME is `/var/www`, and by default it's owned by root. That means you might have to do this before installing Redmine: `sudo mkdir /var/www/.ssh; sudo chown www-data:www-data /var/www/.ssh` +## Configuration + +The plugin offers two configuration options: + +* Local Repository Path (git_local_path) - Path, where repositories are created on the local system. This defaults to `REDMINE_PLUGINS_PATH/redmine_git_remote/repos`. +* Remote Repository Url Prefix - Default Prefix of the Remote Repository. The Default Prefix for Remote Repositories, defaults to an empty value. If this value is set, this prefix is shown in the Clone URL field of a repository by default, but can be overwritten by the user (eg. https://github.com/). + + + +The above configuration can be found at `Administration -> Plugins -> Redmine Git Remote -> Config`. Furthermore for initial values, the file `redmine_git_remote/conf/settings.yml` can be used. + ## Usage This plugin defines a new repository type, GitRemote, which allows you to associate @@ -57,7 +68,7 @@ On submitting the repository creation form, the identifier and `url` For example, if you enter `https://github.com/dergachev/vagrant-vbox-snapshot` as the Clone URL, it will prefill the Identifier and filesystem path fields as follows: * Identifier: `vagrant-vbox-snapshot` -* Path: `REDMINE_PLUGINS_PATH/redmine_git_remote/repos/github.com/dergachev/vagrant-vbox-snapshot` +* Path: `REDMINE_PLUGINS_PATH/redmine_git_remote/repos/github.com/dergachev/vagrant-vbox-snapshot` (Note: The Path can be configured using the above mentioned method, but can also be entered for each repository.) Once the remote URL is validated, the plugin creates an [empty clone](http://stackoverflow.com/questions/895819/whats-the-most-straightforward-way-to-clone-an-empty-bare-git-repository) at the specified path. @@ -83,6 +94,7 @@ cd /home/redmine/redmine && ./script/rails runner "Repository.fetch_changesets" Notes: * Tested on Redmine 2.6 and ruby 2.1 +* Tested on Redmine 3.3.1 * Currently alpha state, use at your own risk. Given possible security risks of shelling out, we recommend using this plugin only if all RedMine project admins are trusted users. * This plugin doesn't clean-up (delete) cloned repos from the file system when the record diff --git a/app/models/repository/git_remote.rb b/app/models/repository/git_remote.rb index f5c0b2d..0fa5441 100644 --- a/app/models/repository/git_remote.rb +++ b/app/models/repository/git_remote.rb @@ -79,7 +79,16 @@ def initialize_clone p = parse(attributes["extra_info"]["extra_clone_url"]) self.identifier = p[:identifier] if identifier.empty? - self.url = PATH_PREFIX + p[:path] if url.empty? + + url_prefix = PATH_PREFIX + unless Setting.plugin_redmine_git_remote["git_local_path_default"].blank? + url_prefix = Setting.plugin_redmine_git_remote["git_local_path_default"] + if !url_prefix.end_with?("/") then + url_prefix = url_prefix + "/" + end + end + + self.url = url_prefix + p[:path] if url.empty? err = ensure_possibly_empty_clone_exists errors.add :extra_clone_url, err if err diff --git a/app/views/settings/_redmine_git_remote.html.erb b/app/views/settings/_redmine_git_remote.html.erb new file mode 100644 index 0000000..c1416a0 --- /dev/null +++ b/app/views/settings/_redmine_git_remote.html.erb @@ -0,0 +1,16 @@ +
+ + + Path, where repositories are created locally. +
++ + + Default Prefix of the Remote Repository. +
diff --git a/config/settings.yml b/config/settings.yml new file mode 100644 index 0000000..819d1af --- /dev/null +++ b/config/settings.yml @@ -0,0 +1,2 @@ +git_local_path: '' +git_remote_url_prefix: '' diff --git a/doc/settings.jpg b/doc/settings.jpg new file mode 100644 index 0000000..892353f Binary files /dev/null and b/doc/settings.jpg differ diff --git a/init.rb b/init.rb index badbe78..c67a91c 100644 --- a/init.rb +++ b/init.rb @@ -8,5 +8,12 @@ author 'Alex Dergachev' url 'https://github.com/dergachev/redmine_git_remote' description 'Automatically clone and fetch remote git repositories' - version '0.0.1' + version '0.0.2' + + PLUGIN_ROOT = Pathname.new(__FILE__).join("..").realpath.to_s + options = YAML::load( File.open(File.join(PLUGIN_ROOT + '/config', 'settings.yml'))) + + settings :default => {'git_local_path_default' => options['git_local_path'], + 'git_remote_url_prefix_default' => options['git_remote_url_prefix']}, + :partial => 'settings/redmine_git_remote' end diff --git a/lib/redmine_git_remote/repositories_helper_patch.rb b/lib/redmine_git_remote/repositories_helper_patch.rb index 508ac53..95b1f1c 100644 --- a/lib/redmine_git_remote/repositories_helper_patch.rb +++ b/lib/redmine_git_remote/repositories_helper_patch.rb @@ -6,15 +6,22 @@ def self.included(base) # :nodoc: module InstanceMethods def git_remote_field_tags(form, repository) - content_tag('p', form.text_field(:url, - :size => 60, :required => false, - :disabled => !repository.safe_attribute?('url'), - :label => l(:field_path_to_repository)) + - content_tag('em', l(:text_git_remote_path_note), :class => 'info') + - form.text_field(:extra_clone_url, :size => 60, :required => true, - :disabled => !repository.safe_attribute?('url')) + - content_tag('em', l(:text_git_remote_url_note), :class => 'info') - ) + local_path_tag = form.text_field(:url, + :size => 60, :required => false, + :disabled => !repository.safe_attribute?('url'), + :label => l(:field_path_to_repository)) + local_path_note = content_tag('em', l(:text_git_remote_path_note), :class => 'info') + + remote_url_prefix = Setting.plugin_redmine_git_remote["git_remote_url_prefix_default"].presence || '' + + remote_url_tag = form.text_field(:extra_clone_url, :size => 60, :required => true, + :value => remote_url_prefix, + :disabled => !repository.safe_attribute?('url')) + remote_url_note = content_tag('em', l(:text_git_remote_url_note), :class => 'info') + + git_remote_tag = content_tag('p', local_path_tag + local_path_note + remote_url_tag + remote_url_note) + + git_remote_tag end end end