Commit 137594dd08e739a68af656d697a5b8c6be23854f

Authored by Dmitriy Zaporozhets
2 parents 5cb9e7ee b3c8688d

Merge pull request #1339 from chopmann/fix-import_bulk

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 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 8 puts "Found #{repos_to_import.length} repos to import"
11 9  
12 10 imported_count = 0
... ... @@ -14,11 +12,9 @@ task :import_projects, [:email] => :environment do |t, args|
14 12 failed_count = 0
15 13 repos_to_import.each do |repo_path|
16 14 repo_name = File.basename repo_path
17   - repo_full_path = File.join(Rails.root, repo_path)
18 15  
19 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 19 if Dir.exists? clone_path
24 20 if Project.find_by_code(repo_name)
... ... @@ -30,7 +26,7 @@ task :import_projects, [:email] => :environment do |t, args|
30 26 end
31 27 else
32 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 30 failed_count += 1
35 31 next
36 32 end
... ... @@ -48,14 +44,17 @@ task :import_projects, [:email] => :environment do |t, args|
48 44 puts "Finished importing #{imported_count} projects (skipped #{skipped_count}, failed #{failed_count})."
49 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 48 def clone_bare_repo_as_git(existing_path, new_path)
  49 + git_user = Gitlab.config.ssh_user
53 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 52 true
56   - rescue
  53 + rescue Exception=> msg
57 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 58 end
60 59 end
61 60  
... ...