Commit b3c8688da33ac2fd79d733fc9992a526c18c2c40

Authored by Cornelio
Committed by Hopmann, Cornelio
1 parent e4447de2

fix bulk_import for #1309

Showing 1 changed file with 14 additions and 15 deletions   Show diff stats
lib/tasks/bulk_import.rake
1 -IMPORT_DIRECTORY = 'import_projects'  
2 -  
3 -desc "Imports existing Git repos into new projects from the import_projects folder"  
4 -task :import_projects, [:email] => :environment do |t, args|  
5 - REPOSITORY_DIRECTORY = Gitlab.config.git_base_path  
6 1
  2 +desc "Imports existing Git repos from a directory into new projects in git_base_path"
  3 +task :import_projects, [:directory,:email] => :environment do |t, args|
7 user_email = args.email 4 user_email = args.email
8 - repos_to_import = Dir.glob("#{IMPORT_DIRECTORY}/*")  
9 - 5 + import_directory = args.directory
  6 + repos_to_import = Dir.glob("#{import_directory}/*")
  7 + git_base_path = Gitlab.config.git_base_path
10 puts "Found #{repos_to_import.length} repos to import" 8 puts "Found #{repos_to_import.length} repos to import"
11 9
12 imported_count = 0 10 imported_count = 0
@@ -14,11 +12,9 @@ task :import_projects, [:email] => :environment do |t, args| @@ -14,11 +12,9 @@ task :import_projects, [:email] => :environment do |t, args|
14 failed_count = 0 12 failed_count = 0
15 repos_to_import.each do |repo_path| 13 repos_to_import.each do |repo_path|
16 repo_name = File.basename repo_path 14 repo_name = File.basename repo_path
17 - repo_full_path = File.join(Rails.root, repo_path)  
18 15
19 puts " Processing #{repo_name}" 16 puts " Processing #{repo_name}"
20 -  
21 - clone_path = "#{REPOSITORY_DIRECTORY}/#{repo_name}.git" 17 + clone_path = "#{git_base_path}#{repo_name}.git"
22 18
23 if Dir.exists? clone_path 19 if Dir.exists? clone_path
24 if Project.find_by_code(repo_name) 20 if Project.find_by_code(repo_name)
@@ -30,7 +26,7 @@ task :import_projects, [:email] => :environment do |t, args| @@ -30,7 +26,7 @@ task :import_projects, [:email] => :environment do |t, args|
30 end 26 end
31 else 27 else
32 # Clone the repo 28 # Clone the repo
33 - unless clone_bare_repo_as_git(repo_full_path, clone_path) 29 + unless clone_bare_repo_as_git(repo_path, clone_path)
34 failed_count += 1 30 failed_count += 1
35 next 31 next
36 end 32 end
@@ -48,14 +44,17 @@ task :import_projects, [:email] => :environment do |t, args| @@ -48,14 +44,17 @@ task :import_projects, [:email] => :environment do |t, args|
48 puts "Finished importing #{imported_count} projects (skipped #{skipped_count}, failed #{failed_count})." 44 puts "Finished importing #{imported_count} projects (skipped #{skipped_count}, failed #{failed_count})."
49 end 45 end
50 46
51 -# Clones a repo as bare git repo using the git user 47 +# Clones a repo as bare git repo using the git_user
52 def clone_bare_repo_as_git(existing_path, new_path) 48 def clone_bare_repo_as_git(existing_path, new_path)
  49 + git_user = Gitlab.config.ssh_user
53 begin 50 begin
54 - sh "sudo -u git -i git clone --bare '#{existing_path}' #{new_path}" 51 + sh "sudo -u #{git_user} -i git clone --bare '#{existing_path}' #{new_path}"
55 true 52 true
56 - rescue 53 + rescue Exception=> msg
57 puts " ERROR: Faild to clone #{existing_path} to #{new_path}" 54 puts " ERROR: Faild to clone #{existing_path} to #{new_path}"
58 - false 55 + puts " Make sure #{git_user} can reach #{existing_path}"
  56 + puts " Exception-MSG: #{msg}"
  57 + false
59 end 58 end
60 end 59 end
61 60