summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2017-11-08 15:04:56 +0000
committerTiago Botelho <tiagonbotelho@hotmail.com>2017-11-08 16:52:32 +0000
commit37842fc815d8e0b18ef5adcc83572a0588529c24 (patch)
tree7a3aafe8095f5692e3a65eaff8b410f2f1750206
parent76e75549b9bec9dee1e856969ef169a4450b3f30 (diff)
downloadgitlab-shell-add-single-branch-option-to-git-clone.tar.gz
Adds --single-branch option to git cloneadd-single-branch-option-to-git-clone
-rw-r--r--lib/gitlab_projects.rb9
-rw-r--r--spec/gitlab_projects_spec.rb40
2 files changed, 34 insertions, 15 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index 9586345..4231b78 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -252,11 +252,16 @@ class GitlabProjects
@source = ARGV.shift
masked_source = mask_password_in_url(@source)
+ # clone with --single-branch ?
+ single_branch = ARGV.delete('--single-branch') if ARGV.include?('--single-branch')
+
# timeout for clone
timeout = (ARGV.shift || 120).to_i
- $logger.info "Importing project #{@project_name} from <#{masked_source}> to <#{full_path}>."
- cmd = %W(git clone --bare -- #{@source} #{full_path})
+ $logger.info "Importing project #{@project_name} from <#{masked_source}> to <#{full_path}>."
+ cmd = %W(git clone --bare)
+ cmd << single_branch if single_branch
+ cmd += %W(-- #{@source} #{full_path})
pid = Process.spawn(*cmd)
begin
diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb
index ffba3d4..cc7a851 100644
--- a/spec/gitlab_projects_spec.rb
+++ b/spec/gitlab_projects_spec.rb
@@ -450,16 +450,19 @@ describe GitlabProjects do
context 'success import' do
let(:gl_projects) { build_gitlab_projects('import-project', tmp_repos_path, repo_name, 'https://github.com/randx/six.git') }
- it { gl_projects.exec.should be_true }
+ it { expect(gl_projects.exec).to be true }
- it "should import a repo" do
+ it "imports a repo" do
gl_projects.exec
- File.exists?(File.join(tmp_repo_path, 'HEAD')).should be_true
+
+ expect(File.exists?(File.join(tmp_repo_path, 'HEAD'))).to be true
end
- it "should log an import-project event" do
+ it "logs an import-project event" do
message = "Importing project #{repo_name} from <https://github.com/randx/six.git> to <#{tmp_repo_path}>."
- $logger.should_receive(:info).with(message)
+
+ expect($logger).to receive(:info).with(message)
+
gl_projects.exec
end
end
@@ -467,28 +470,39 @@ describe GitlabProjects do
context 'already exists' do
let(:gl_projects) { build_gitlab_projects('import-project', tmp_repos_path, repo_name, 'https://github.com/randx/six.git') }
- it 'should import only once' do
- gl_projects.exec.should be_true
- gl_projects.exec.should be_false
+ it 'imports only once' do
+ expect(gl_projects.exec).to be true
+ expect(gl_projects.exec).to be false
end
end
context 'timeout' do
let(:gl_projects) { build_gitlab_projects('import-project', tmp_repos_path, repo_name, 'https://github.com/gitlabhq/gitlabhq.git', '1') }
- it { gl_projects.exec.should be_false }
+ it { expect(gl_projects.exec).to be false }
- it "should not import a repo" do
+ it "does not import a repo" do
gl_projects.exec
- File.exists?(File.join(tmp_repo_path, 'HEAD')).should be_false
+
+ expect(File.exists?(File.join(tmp_repo_path, 'HEAD'))).to be false
end
- it "should log an import-project event" do
+ it "logs an import-project event" do
message = "Importing project #{repo_name} from <https://github.com/gitlabhq/gitlabhq.git> failed due to timeout."
- $logger.should_receive(:error).with(message)
+
+ expect($logger).to receive(:error).with(message)
+
gl_projects.exec
end
end
+
+ context 'single-branch' do
+ let(:gl_projects) { build_gitlab_projects('import-project', tmp_repos_path, repo_name, 'https://github.com/randx/six.git', '--single-branch') }
+
+ it "imports repo" do
+ expect(gl_projects.exec).to be true
+ end
+ end
end
describe :fork_project do