diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-03-05 10:45:46 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-03-05 10:45:46 +0000 |
commit | f1d8efb7700fb95b98924ffe2e65dd08f7f376c9 (patch) | |
tree | f1534c98525491abdbbfeafe21168996c304117c | |
parent | 132c1b4c0ab54512e68eac68de322d8e4f8f59c4 (diff) | |
parent | d6b0ac96f7b2952edb8aad0efcd48e0bccd23fe0 (diff) | |
download | gitlab-ce-f1d8efb7700fb95b98924ffe2e65dd08f7f376c9.tar.gz |
Merge branch 'shell_new_style' into 'master'
Use new style shell commands
-rw-r--r-- | app/controllers/admin/background_jobs_controller.rb | 3 | ||||
-rw-r--r-- | config/initializers/2_app.rb | 2 | ||||
-rw-r--r-- | lib/backup/manager.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/logger.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/upgrader.rb | 27 | ||||
-rw-r--r-- | lib/tasks/gitlab/check.rake | 9 | ||||
-rw-r--r-- | lib/tasks/gitlab/generate_docs.rake | 2 | ||||
-rw-r--r-- | lib/tasks/gitlab/info.rake | 12 | ||||
-rw-r--r-- | lib/tasks/gitlab/task_helpers.rake | 13 | ||||
-rw-r--r-- | lib/tasks/gitlab/test.rake | 12 | ||||
-rw-r--r-- | lib/tasks/sidekiq.rake | 8 | ||||
-rw-r--r-- | spec/models/gollum_wiki_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/wiki_page_spec.rb | 6 | ||||
-rw-r--r-- | spec/support/test_env.rb | 17 |
14 files changed, 66 insertions, 64 deletions
diff --git a/app/controllers/admin/background_jobs_controller.rb b/app/controllers/admin/background_jobs_controller.rb index 159ab2027c2..f2b8277efea 100644 --- a/app/controllers/admin/background_jobs_controller.rb +++ b/app/controllers/admin/background_jobs_controller.rb @@ -1,5 +1,6 @@ class Admin::BackgroundJobsController < Admin::ApplicationController def show - @sidekiq_processes = `ps -U #{Settings.gitlab.user} -o euser,pid,pcpu,pmem,stat,start,command | grep sidekiq | grep -v grep` + ps_output, _ = Gitlab::Popen.popen(%W(ps -U #{Settings.gitlab.user} -o euser,pid,pcpu,pmem,stat,start,command)) + @sidekiq_processes = ps_output.split("\n").grep(/sidekiq/) end end diff --git a/config/initializers/2_app.rb b/config/initializers/2_app.rb index e2f98002347..655590dff0b 100644 --- a/config/initializers/2_app.rb +++ b/config/initializers/2_app.rb @@ -1,6 +1,6 @@ module Gitlab VERSION = File.read(Rails.root.join("VERSION")).strip - REVISION = `git log --pretty=format:'%h' -n 1` + REVISION = Gitlab::Popen.popen(%W(git log --pretty=format:%h -n 1)).first.chomp def self.config Settings diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb index a93d35a1cd1..05814fc78f6 100644 --- a/lib/backup/manager.rb +++ b/lib/backup/manager.rb @@ -8,7 +8,7 @@ module Backup s[:db_version] = "#{ActiveRecord::Migrator.current_version}" s[:backup_created_at] = Time.now s[:gitlab_version] = Gitlab::VERSION - s[:tar_version] = %x{tar --version | head -1}.gsub(/\n/,"") + s[:tar_version] = tar_version Dir.chdir(Gitlab.config.backup.path) @@ -98,5 +98,10 @@ module Backup exit 1 end end + + def tar_version + tar_version, _ = Gitlab::Popen.popen(%W(tar --version)) + tar_version.split("\n").first + end end end diff --git a/lib/gitlab/logger.rb b/lib/gitlab/logger.rb index 389eef3395f..64cf3303ea3 100644 --- a/lib/gitlab/logger.rb +++ b/lib/gitlab/logger.rb @@ -11,12 +11,14 @@ module Gitlab def self.read_latest path = Rails.root.join("log", file_name) self.build unless File.exist?(path) - logs = `tail -n 2000 #{path}`.split("\n") + tail_output, _ = Gitlab::Popen.popen(%W(tail -n 2000 #{path})) + tail_output.split("\n") end def self.read_latest_for filename path = Rails.root.join("log", filename) - logs = `tail -n 2000 #{path}`.split("\n") + tail_output, _ = Gitlab::Popen.popen(%W(tail -n 2000 #{path})) + tail_output.split("\n") end def self.build diff --git a/lib/gitlab/upgrader.rb b/lib/gitlab/upgrader.rb index f46685e4bbe..0fe4888665d 100644 --- a/lib/gitlab/upgrader.rb +++ b/lib/gitlab/upgrader.rb @@ -42,28 +42,33 @@ module Gitlab end def latest_version_raw - git_tags = `git ls-remote --tags origin | grep tags\/v#{current_version.major}` - git_tags = git_tags.lines.to_a.select { |version| version =~ /v\d\.\d\.\d\Z/ } + remote_tags, _ = Gitlab::Popen.popen(%W(git ls-remote --tags origin)) + git_tags = remote_tags.split("\n").grep(/tags\/v#{current_version.major}/) + git_tags = git_tags.select { |version| version =~ /v\d\.\d\.\d\Z/ } last_tag = git_tags.last.match(/v\d\.\d\.\d/).to_s end def update_commands { - "Stash changed files" => "git stash", - "Get latest code" => "git fetch", - "Switch to new version" => "git checkout v#{latest_version}", - "Install gems" => "bundle", - "Migrate DB" => "bundle exec rake db:migrate RAILS_ENV=production", - "Recompile assets" => "bundle exec rake assets:clean assets:precompile RAILS_ENV=production", - "Clear cache" => "bundle exec rake cache:clear RAILS_ENV=production" + "Stash changed files" => %W(git stash), + "Get latest code" => %W(git fetch), + "Switch to new version" => %W(git checkout v#{latest_version}), + "Install gems" => %W(bundle), + "Migrate DB" => %W(bundle exec rake db:migrate), + "Recompile assets" => %W(bundle exec rake assets:clean assets:precompile), + "Clear cache" => %W(bundle exec rake cache:clear) } end + def env + {'RAILS_ENV' => 'production'} + end + def upgrade update_commands.each do |title, cmd| puts title - puts " -> #{cmd}" - if system(cmd) + puts " -> #{cmd.join(' ')}" + if system(env, *cmd) puts " -> OK" else puts " -> FAILED" diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index c91dedf74c7..7bcd4759484 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -168,7 +168,7 @@ namespace :gitlab do def check_migrations_are_up print "All migrations up? ... " - migration_status = `bundle exec rake db:migrate:status` + migration_status, _ = Gitlab::Popen.popen(%W(bundle exec rake db:migrate:status)) unless migration_status =~ /down\s+\d{14}/ puts "yes".green @@ -295,7 +295,7 @@ namespace :gitlab do "user.email" => Gitlab.config.gitlab.email_from } correct_options = options.map do |name, value| - run("git config --global --get #{name}").try(:squish) == value + run(%W(git config --global --get #{name})).try(:squish) == value end if correct_options.all? @@ -628,7 +628,8 @@ namespace :gitlab do end def sidekiq_process_count - `ps ux`.scan(/sidekiq \d+\.\d+\.\d+/).count + ps_ux, _ = Gitlab::Popen.popen(%W(ps ux)) + ps_ux.scan(/sidekiq \d+\.\d+\.\d+/).count end end @@ -739,7 +740,7 @@ namespace :gitlab do def check_git_version required_version = Gitlab::VersionInfo.new(1, 7, 10) - current_version = Gitlab::VersionInfo.parse(run("#{Gitlab.config.git.bin_path} --version")) + current_version = Gitlab::VersionInfo.parse(run(%W(#{Gitlab.config.git.bin_path} --version))) puts "Your git bin path is \"#{Gitlab.config.git.bin_path}\"" print "Git version >= #{required_version} ? ... " diff --git a/lib/tasks/gitlab/generate_docs.rake b/lib/tasks/gitlab/generate_docs.rake index 58795fac4af..332cd61f84c 100644 --- a/lib/tasks/gitlab/generate_docs.rake +++ b/lib/tasks/gitlab/generate_docs.rake @@ -1,7 +1,7 @@ namespace :gitlab do desc "GITLAB | Generate sdocs for project" task generate_docs: :environment do - system("bundle exec sdoc -o doc/code app lib") + system(*%W(bundle exec sdoc -o doc/code app lib)) end end diff --git a/lib/tasks/gitlab/info.rake b/lib/tasks/gitlab/info.rake index ea83efcd887..690f414f3b3 100644 --- a/lib/tasks/gitlab/info.rake +++ b/lib/tasks/gitlab/info.rake @@ -4,20 +4,20 @@ namespace :gitlab do task info: :environment do # check if there is an RVM environment - rvm_version = run_and_match("rvm --version", /[\d\.]+/).try(:to_s) + rvm_version = run_and_match(%W(rvm --version), /[\d\.]+/).try(:to_s) # check Ruby version - ruby_version = run_and_match("ruby --version", /[\d\.p]+/).try(:to_s) + ruby_version = run_and_match(%W(ruby --version), /[\d\.p]+/).try(:to_s) # check Gem version - gem_version = run("gem --version") + gem_version = run(%W(gem --version)) # check Bundler version - bunder_version = run_and_match("bundle --version", /[\d\.]+/).try(:to_s) + bunder_version = run_and_match(%W(bundle --version), /[\d\.]+/).try(:to_s) # check Bundler version - rake_version = run_and_match("rake --version", /[\d\.]+/).try(:to_s) + rake_version = run_and_match(%W(rake --version), /[\d\.]+/).try(:to_s) puts "" puts "System information".yellow puts "System:\t\t#{os_name || "unknown".red}" - puts "Current User:\t#{`whoami`}" + puts "Current User:\t#{run(%W(whoami))}" puts "Using RVM:\t#{rvm_version.present? ? "yes".green : "no"}" puts "RVM Version:\t#{rvm_version}" if rvm_version.present? puts "Ruby Version:\t#{ruby_version || "unknown".red}" diff --git a/lib/tasks/gitlab/task_helpers.rake b/lib/tasks/gitlab/task_helpers.rake index c46d5855faf..d36b9682850 100644 --- a/lib/tasks/gitlab/task_helpers.rake +++ b/lib/tasks/gitlab/task_helpers.rake @@ -28,7 +28,7 @@ namespace :gitlab do # It will primarily use lsb_relase to determine the OS. # It has fallbacks to Debian, SuSE, OS X and systems running systemd. def os_name - os_name = run("lsb_release -irs") + os_name = run(%W(lsb_release -irs)) os_name ||= if File.readable?('/etc/system-release') File.read('/etc/system-release') end @@ -39,7 +39,7 @@ namespace :gitlab do os_name ||= if File.readable?('/etc/SuSE-release') File.read('/etc/SuSE-release') end - os_name ||= if os_x_version = run("sw_vers -productVersion") + os_name ||= if os_x_version = run(%W(sw_vers -productVersion)) "Mac OS X #{os_x_version}" end os_name ||= if File.readable?('/etc/os-release') @@ -80,13 +80,12 @@ namespace :gitlab do # # see also #run_and_match def run(command) - unless `#{command} 2>/dev/null`.blank? - `#{command}` - end + output, _ = Gitlab::Popen.popen(command) + output end def uid_for(user_name) - run("id -u #{user_name}").chomp.to_i + run(%W(id -u #{user_name})).chomp.to_i end def gid_for(group_name) @@ -100,7 +99,7 @@ namespace :gitlab do def warn_user_is_not_gitlab unless @warned_user_not_gitlab gitlab_user = Gitlab.config.gitlab.user - current_user = run("whoami").chomp + current_user = run(%W(whoami)).chomp unless current_user == gitlab_user puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}" puts " You are running as user #{current_user.magenta}, we hope you know what you are doing." diff --git a/lib/tasks/gitlab/test.rake b/lib/tasks/gitlab/test.rake index 011748c9711..f52af0c3ded 100644 --- a/lib/tasks/gitlab/test.rake +++ b/lib/tasks/gitlab/test.rake @@ -2,15 +2,15 @@ namespace :gitlab do desc "GITLAB | Run all tests" task :test do cmds = [ - "rake db:setup", - "rake db:seed_fu", - "rake spinach", - "rake spec", - "rake jasmine:ci" + %W(rake db:setup), + %W(rake db:seed_fu), + %W(rake spinach), + %W(rake spec), + %W(rake jasmine:ci) ] cmds.each do |cmd| - system(cmd + " RAILS_ENV=test") + system({'RAILS_ENV' => 'test'}, *cmd) raise "#{cmd} failed!" unless $?.exitstatus.zero? end diff --git a/lib/tasks/sidekiq.rake b/lib/tasks/sidekiq.rake index e91678473a8..ba806e53ccf 100644 --- a/lib/tasks/sidekiq.rake +++ b/lib/tasks/sidekiq.rake @@ -1,21 +1,21 @@ namespace :sidekiq do desc "GITLAB | Stop sidekiq" task :stop do - system "script/background_jobs stop" + system *%W(script/background_jobs stop) end desc "GITLAB | Start sidekiq" task :start do - system "script/background_jobs start" + system *%W(script/background_jobs start) end desc 'GitLab | Restart sidekiq' task :restart do - system "script/background_jobs restart" + system *%W(script/background_jobs restart) end desc "GITLAB | Start sidekiq with launchd on Mac OS X" task :launchd do - system "script/background_jobs start_no_deamonize" + system *%W(script/background_jobs start_no_deamonize) end end diff --git a/spec/models/gollum_wiki_spec.rb b/spec/models/gollum_wiki_spec.rb index 9e07d9ee191..9b9d15b4ff4 100644 --- a/spec/models/gollum_wiki_spec.rb +++ b/spec/models/gollum_wiki_spec.rb @@ -2,12 +2,6 @@ require "spec_helper" describe GollumWiki do - def create_temp_repo(path) - FileUtils.mkdir_p path - command = "git init --quiet #{path};" - system(command) - end - def remove_temp_repo(path) FileUtils.rm_rf path end diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index 67f2a6da42d..1c70edf0d4d 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -2,12 +2,6 @@ require "spec_helper" describe WikiPage do - def create_temp_repo(path) - FileUtils.mkdir_p path - command = "git init --quiet #{path};" - system(command) - end - def remove_temp_repo(path) FileUtils.rm_rf path end diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 43aec1cd43d..77a669c0cc1 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -104,10 +104,12 @@ module TestEnv def reset_satellite_dir setup_stubs - FileUtils.cd(seed_satellite_path) do - `git reset --hard --quiet` - `git clean -fx` - `git checkout --quiet origin/master` + [ + %W(git reset --hard --quiet), + %W(git clean -fx), + %W(git checkout --quiet origin/master) + ].each do |git_cmd| + system(*git_cmd, chdir: seed_satellite_path) end end @@ -117,7 +119,7 @@ module TestEnv repo = repo(namespace, name) # Symlink tmp/repositories/gitlabhq to tmp/test-git-base-path/gitlabhq - system("ln -s -f #{seed_repo_path()} #{repo}") + FileUtils.ln_sf(seed_repo_path, repo) create_satellite(repo, namespace, name) end @@ -181,12 +183,11 @@ module TestEnv # Symlink tmp/satellite/gitlabhq to tmp/test-git-base-path/satellite/gitlabhq, create the directory if it doesn't exist already satellite_dir = File.dirname(satellite_repo) FileUtils.mkdir_p(satellite_dir) unless File.exists?(satellite_dir) - system("ln -s -f #{seed_satellite_path} #{satellite_repo}") + FileUtils.ln_sf(seed_satellite_path, satellite_repo) end def create_temp_repo(path) FileUtils.mkdir_p path - command = "git init --quiet --bare #{path};" - system(command) + system(*%W(git init --quiet --bare -- #{path})) end end |