Add --all option to pull to update all castles
Abstracted the logic for doing some operation for all castles into Homesick.inside_each_castle() which takes a block argument. Homesick.list() is also reimplemented to use this new method, because that's where the logic was stolen from. The actual updating is also moved to the private method update_castle() to make pull() shorter.
This commit is contained in:
@@ -60,14 +60,16 @@ class Homesick < Thor
|
|||||||
end
|
end
|
||||||
|
|
||||||
desc "pull NAME", "Update the specified castle"
|
desc "pull NAME", "Update the specified castle"
|
||||||
def pull(name)
|
method_option :all, :type => :boolean, :default => false, :required => false, :desc => "Update all cloned castles"
|
||||||
check_castle_existance(name, "pull")
|
def pull(name="")
|
||||||
|
if options[:all]
|
||||||
inside repos_dir.join(name) do
|
inside_each_castle do |castle|
|
||||||
git_pull
|
update_castle castle
|
||||||
git_submodule_init
|
|
||||||
git_submodule_update
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
update_castle name
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "symlink NAME", "Symlinks all dotfiles from the specified castle"
|
desc "symlink NAME", "Symlinks all dotfiles from the specified castle"
|
||||||
@@ -107,13 +109,10 @@ class Homesick < Thor
|
|||||||
|
|
||||||
desc "list", "List cloned castles"
|
desc "list", "List cloned castles"
|
||||||
def list
|
def list
|
||||||
Pathname.glob("#{repos_dir}/**/*/.git") do |git_dir|
|
inside_each_castle do |castle|
|
||||||
castle = git_dir.dirname
|
|
||||||
Dir.chdir castle do # so we can call git config from the right contxt
|
|
||||||
say_status castle.relative_path_from(repos_dir), `git config remote.origin.url`.chomp, :cyan
|
say_status castle.relative_path_from(repos_dir), `git config remote.origin.url`.chomp, :cyan
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
desc "generate PATH", "generate a homesick-ready git repo at PATH"
|
desc "generate PATH", "generate a homesick-ready git repo at PATH"
|
||||||
def generate(castle)
|
def generate(castle)
|
||||||
@@ -158,4 +157,21 @@ class Homesick < Thor
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def inside_each_castle(&block)
|
||||||
|
Pathname.glob("#{repos_dir}/**/*/.git") do |git_dir|
|
||||||
|
castle = git_dir.dirname
|
||||||
|
Dir.chdir castle do # so we can call git config from the right contxt
|
||||||
|
yield castle
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_castle(castle)
|
||||||
|
check_castle_existance(castle, "pull")
|
||||||
|
inside repos_dir.join(castle) do
|
||||||
|
git_pull
|
||||||
|
git_submodule_init
|
||||||
|
git_submodule_update
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user