To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / plugins / redmine_checkout / lib / checkout / repository_patch.rb @ 1318:9c2a5a4514a8
History | View | Annotate | Download (4.66 KB)
| 1 |
require_dependency 'repository'
|
|---|---|
| 2 |
require_dependency 'checkout_helper'
|
| 3 |
|
| 4 |
module Checkout |
| 5 |
module RepositoryPatch |
| 6 |
def self.included(base) # :nodoc: |
| 7 |
base.extend(ClassMethods)
|
| 8 |
base.send(:include, InstanceMethods) |
| 9 |
|
| 10 |
base.class_eval do
|
| 11 |
unloadable |
| 12 |
serialize :checkout_settings, Hash |
| 13 |
end
|
| 14 |
end
|
| 15 |
|
| 16 |
module ClassMethods |
| 17 |
def allow_subtree_checkout? |
| 18 |
# default implementation
|
| 19 |
false
|
| 20 |
end
|
| 21 |
|
| 22 |
def checkout_default_command |
| 23 |
# default implementation
|
| 24 |
""
|
| 25 |
end
|
| 26 |
end
|
| 27 |
|
| 28 |
module InstanceMethods |
| 29 |
def after_initialize |
| 30 |
self.checkout_settings ||= {}
|
| 31 |
end
|
| 32 |
|
| 33 |
def checkout_overwrite=(value) |
| 34 |
checkout_settings['checkout_overwrite'] = value
|
| 35 |
end
|
| 36 |
|
| 37 |
def checkout_overwrite |
| 38 |
(checkout_settings['checkout_overwrite'].to_i > 0) ? '1' : '0' |
| 39 |
end
|
| 40 |
|
| 41 |
def checkout_overwrite? |
| 42 |
self.scm_name != 'Abstract' && checkout_overwrite.to_i > 0 |
| 43 |
end
|
| 44 |
|
| 45 |
def checkout_description=(value) |
| 46 |
checkout_settings['checkout_description'] = value
|
| 47 |
end
|
| 48 |
|
| 49 |
def checkout_description |
| 50 |
if checkout_overwrite?
|
| 51 |
checkout_settings['checkout_description']
|
| 52 |
else
|
| 53 |
if CheckoutHelper.supported_scm.include?(scm_name) && Setting.send("checkout_overwrite_description_#{scm_name}?") |
| 54 |
Setting.send("checkout_description_#{scm_name}") |
| 55 |
else
|
| 56 |
Setting.send("checkout_description_Abstract") |
| 57 |
end
|
| 58 |
end
|
| 59 |
end
|
| 60 |
|
| 61 |
def checkout_protocols |
| 62 |
@checkout_protocols ||= begin |
| 63 |
if CheckoutHelper.supported_scm.include? scm_name |
| 64 |
if checkout_overwrite?
|
| 65 |
protocols = checkout_settings['checkout_protocols'] || []
|
| 66 |
else
|
| 67 |
protocols = Setting.send("checkout_protocols_#{scm_name}") || [] |
| 68 |
end
|
| 69 |
else
|
| 70 |
protocols = [] |
| 71 |
end
|
| 72 |
|
| 73 |
protocols.collect do |p|
|
| 74 |
Checkout::Protocol.new p.merge({:repository => self}) |
| 75 |
end
|
| 76 |
end
|
| 77 |
end
|
| 78 |
|
| 79 |
def checkout_protocols=(value) |
| 80 |
# value is an Array or a Hash
|
| 81 |
if value.is_a? Hash |
| 82 |
value = value.dup.delete_if {|id, protocol| id.to_i < 0 }
|
| 83 |
value = value.sort{|(ak,av),(bk,bv)|ak<=>bk}.collect{|id,protocol| protocol}
|
| 84 |
end
|
| 85 |
|
| 86 |
checkout_settings['checkout_protocols'] = value
|
| 87 |
end
|
| 88 |
|
| 89 |
def checkout_display_login |
| 90 |
if checkout_overwrite? && self.scm_name == "Subversion" |
| 91 |
result = checkout_settings['checkout_display_login']
|
| 92 |
else
|
| 93 |
result = Setting.checkout_display_login
|
| 94 |
end
|
| 95 |
(result.to_i > 0) ? '1' : '0' |
| 96 |
end
|
| 97 |
|
| 98 |
def checkout_display_login? |
| 99 |
checkout_display_login.to_i > 0
|
| 100 |
end
|
| 101 |
|
| 102 |
def checkout_display_login=(value) |
| 103 |
value = nil unless self.scm_name == "Subversion" |
| 104 |
checkout_settings['checkout_display_login'] = value
|
| 105 |
end
|
| 106 |
|
| 107 |
def checkout_display_command? |
| 108 |
checkout_display_command.to_i > 0
|
| 109 |
end
|
| 110 |
|
| 111 |
def checkout_display_command=(value) |
| 112 |
checkout_settings['checkout_display_command'] = value
|
| 113 |
end
|
| 114 |
|
| 115 |
def checkout_display_command |
| 116 |
if checkout_overwrite?
|
| 117 |
checkout_settings['checkout_display_command']
|
| 118 |
else
|
| 119 |
Setting.send("checkout_display_command_#{scm_name}") |
| 120 |
end
|
| 121 |
end
|
| 122 |
|
| 123 |
def allow_subtree_checkout? |
| 124 |
self.class.allow_subtree_checkout?
|
| 125 |
end
|
| 126 |
|
| 127 |
def checkout_default_command |
| 128 |
self.class.checkout_default_command
|
| 129 |
end
|
| 130 |
end
|
| 131 |
end
|
| 132 |
end
|
| 133 |
|
| 134 |
Repository.send(:include, Checkout::RepositoryPatch) |
| 135 |
|
| 136 |
subtree_checkout_repos = ["Subversion", "Cvs"] |
| 137 |
commands = {
|
| 138 |
'Bazaar' => 'bzr checkout', |
| 139 |
'Cvs' => 'cvs checkout', |
| 140 |
'Darcs' => 'darcs get', |
| 141 |
'Git' => 'git clone', |
| 142 |
'Mercurial' => 'hg clone', |
| 143 |
'Subversion' => 'svn checkout' |
| 144 |
} |
| 145 |
|
| 146 |
CheckoutHelper.supported_scm.each do |scm| |
| 147 |
require_dependency "repository/#{scm.underscore}"
|
| 148 |
cls = Repository.const_get(scm)
|
| 149 |
|
| 150 |
allow_subtree_checkout = ""
|
| 151 |
if subtree_checkout_repos.include? scm
|
| 152 |
allow_subtree_checkout = <<-EOS |
| 153 |
def allow_subtree_checkout?
|
| 154 |
true
|
| 155 |
end
|
| 156 |
EOS
|
| 157 |
end
|
| 158 |
|
| 159 |
checkout_command = ""
|
| 160 |
if commands[scm]
|
| 161 |
checkout_command = <<-EOS |
| 162 |
def checkout_default_command
|
| 163 |
'#{commands[scm]}'
|
| 164 |
end
|
| 165 |
EOS
|
| 166 |
end
|
| 167 |
|
| 168 |
class_mod = Module.new
|
| 169 |
class_mod.module_eval(<<-EOF |
| 170 |
def self.included(base)
|
| 171 |
base.extend ChildClassMethods
|
| 172 |
|
| 173 |
base.class_eval do
|
| 174 |
unloadable
|
| 175 |
serialize :checkout_settings, Hash
|
| 176 |
end
|
| 177 |
end
|
| 178 |
|
| 179 |
module ChildClassMethods
|
| 180 |
#{allow_subtree_checkout}
|
| 181 |
#{checkout_command}
|
| 182 |
end
|
| 183 |
EOF
|
| 184 |
) |
| 185 |
cls.send(:include, class_mod)
|
| 186 |
end
|