Skip to content

Commit

Permalink
Merge pull request #219 from tyamagu2/git_depth
Browse files Browse the repository at this point in the history
Add depth attribute to git resource
  • Loading branch information
ryotarai authored Oct 27, 2016
2 parents bd91ea7 + e159f8c commit 0d54865
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/itamae/resource/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/integration/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,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' }
Expand Down
5 changes: 5 additions & 0 deletions spec/integration/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,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
Expand Down

0 comments on commit 0d54865

Please sign in to comment.