240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
# File 'lib/utopia/command.rb', line 240
def invoke(parent)
destination_root = parent.root
branch_name = "utopia-upgrade-#{Utopia::VERSION}"
$stderr.puts "Upgrading #{destination_root}..."
Dir.chdir(destination_root) do
system('git', 'checkout', '-b', branch_name)
end
Setup::Site::DIRECTORIES.each do |directory|
FileUtils.mkdir_p(File.join(destination_root, directory))
end
Setup::Site::OLD_DIRECTORIES.each do |directory|
path = File.join(destination_root, directory)
$stderr.puts "\tRemoving #{path}..."
FileUtils.rm_rf(path)
end
Setup::Site::CONFIGURATION_FILES.each do |configuration_file|
source_path = File.join(Setup::Site::ROOT, configuration_file)
destination_path = File.join(destination_root, configuration_file)
$stderr.puts "Updating #{destination_path}..."
FileUtils.copy_entry(source_path, destination_path)
buffer = File.read(destination_path).gsub('$UTOPIA_VERSION', Utopia::VERSION)
File.open(destination_path, "w") { |file| file.write(buffer) }
end
begin
Dir.chdir(destination_root) do
system("git", "add", "-u")
system("git", "add", *Setup::Site::CONFIGURATION_FILES)
move_static!
system("git", "commit", "-m", "Upgrade to utopia #{Utopia::VERSION}.")
system("git", "checkout", "master")
system("git", "merge", "--no-commit", "--no-ff", branch_name)
end
rescue RuntimeError
$stderr.puts "** Detected error with upgrade, reverting changes. Some new files may still exist in tree. **"
system("git", "checkout", "master")
system("git", "branch", "-d", branch_name)
end
end
|