Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only search gitlab:import:repos on repos on subdir [failure unrelated][can be updated] #8140

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/raketasks/import.md
Expand Up @@ -22,6 +22,8 @@ your repositories are located by looking at `config/gitlab.yml` under the `gitla
$ cp -r /old/git/foo.git/ /home/git/repositories/new_group/
```

The repository folder must end in `.git`.

### Run the command below depending on your type of installation:

#### Omnibus Installation
Expand Down
29 changes: 13 additions & 16 deletions lib/tasks/gitlab/import.rake
Expand Up @@ -13,15 +13,14 @@ namespace :gitlab do
task repos: :environment do

git_base_path = Gitlab.config.gitlab_shell.repos_path
repos_to_import = Dir.glob(git_base_path + '/**/*.git')
repos_to_import = Dir.glob(git_base_path + '/*/*.git')

repos_to_import.each do |repo_path|
# strip repo base path
repo_path[0..git_base_path.length] = ''

path = repo_path.sub(/\.git$/, '')
group_name, name = File.split(path)
group_name = nil if group_name == '.'

puts "Processing #{repo_path}".yellow

Expand All @@ -43,22 +42,20 @@ namespace :gitlab do
}

# find group namespace
if group_name
group = Namespace.find_by(path: group_name)
# create group namespace
unless group
group = Group.new(:name => group_name)
group.path = group_name
group.owner = user
if group.save
puts " * Created Group #{group.name} (#{group.id})".green
else
puts " * Failed trying to create group #{group.name}".red
end
group = Namespace.find_by(path: group_name)
# create group namespace
if !group
group = Group.new(:name => group_name)
group.path = group_name
group.owner = user
if group.save
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want validations to run here? i.e. save!?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC .save already does validations and returns false on fail: the difference is that save! would raise: http://guides.rubyonrails.org/active_record_validations.html#when-does-validation-happen-questionmark

puts " * Created Group #{group.name} (#{group.id})".green
else
puts " * Failed trying to create group #{group.name}".red
end
# set project group
project_params[:namespace_id] = group.id
end
# set project group
project_params[:namespace_id] = group.id

project = Projects::CreateService.new(user, project_params).execute

Expand Down