summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2014-09-16 14:20:31 +0200
committerJacob Vosmaer <contact@jacobvosmaer.nl>2014-09-16 14:23:12 +0200
commit236592521ec239437a8fb3ae027a0e4d693a7a47 (patch)
tree76358101dca4d5b7a73199c52441350fe6c6836c
parentff1633f418c29bd613d571107df43396e27b522e (diff)
downloadgitlab-ce-236592521ec239437a8fb3ae027a0e4d693a7a47.tar.gz
Add `rake gitlab:migrate:shell_hooks`
-rw-r--r--db/migrate/20140903115954_migrate_to_new_shell.rb.skip5
-rw-r--r--lib/tasks/gitlab/migrate/shell_hooks.rake36
2 files changed, 41 insertions, 0 deletions
diff --git a/db/migrate/20140903115954_migrate_to_new_shell.rb.skip b/db/migrate/20140903115954_migrate_to_new_shell.rb.skip
new file mode 100644
index 00000000000..8c22ee181bb
--- /dev/null
+++ b/db/migrate/20140903115954_migrate_to_new_shell.rb.skip
@@ -0,0 +1,5 @@
+class MigrateToNewShell < ActiveRecord::Migration
+ def change
+ # The migration was performed by the rake task
+ end
+end
diff --git a/lib/tasks/gitlab/migrate/shell_hooks.rake b/lib/tasks/gitlab/migrate/shell_hooks.rake
new file mode 100644
index 00000000000..b4fc020b5e3
--- /dev/null
+++ b/lib/tasks/gitlab/migrate/shell_hooks.rake
@@ -0,0 +1,36 @@
+namespace :gitlab do
+ namespace :migrate do
+ task shell_hooks: :environment do
+ migration_file = Rails.root.join('db/migrate/20140903115954_migrate_to_new_shell.rb')
+ migration_source_file = "#{migration_file}.skip"
+
+ unless File.exists?(migration_file)
+ begin
+ FileUtils.cp(migration_source_file, migration_file)
+ rescue => ex
+ warn "Please make sure #{migration_file} exists."
+ warn "\n sudo cp #{migration_source_file} #{migration_file}\n\n"
+ raise ex
+ end
+ end
+
+ gitlab_shell_path = Gitlab.config.gitlab_shell.path
+ unless system("#{gitlab_shell_path}/bin/create-hooks")
+ abort 'Failed to rewrite gitlab-shell hooks in repositories'
+ end
+
+ hooks_migration_id = '20140903115954'
+ unless system(*%W(rake db:migrate:up VERSION=#{hooks_migration_id}))
+ abort "Failed to run migration #{hooks_migration_id}"
+ end
+
+ puts 'Repositories updated with new hooks'
+ begin
+ FileUtils.rm(migration_file)
+ rescue
+ warn "Please remove #{migration_file}"
+ warn "\n sudo rm #{migration_file}\n\n"
+ end
+ end
+ end
+end