From c9399064e059f1814c04ce96ae6539971ac28a96 Mon Sep 17 00:00:00 2001 From: Joshua Nichols Date: Thu, 8 Apr 2010 01:05:34 -0400 Subject: [PATCH] First pass at castle generator task. --- lib/homesick.rb | 21 +++++++++++++++++++++ lib/homesick/actions.rb | 25 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/lib/homesick.rb b/lib/homesick.rb index fb82908..034c1e0 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -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 diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index e92e688..f815714 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -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]