From 59d91729c833278c518d85d1ba3c24ca21762c46 Mon Sep 17 00:00:00 2001 From: Donny Kurnia Date: Mon, 28 Jan 2013 21:53:41 +0700 Subject: [PATCH 1/2] Check if project.repository before check Fix for #2776 --- lib/tasks/gitlab/check.rake | 84 +++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index e20809cc..b132a48a 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -778,23 +778,25 @@ namespace :gitlab do } Project.find_each(batch_size: 100) do |project| - print "#{project.name_with_namespace.yellow} ... " + if project.repository + print "#{project.name_with_namespace.yellow} ... " - correct_options = options.map do |name, value| - run("git --git-dir=\"#{project.repository.path_to_repo}\" config --get #{name}").try(:chomp) == value - end + correct_options = options.map do |name, value| + run("git --git-dir=\"#{project.repository.path_to_repo}\" config --get #{name}").try(:chomp) == value + end - if correct_options.all? - puts "ok".green - else - puts "wrong or missing".red - try_fixing_it( - sudo_gitlab("bundle exec rake gitlab:gitolite:update_repos") - ) - for_more_information( - "doc/raketasks/maintenance.md" - ) - fix_and_rerun + if correct_options.all? + puts "ok".green + else + puts "wrong or missing".red + try_fixing_it( + sudo_gitlab("bundle exec rake gitlab:gitolite:update_repos") + ) + for_more_information( + "doc/raketasks/maintenance.md" + ) + fix_and_rerun + end end end end @@ -819,33 +821,35 @@ namespace :gitlab do puts "" Project.find_each(batch_size: 100) do |project| - print "#{project.name_with_namespace.yellow} ... " - project_hook_file = File.join(project.repository.path_to_repo, "hooks", hook_file) + if project.repository + print "#{project.name_with_namespace.yellow} ... " + project_hook_file = File.join(project.repository.path_to_repo, "hooks", hook_file) - unless File.exists?(project_hook_file) - puts "missing".red - try_fixing_it( - "sudo -u #{gitolite_ssh_user} ln -sf #{gitolite_hook_file} #{project_hook_file}" - ) - for_more_information( - "lib/support/rewrite-hooks.sh" - ) - fix_and_rerun - next - end + unless File.exists?(project_hook_file) + puts "missing".red + try_fixing_it( + "sudo -u #{gitolite_ssh_user} ln -sf #{gitolite_hook_file} #{project_hook_file}" + ) + for_more_information( + "lib/support/rewrite-hooks.sh" + ) + fix_and_rerun + next + end - if File.lstat(project_hook_file).symlink? && - File.realpath(project_hook_file) == File.realpath(gitolite_hook_file) - puts "ok".green - else - puts "not a link to Gitolite's hook".red - try_fixing_it( - "sudo -u #{gitolite_ssh_user} ln -sf #{gitolite_hook_file} #{project_hook_file}" - ) - for_more_information( - "lib/support/rewrite-hooks.sh" - ) - fix_and_rerun + if File.lstat(project_hook_file).symlink? && + File.realpath(project_hook_file) == File.realpath(gitolite_hook_file) + puts "ok".green + else + puts "not a link to Gitolite's hook".red + try_fixing_it( + "sudo -u #{gitolite_ssh_user} ln -sf #{gitolite_hook_file} #{project_hook_file}" + ) + for_more_information( + "lib/support/rewrite-hooks.sh" + ) + fix_and_rerun + end end end end From 506309e17a4ecb78b042df34f9a2495a7aafb459 Mon Sep 17 00:00:00 2001 From: Donny Kurnia Date: Mon, 28 Jan 2013 22:07:46 +0700 Subject: [PATCH 2/2] Using empty_repo? instead Display message if repository is empty --- lib/tasks/gitlab/check.rake | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index b132a48a..00068abf 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -778,9 +778,11 @@ namespace :gitlab do } Project.find_each(batch_size: 100) do |project| - if project.repository - print "#{project.name_with_namespace.yellow} ... " + print "#{project.name_with_namespace.yellow} ... " + if project.empty_repo? + puts "repository is empty".magenta + else correct_options = options.map do |name, value| run("git --git-dir=\"#{project.repository.path_to_repo}\" config --get #{name}").try(:chomp) == value end @@ -821,8 +823,11 @@ namespace :gitlab do puts "" Project.find_each(batch_size: 100) do |project| - if project.repository - print "#{project.name_with_namespace.yellow} ... " + print "#{project.name_with_namespace.yellow} ... " + + if project.empty_repo? + puts "repository is empty".magenta + else project_hook_file = File.join(project.repository.path_to_repo, "hooks", hook_file) unless File.exists?(project_hook_file)