First pass at castle generator task.

This commit is contained in:
Joshua Nichols
2010-04-08 01:05:34 -04:00
parent e1901b3a83
commit c9399064e0
2 changed files with 46 additions and 0 deletions

View File

@@ -75,6 +75,27 @@ class Homesick < Thor
end
end
desc "generate PATH", "generate a homesick-ready git repo at PATH"
def generate(castle)
castle = Pathname.new(castle).expand_path
github_user = `git config github.user`.chomp
github_user = nil if github_user == ""
github_repo = castle.basename
empty_directory castle
inside castle do
git_init
if github_user
url = "git@github.com:#{github_user}/#{github_repo}.git"
git_remote_add 'origin', url
end
empty_directory "home"
end
end
protected
def home_dir

View File

@@ -19,6 +19,31 @@ class Homesick
end
end
def git_init(path = ".")
path = Pathname.new(path)
inside path do
unless path.join('.git').exist?
say_status 'git init', '' unless options[:quiet]
system "git init >/dev/null" unless options[:pretend]
else
say_status 'git init', 'already initialized', :blue unless options[:quiet]
end
end
end
def git_remote_add(name, url)
existing_remote = `git config remote.#{name}.url`.chomp
existing_remote = nil if existing_remote == ''
unless existing_remote
say_status 'git remote', "add #{name} #{url}" unless options[:quiet]
system "git remote add #{name} #{url}" unless options[:pretend]
else
say_status 'git remote', "#{name} already exists", :blue unless options[:quiet]
end
end
def git_submodule_init(config = {})
say_status 'git submodule', 'init', :green unless options[:quiet]
system "git submodule --quiet init" unless options[:pretend]