From 493553f9795e7c71d464e55ac4dc8ce317a17f3d Mon Sep 17 00:00:00 2001
From: Maxwell Salzberg <maxwell@joindiaspora.com>
Date: Thu, 19 Jan 2012 16:36:06 -0800
Subject: [PATCH] working on making heroku_san magical

---
 config/heroku.yml.example    |  2 ++
 lib/tasks/after_deploy.rake  |  2 +-
 lib/tasks/before_deploy.rake | 22 +++++++++++-----------
 3 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/config/heroku.yml.example b/config/heroku.yml.example
index 332ed764a7..f069a66684 100644
--- a/config/heroku.yml.example
+++ b/config/heroku.yml.example
@@ -7,9 +7,11 @@ production:
   config: 
     <<: *defaults
     BUNDLE_WITHOUT: "development:test"
+    HOME_FILE: 'app/views/home/_show.html.haml'
 staging:
   app: staging
   stack: cedar
   config: 
     <<: *defaults
     BUNDLE_WITHOUT: "development:test"
+    HOME_FILE: 'app/views/home/_show.html.haml'
diff --git a/lib/tasks/after_deploy.rake b/lib/tasks/after_deploy.rake
index cbed7d2aff..0f76cb1379 100644
--- a/lib/tasks/after_deploy.rake
+++ b/lib/tasks/after_deploy.rake
@@ -6,7 +6,7 @@ task :after_deploy => :environment do
     puts "-----> resetting HEAD before custom landing page commit"
 
     system("git reset --hard HEAD^") ? true : fail
-    system("git stash pop") ? true : fail
+    system("git stash pop") unless @did_not_stash
 
     puts "-----> done"
   end
diff --git a/lib/tasks/before_deploy.rake b/lib/tasks/before_deploy.rake
index 841c92224f..d899db86c1 100644
--- a/lib/tasks/before_deploy.rake
+++ b/lib/tasks/before_deploy.rake
@@ -1,20 +1,20 @@
 desc "include custom landing page before heroku san deploys"
 task :before_deploy => :environment do
 
-  # Perform this task only if custom landing page is not present in app/views/home/_show.html.haml
-  if File.exist?(File.join(Rails.root, "app", "views", "home", "_show.html.haml"))
-    puts "-----> custom landing page detected..."
+  each_heroku_app do |name, app, repo| 
+    home_file = @app_settings[name]['config']['HOME_FILE']
+    # Perform this task only if custom landing page is not present in app/views/home/_show.html.haml
+    if home_file.present?
+      puts "-----> custom landing page detected..."
 
-    puts "-----> including custom landing page in a temp commit"
+      puts "-----> including custom landing page in a temp commit"
 
+      @did_not_stash = system("git stash| grep 'No local changes to save'")      
+      system("git add #{home_file} -f") ? true : fail
+      system("git commit -m 'adding custom landing page for heroku'") ? true : fail
 
-    pp @app_settings
-
-    system("git stash") ? true : fail
-    system("git add app/views/home/_show.html.haml -f") ? true : fail
-    system("git commit -m 'adding custom landing page for heroku'") ? true : fail
-
-    puts "-----> done"
+      puts "-----> done"
+    end
   end
 
 end
-- 
GitLab