diff options
author | Stan Hu <stanhu@gmail.com> | 2019-03-22 21:40:50 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-03-22 21:40:50 +0300 |
commit | 3eba3a187c6fab19937ff072f848e5a4d47ab2b2 (patch) | |
tree | 903105d81ef9640677c3b9d59f8ddf3aff2ed092 | |
parent | 7ffc79829194d3be18cf66017528a90b41586054 (diff) | |
parent | 98194f176618fc2e83c3e8e89759356ca132f86a (diff) |
Merge branch 'retain-default-branch-on-import' into 'master'
Set proper default-branch on GitHub Import
Closes #59347
See merge request gitlab-org/gitlab-ce!26476
3 files changed, 31 insertions, 1 deletions
diff --git a/changelogs/unreleased/retain-default-branch-on-import.yml b/changelogs/unreleased/retain-default-branch-on-import.yml new file mode 100644 index 00000000000..c83ccf39a27 --- /dev/null +++ b/changelogs/unreleased/retain-default-branch-on-import.yml @@ -0,0 +1,5 @@ +--- +title: Set proper default-branch for repository on GitHub Import +merge_request: 26476 +author: +type: fixed diff --git a/lib/gitlab/github_import/importer/repository_importer.rb b/lib/gitlab/github_import/importer/repository_importer.rb index e2dfb00dcc5..6d48c6a15b4 100644 --- a/lib/gitlab/github_import/importer/repository_importer.rb +++ b/lib/gitlab/github_import/importer/repository_importer.rb @@ -5,6 +5,7 @@ module Gitlab module Importer class RepositoryImporter include Gitlab::ShellAdapter + include Gitlab::Utils::StrongMemoize attr_reader :project, :client, :wiki_formatter @@ -17,7 +18,7 @@ module Gitlab # Returns true if we should import the wiki for the project. # rubocop: disable CodeReuse/ActiveRecord def import_wiki? - client.repository(project.import_source)&.has_wiki && + client_repository&.has_wiki && !project.wiki_repository_exists? && Gitlab::GitalyClient::RemoteService.exists?(wiki_url) end @@ -52,6 +53,7 @@ module Gitlab refmap = Gitlab::GithubImport.refmap project.repository.fetch_as_mirror(project.import_url, refmap: refmap, forced: true, remote_name: 'github') + project.change_head(default_branch) if default_branch true rescue Gitlab::Git::Repository::NoRepository, Gitlab::Shell::Error => e fail_import("Failed to import the repository: #{e.message}") @@ -82,6 +84,18 @@ module Gitlab project.import_state.mark_as_failed(message) false end + + private + + def default_branch + client_repository&.default_branch + end + + def client_repository + strong_memoize(:client_repository) do + client.repository(project.import_source) + end + end end end end diff --git a/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb b/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb index 47233ea6ee2..41810a8ec03 100644 --- a/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb @@ -179,6 +179,17 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do describe '#import_repository' do it 'imports the repository' do + repo = double(:repo, default_branch: 'develop') + + expect(client) + .to receive(:repository) + .with('foo/bar') + .and_return(repo) + + expect(project) + .to receive(:change_head) + .with('develop') + expect(project) .to receive(:ensure_repository) |