Merge pull request #557 from knu/heroku-reset-repo

Set up the work tree for user in bin/setup_heroku.

Akinori MUSHA 10 lat temu
rodzic
commit
f24b7dc910
1 zmienionych plików z 29 dodań i 2 usunięć
  1. 29 2
      bin/setup_heroku

+ 29 - 2
bin/setup_heroku

@@ -10,7 +10,11 @@ unless `which heroku` =~ /heroku/
10 10
 end
11 11
 
12 12
 def capture(cmd, opts = {})
13
-  o, s = Open3.capture2e(cmd, opts)
13
+  if opts.delete(:no_stderr)
14
+    o, s = Open3.capture2(cmd, opts)
15
+  else
16
+    o, s = Open3.capture2e(cmd, opts)
17
+  end
14 18
   o.strip
15 19
 end
16 20
 
@@ -33,7 +37,7 @@ def yes?(question)
33 37
 end
34 38
 
35 39
 def grab_heroku_config!
36
-  config_data = capture("heroku config -s")
40
+  config_data = capture("heroku config -s", no_stderr: true)
37 41
   $config = {}
38 42
   if config_data !~ /has no config vars/
39 43
     config_data.split("\n").map do |line|
@@ -80,6 +84,29 @@ unless yes?("Your Heroku app name is #{app_name}.  Is this correct?")
80 84
   exit 1
81 85
 end
82 86
 
87
+if (root_id = `git rev-list --max-parents=0 HEAD`.chomp) != '620acffa5a302c6a27165d3214cf3da6be6c1d0d'
88
+  if (`git remote`.split - %w[heroku]).empty?
89
+    puts "You don't seem to have cantino/huginn set up as upstream repository."
90
+    if yes?("Would you like me to set this work tree up for you?")
91
+      if system('git remote add origin https://github.com/cantino/huginn.git') &&
92
+         system('git remote update origin')
93
+        rebase_command = "git rebase #{root_id} --onto origin/master"
94
+        if system(rebase_command)
95
+          puts "Done!"
96
+        else
97
+          system('git rebase --abort')
98
+          puts "Rebasing your work tree onto the upstream master failed."
99
+          puts "Please run the following command and merge your local changes by yourself."
100
+          puts "\t#{rebase_command}"
101
+          exit 1
102
+        end
103
+      else
104
+        exit 1
105
+      end
106
+    end
107
+  end
108
+end
109
+
83 110
 grab_heroku_config!
84 111
 
85 112
 if $config.length > 0