replace .manifest to .homesick_subdir

This commit is contained in:
muratayusuke
2013-05-27 18:08:09 +00:00
committed by thilko
parent bba0e3ed7d
commit 01934d5b00
2 changed files with 28 additions and 31 deletions

View File

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

View File

@@ -221,16 +221,16 @@ describe "homesick" do
File.realdirpath(some_nested_dir).should == File.realdirpath(tracked_file)
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')
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|
subdir_file = castle.join(Homesick::SUBDIR_FILENAME)
File.open(subdir_file, 'r') do |f|
f.readline.should == "some/nested\n"
end
end
@@ -243,13 +243,13 @@ describe "homesick" do
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|
subdir_file = castle.join(Homesick::SUBDIR_FILENAME)
File.open(subdir_file, 'r') do |f|
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
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')
some_nested_file = home.file('some/nested/file.txt')
@@ -257,8 +257,8 @@ describe "homesick" do
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|
subdir_file = castle.join(Homesick::SUBDIR_FILENAME)
File.open(subdir_file, 'r') do |f|
f.each_line { |line| line.should_not == "some/nested\n" }
end
end