diff --git a/lib/homesick.rb b/lib/homesick.rb index a61645e..9f5a63f 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -134,6 +134,15 @@ class Homesick < Thor inside castle_path do git_add absolute_path end + + # are we tracking something nested? Add the parent dir to the manifest unless its already listed + unless relative_dir.eql?(Pathname.new('.')) + manifest_path = Pathname.new(repos_dir.join(castle, '.manifest')) + File.open(manifest_path, 'a+') do |manifest| + manifest.puts relative_dir unless manifest.readlines.inject(false) { |memo, line| line.eql?("#{relative_dir.to_s}\n") || memo } + end + end + end desc "list", "List cloned castles" diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 9e34ed3..d769489 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -191,5 +191,34 @@ describe "homesick" do tracked_file.should exist File.realdirpath(some_nested_dir).should == File.realdirpath(tracked_file) end + + describe "manifest" do + + it 'should add the nested files parent to the manifest' do + castle = given_castle('castle_repo') + + some_nested_file = home.file('some/nested/file.txt') + homesick.track(some_nested_file.to_s, 'castle_repo') + + manifest = Pathname.new(castle.parent.join('.manifest')) + File.open(manifest, 'r') do |f| + f.readline.should == "some/nested\n" + end + end + + it 'should NOT add anything if the files parent is already listed' do + castle = given_castle('castle_repo') + + some_nested_file = home.file('some/nested/file.txt') + other_nested_file = home.file('some/nested/other.txt') + homesick.track(some_nested_file.to_s, 'castle_repo') + homesick.track(other_nested_file.to_s, 'castle_repo') + + manifest = Pathname.new(castle.parent.join('.manifest')) + File.open(manifest, 'r') do |f| + f.readlines.size.should == 1 + end + end + end end end