Handling edge cases

Covers only edge cases related to tracking, not yet
handling linking or updating. Getting a bit hairy,
must be refactored.
This commit is contained in:
Eric West
2013-05-24 16:24:42 -05:00
parent b93eea0e24
commit 6867ef78dc
2 changed files with 46 additions and 1 deletions

View File

@@ -123,7 +123,38 @@ class Homesick < Thor
FileUtils.mkdir_p castle_path
end
mv absolute_path, castle_path
# Are we already tracking this or anything inside it?
target = Pathname.new(castle_path.join(file.basename))
if target.exist?
if absolute_path.directory?
child_files = absolute_path.children
child_files.each do |child|
if target.join(child.basename).exist?
next
end
mv child, target
end
absolute_path.rmtree
manifest = Pathname.new(repos_dir.join(castle, '.manifest'))
if manifest.exist?
lines = IO.readlines(manifest).delete_if { |line| line == "#{relative_dir + file.basename}\n" }
File.open(manifest, 'w') { |manfile| manfile.puts lines }
end
elsif absolute_path.mtime > target.mtime && !absolute_path.symlink?
target.delete
mv absolute_path, castle_path
else
shell.say_status(:track, "#{target} already exists, and is more recent than #{file}. Run 'homesick SYMLINK CASTLE' to create symlinks.")
end
else
mv absolute_path, castle_path
end
inside home_dir do
absolute_path = castle_path + file.basename

View File

@@ -219,6 +219,20 @@ describe "homesick" do
f.readlines.size.should == 1
end
end
it 'should remove the parent of a tracked file from the manifest if the parent itself is tracked' do
castle = given_castle('castle_repo')
some_nested_file = home.file('some/nested/file.txt')
nested_parent = home.directory('some/nested/')
homesick.track(some_nested_file.to_s, 'castle_repo')
homesick.track(nested_parent.to_s, 'castle_repo')
manifest = Pathname.new(castle.parent.join('.manifest'))
File.open(manifest, 'r') do |f|
f.each_line { |line| line.should_not == "some/nested\n" }
end
end
end
end
end