replace .manifest to .homesick_subdir

This commit is contained in:
muratayusuke
2013-05-27 18:08:09 +00:00
parent 2d54086d89
commit 3559d825ca
2 changed files with 28 additions and 31 deletions

View File

@@ -98,10 +98,10 @@ class Homesick < Thor
inside castle_dir(name) do inside castle_dir(name) do
# prepare subdir information # prepare subdir information
subdir_file = Pathname.new(".").join(SUBDIR_FILENAME) subdir_filepath = subdir_file(name)
subdirs = [] subdirs = []
if subdir_file.exist? then if subdir_filepath.exist? then
subdir_file.readlines.each do |subdir| subdir_filepath.readlines.each do |subdir|
subdirs.push(subdir.chomp) subdirs.push(subdir.chomp)
end end
end end
@@ -154,10 +154,7 @@ class Homesick < Thor
absolute_path = file.expand_path absolute_path = file.expand_path
relative_dir = absolute_path.relative_path_from(home_dir).dirname relative_dir = absolute_path.relative_path_from(home_dir).dirname
castle_path = Pathname.new(castle_dir(castle)).join(relative_dir) castle_path = Pathname.new(castle_dir(castle)).join(relative_dir)
FileUtils.mkdir_p castle_path
unless castle_path.exist?
FileUtils.mkdir_p castle_path
end
# Are we already tracking this or anything inside it? # Are we already tracking this or anything inside it?
target = Pathname.new(castle_path.join(file.basename)) target = Pathname.new(castle_path.join(file.basename))
@@ -165,7 +162,7 @@ class Homesick < Thor
if absolute_path.directory? if absolute_path.directory?
move_dir_contents(target, absolute_path) move_dir_contents(target, absolute_path)
absolute_path.rmtree absolute_path.rmtree
manifest_remove(castle, relative_dir + file.basename) subdir_remove(castle, relative_dir + file.basename)
elsif more_recent? absolute_path, target elsif more_recent? absolute_path, target
target.delete target.delete
@@ -189,7 +186,7 @@ class Homesick < Thor
# are we tracking something nested? Add the parent dir to the manifest # are we tracking something nested? Add the parent dir to the manifest
unless relative_dir.eql?(Pathname.new('.')) unless relative_dir.eql?(Pathname.new('.'))
manifest_add(castle, relative_dir) subdir_add(castle, relative_dir)
end end
end end
@@ -283,30 +280,30 @@ class Homesick < Thor
end end
end end
def manifest(castle) def subdir_file(castle)
Pathname.new(repos_dir.join(castle, '.manifest')) castle_dir(castle).join(SUBDIR_FILENAME)
end end
def manifest_add(castle, path) def subdir_add(castle, path)
manifest_path = manifest(castle) subdir_filepath = subdir_file(castle)
File.open(manifest_path, 'a+') do |manifest| File.open(subdir_filepath, 'a+') do |subdir|
manifest.puts path unless manifest.readlines.inject(false) { |memo, line| line.eql?("#{path.to_s}\n") || memo } subdir.puts path unless subdir.readlines.inject(false) { |memo, line| line.eql?("#{path.to_s}\n") || memo }
end end
inside castle_dir(castle) do inside castle_dir(castle) do
git_add manifest_path git_add subdir_filepath
end end
end end
def manifest_remove(castle, path) def subdir_remove(castle, path)
manifest_file = manifest(castle) subdir_filepath = subdir_file(castle)
if manifest_file.exist? if subdir_filepath.exist?
lines = IO.readlines(manifest_file).delete_if { |line| line == "#{path}\n" } lines = IO.readlines(subdir_filepath).delete_if { |line| line == "#{path}\n" }
File.open(manifest_file, 'w') { |manfile| manfile.puts lines } File.open(subdir_filepath, 'w') { |manfile| manfile.puts lines }
end end
inside castle_dir(castle) do inside castle_dir(castle) do
git_add manifest_file git_add subdir_filepath
end end
end end

View File

@@ -220,16 +220,16 @@ describe "homesick" do
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 describe "subdir_file" do
it 'should add the nested files parent to the manifest' do it 'should add the nested files parent to the subdir_file' do
castle = given_castle('castle_repo') castle = given_castle('castle_repo')
some_nested_file = home.file('some/nested/file.txt') some_nested_file = home.file('some/nested/file.txt')
homesick.track(some_nested_file.to_s, 'castle_repo') homesick.track(some_nested_file.to_s, 'castle_repo')
manifest = Pathname.new(castle.parent.join('.manifest')) subdir_file = castle.join(Homesick::SUBDIR_FILENAME)
File.open(manifest, 'r') do |f| File.open(subdir_file, 'r') do |f|
f.readline.should == "some/nested\n" f.readline.should == "some/nested\n"
end end
end end
@@ -242,13 +242,13 @@ describe "homesick" do
homesick.track(some_nested_file.to_s, 'castle_repo') homesick.track(some_nested_file.to_s, 'castle_repo')
homesick.track(other_nested_file.to_s, 'castle_repo') homesick.track(other_nested_file.to_s, 'castle_repo')
manifest = Pathname.new(castle.parent.join('.manifest')) subdir_file = castle.join(Homesick::SUBDIR_FILENAME)
File.open(manifest, 'r') do |f| File.open(subdir_file, 'r') do |f|
f.readlines.size.should == 1 f.readlines.size.should == 1
end end
end end
it 'should remove the parent of a tracked file from the manifest if the parent itself is tracked' do it 'should remove the parent of a tracked file from the subdir_file if the parent itself is tracked' do
castle = given_castle('castle_repo') castle = given_castle('castle_repo')
some_nested_file = home.file('some/nested/file.txt') some_nested_file = home.file('some/nested/file.txt')
@@ -256,8 +256,8 @@ describe "homesick" do
homesick.track(some_nested_file.to_s, 'castle_repo') homesick.track(some_nested_file.to_s, 'castle_repo')
homesick.track(nested_parent.to_s, 'castle_repo') homesick.track(nested_parent.to_s, 'castle_repo')
manifest = Pathname.new(castle.parent.join('.manifest')) subdir_file = castle.join(Homesick::SUBDIR_FILENAME)
File.open(manifest, 'r') do |f| File.open(subdir_file, 'r') do |f|
f.each_line { |line| line.should_not == "some/nested\n" } f.each_line { |line| line.should_not == "some/nested\n" }
end end
end end