From e159f8c3f70a569f027e02f9f6f1c15d496d90b2 Mon Sep 17 00:00:00 2001 From: tyamagu2 Date: Wed, 13 Jul 2016 19:02:53 +0900 Subject: [PATCH] Add depth attribute to git resource --- lib/itamae/resource/git.rb | 2 ++ spec/integration/default_spec.rb | 4 ++++ spec/integration/recipes/default.rb | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/lib/itamae/resource/git.rb b/lib/itamae/resource/git.rb index 60c86c1e..928a051e 100644 --- a/lib/itamae/resource/git.rb +++ b/lib/itamae/resource/git.rb @@ -10,6 +10,7 @@ class Git < Base define_attribute :repository, type: String, required: true define_attribute :revision, type: String define_attribute :recursive, type: [TrueClass, FalseClass], default: false + define_attribute :depth, type: Integer def pre_action case @current_action @@ -30,6 +31,7 @@ def action_sync(options) if check_empty_dir cmd = ['git', 'clone'] cmd << '--recursive' if attributes.recursive + cmd += ['--depth', attributes.depth.to_s] if attributes.depth cmd << attributes.repository << attributes.destination run_command(cmd) new_repository = true diff --git a/spec/integration/default_spec.rb b/spec/integration/default_spec.rb index c2c94330..0631e4c7 100644 --- a/spec/integration/default_spec.rb +++ b/spec/integration/default_spec.rb @@ -149,6 +149,10 @@ its(:stdout) { should match(/Empty Repo/) } end +describe command('cd /tmp/git_repo_depth_1 && git rev-list --count HEAD') do + its(:stdout) { should eq "1\n" } +end + describe file('/tmp/created_by_itamae_user') do it { should be_file } it { should be_owned_by 'itamae' } diff --git a/spec/integration/recipes/default.rb b/spec/integration/recipes/default.rb index 555ccaf3..2fbcd295 100644 --- a/spec/integration/recipes/default.rb +++ b/spec/integration/recipes/default.rb @@ -284,6 +284,11 @@ recursive true end +git "/tmp/git_repo_depth_1" do + repository "https://github.com/ryotarai/infrataster.git" + depth 1 +end + ##### execute "echo -n \"$HOME\n$(pwd)\" > /tmp/created_by_itamae_user" do