Track makes entries in .manifest

When a user tracks a file or directory that is in
a nested folder, Homesick creates a .manifest in the
user's castle (if there isn't one already) and adds
an entry listing the file or directory's parent
directory (if it isn't already listed).
This commit is contained in:
Eric West
2013-05-24 07:52:54 -05:00
parent 7332aa4acd
commit b93eea0e24
2 changed files with 38 additions and 0 deletions

View File

@@ -134,6 +134,15 @@ class Homesick < Thor
inside castle_path do inside castle_path do
git_add absolute_path git_add absolute_path
end 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 end
desc "list", "List cloned castles" desc "list", "List cloned castles"

View File

@@ -191,5 +191,34 @@ describe "homesick" do
tracked_file.should exist tracked_file.should exist
File.realdirpath(some_nested_dir).should == File.realdirpath(tracked_file) File.realdirpath(some_nested_dir).should == File.realdirpath(tracked_file)
end 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
end end