Skip to content

Commit 7f5a814

Browse files
committed
Patches to aid initial migration, suggested by Greg Thornton
1 parent d5c9df4 commit 7f5a814

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

Diff for: app/models/git_hosting_settings_observer.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class GitHostingSettingsObserver < ActiveRecord::Observer
22
observe :setting
33

4-
@@old_valuehash = (Setting.plugin_redmine_git_hosting).clone
4+
@@old_valuehash = ((Setting.plugin_redmine_git_hosting).clone rescue {})
55

66
def reload_this_observer
77
observed_classes.each do |klass|
@@ -31,14 +31,14 @@ def before_save(object)
3131

3232
# Script directory either absolute or relative to redmine root
3333
stripped = valuehash['gitScriptDir'].lstrip.rstrip
34-
normalizedFile = File.expand_path(stripped,"/") # Get rid of extra path components
34+
normalizedFile = File.expand_path(stripped,"/") # Get rid of extra path components
3535
if (normalizedFile == "/")
3636
# Assume that we are relative bin directory ("/" and "" => "")
3737
valuehash['gitScriptDir'] = ""
3838
elsif (stripped[0,1] != "/")
39-
valuehash['gitScriptDir'] = normalizedFile[1..-1] + "/" # Clobber leading '/' add trailing '/'
39+
valuehash['gitScriptDir'] = normalizedFile[1..-1] + "/" # Clobber leading '/' add trailing '/'
4040
else
41-
valuehash['gitScriptDir'] = normalizedFile + "/" # Add trailing '/'
41+
valuehash['gitScriptDir'] = normalizedFile + "/" # Add trailing '/'
4242
end
4343
elsif valuehash['gitUser'] != @@old_valuehash['gitUser'] ||
4444
valuehash['gitoliteIdentityFile'] != @@old_valuehash['gitoliteIdentityFile'] ||
@@ -53,12 +53,12 @@ def before_save(object)
5353
%x[ rm -rf '#{ GitHosting.get_tmp_dir }' ]
5454

5555
stripped = valuehash['gitTempDataDir'].lstrip.rstrip
56-
normalizedFile = File.expand_path(stripped,"/") # Get rid of extra path components
56+
normalizedFile = File.expand_path(stripped,"/") # Get rid of extra path components
5757
if (normalizedFile == "/" || stripped[0,1] != "/")
5858
# Don't allow either root-level (absolute) or relative
5959
valuehash['gitTempDataDir'] = "/tmp/redmine_git_hosting/"
6060
else
61-
valuehash['gitTempDataDir'] = normalizedFile + "/" # Add trailing '/'
61+
valuehash['gitTempDataDir'] = normalizedFile + "/" # Add trailing '/'
6262
end
6363
end
6464

@@ -86,7 +86,7 @@ def before_save(object)
8686
if valuehash['httpServerSubdir']
8787
normalizedFile = File.expand_path(valuehash['httpServerSubdir'].lstrip.rstrip,"/")
8888
if (normalizedFile != "/")
89-
valuehash['httpServerSubdir'] = normalizedFile[1..-1] + "/" # Clobber leading '/' add trailing '/'
89+
valuehash['httpServerSubdir'] = normalizedFile[1..-1] + "/" # Clobber leading '/' add trailing '/'
9090
else
9191
valuehash['httpServerSubdir'] = ''
9292
end
@@ -122,7 +122,7 @@ def before_save(object)
122122
if valuehash['gitRedmineSubdir']
123123
normalizedFile = File.expand_path(valuehash['gitRedmineSubdir'].lstrip.rstrip,"/")
124124
if (normalizedFile != "/")
125-
valuehash['gitRedmineSubdir'] = normalizedFile[1..-1] + "/" # Clobber leading '/' add trailing '/'
125+
valuehash['gitRedmineSubdir'] = normalizedFile[1..-1] + "/" # Clobber leading '/' add trailing '/'
126126
else
127127
valuehash['gitRedmineSubdir'] = ''
128128
end
@@ -144,7 +144,7 @@ def before_save(object)
144144
h[x]+=1 unless x.blank?
145145
h
146146
end.values.max) || 0) > 1
147-
# Oops -- have duplication. Force to false.
147+
# Oops -- have duplication. Force to false.
148148
GitHosting.logger.error "Detected non-unique repository identifiers. Setting gitRepositoryIdentUnique => 'false'."
149149
valuehash['gitRepositoryIdentUnique'] = "false"
150150
end

Diff for: config/routes.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
def install_redmine_git_hosting_routes(map)
2-
# URL for items of type httpServer/XXX.git. Some versions of rails has problems with multiple regex expressions, so avoid...
2+
# URL for items of type httpServer/XXX.git. Some versions of rails has problems with multiple regex expressions, so avoid...
33
# Note that 'http_server_subdir' is either empty (default case) or ends in '/'.
44
map.connect ":repo_path/*path",
5-
:prefix => Setting.plugin_redmine_git_hosting['httpServerSubdir'], :repo_path => /([^\/]+\/)*?[^\/]+\.git/, :controller => 'git_http'
5+
:prefix => (Setting.plugin_redmine_git_hosting['httpServerSubdir'] rescue ""), :repo_path => /([^\/]+\/)*?[^\/]+\.git/, :controller => 'git_http'
66

77
# Handle the public keys plugin to my/account.
88
map.resources :public_keys, :controller => 'gitolite_public_keys', :path_prefix => 'my'

Diff for: init.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ class GitRepoUrlHook < Redmine::Hook::ViewListener
8989
Redmine::Scm::Base.all.unshift("Git").uniq!
9090

9191
# initialize observer
92+
# Don't initialize this while doing migration of primary system (i.e. Redmine/Chiliproject)
93+
migrating_primary = (File.basename($0) == "rake" && ARGV.include?("db:migrate"))
9294
config.after_initialize do
93-
if config.action_controller.perform_caching
95+
if config.action_controller.perform_caching && !migrating_primary
9496
ActiveRecord::Base.observers = ActiveRecord::Base.observers << GitHostingObserver
9597
ActiveRecord::Base.observers = ActiveRecord::Base.observers << GitHostingSettingsObserver
9698

@@ -102,4 +104,3 @@ class GitRepoUrlHook < Redmine::Hook::ViewListener
102104
end
103105
end
104106
end
105-

0 commit comments

Comments
 (0)