Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Merge branch 'subdir-cookbooks-git'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsdeleo committed Nov 6, 2014
2 parents 667d69b + c3a921a commit 2f14643
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/chef-dk/policyfile/cookbook_locks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,15 @@ def initialize(name, storage_config)

@identifier_updated = false
@version_updated = false
@cookbook_in_git_repo = nil
end

def cookbook_path
File.expand_path(source, relative_paths_root)
end

def scm_profiler
if File.exist?(File.join(cookbook_path, ".git"))
if cookbook_in_git_repo?
CookbookProfiler::Git.new(cookbook_path)
else
CookbookProfiler::NullSCM.new(cookbook_path)
Expand Down Expand Up @@ -373,6 +374,23 @@ def assert_required_keys_valid!(lock_data)
end
end

def cookbook_in_git_repo?
return @cookbook_in_git_repo unless @cookbook_in_git_repo.nil?

@cookbook_in_git_repo = false

dot_git = Pathname.new(".git")
Pathname.new(cookbook_path).ascend do |parent_dir|
possbile_git_dir = parent_dir + dot_git
if possbile_git_dir.exist?
@cookbook_in_git_repo = true
break
end
end

@cookbook_in_git_repo
end

end
end
end
58 changes: 58 additions & 0 deletions spec/unit/policyfile/cookbook_locks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,64 @@

end

describe "selecting an SCM profiler" do

let(:cookbook_source_relpath) { "nginx" }

let(:cookbook_source_path) do
path = File.join(tempdir, cookbook_source_relpath)
FileUtils.mkdir_p(path)
path
end

before do
cookbook_lock.source = cookbook_source_path
end

after do
clear_tempdir
end

context "when the cookbook is in a git-repo" do

before do
FileUtils.mkdir_p(git_dir_path)
end

context "when the cookbook is a self-contained git repo" do

let(:git_dir_path) { File.join(cookbook_source_path, ".git") }

it "selects the git profiler" do
expect(cookbook_lock.scm_profiler).to be_an_instance_of(ChefDK::CookbookProfiler::Git)
end

end

context "when the cookbook is a subdirectory of a git repo" do

let(:cookbook_source_relpath) { "cookbook_repo/nginx" }

let(:git_dir_path) { File.join(tempdir, "cookbook_repo/.git") }

it "selects the git profiler" do
expect(cookbook_lock.scm_profiler).to be_an_instance_of(ChefDK::CookbookProfiler::Git)
end

end

end

context "when the cookbook is not in a git repo" do

it "selects the null profiler" do
expect(cookbook_lock.scm_profiler).to be_an_instance_of(ChefDK::CookbookProfiler::NullSCM)
end

end

end

context "when loading data from a serialized form" do

let(:previous_lock_data) do
Expand Down

0 comments on commit 2f14643

Please sign in to comment.