rakelib/workflow.rake
changeset 127 664296ccdb4a
parent 116 2512c874e5e1
child 138 2507036dfee8
--- a/rakelib/workflow.rake	Tue Mar 21 13:00:49 2017 +0000
+++ b/rakelib/workflow.rake	Thu May 25 22:33:44 2017 +0100
@@ -17,7 +17,8 @@
     end    
   end
   
-  def push(remote, user, pass, review_only, push_bookmark)  
+  def push(remote, user, pass, review_only, push_bookmark)
+    has_changes = false;
     hg_repositories do | pkg, hg |
       opts = {
         :user => user,
@@ -43,24 +44,33 @@
       # mainly beacuse there are on separate protected repositories 
       # not accessible without a special setup. Sigh...
       if ((pkg.name == 'stx:stc') or (pkg.name == 'stx:librun')) and ((remote_used == 'upstream') or (remote_used == 'canonical')) then        
-        puts ""
-        puts "== Skipping push of #{pkg.name} - you must push manually =="
-        puts ""                  
+        if not review_only then
+          puts ""
+          puts "== Skipping push of #{pkg.name} - you must push manually =="
+          puts ""                  
+        end
       else      
         if review_only then
           opts[:rev] = '.'
           remote_url = hg.paths[remote_used] || remote_used
           bookmark = hg.bookmark()
-          puts ""
-          puts "== changes going to #{remote_url} =="
-          puts ""
-          hg.outgoing(remote_used, **opts)
-          puts ""
-          if push_bookmark and bookmark then
-            puts "Will update bookmark '#{bookmark}"
+          hg.outgoing(remote_used, **opts) do | status, stdout |
+            case status.exitstatus
+            when 0          
+              puts ""
+              puts "== changes going to #{remote_url} =="              
+              STDOUT.print stdout
+              if push_bookmark and bookmark then              
+                puts "Will update bookmark '#{bookmark}"
+              end
+              puts "===================================="
+              has_changes = true
+            when 1
+              # nothing
+            else        
+              raise Exception.new("Failed to do 'outgoing' from #{remote} (exit code #{status.exitstatus})")
+            end
           end
-          puts "===================================="
-          puts ""
         else
           if push_bookmark && bookmark then
             opts[:bookmarks] = ['.']
@@ -68,14 +78,22 @@
             opts[:rev] = '.'
           end        
           hg.push(remote_used, **opts)
+          has_changes = true
         end
       end
     end
+    return has_changes
   end
 
   desc "Display changes to be pushed to upstream repositores (use it to review what workflow:push-upstream would do)"
   task :'out-upstream', :user, :pass do | t, args |
-    push('upstream', args[:user], args[:pass], true, false)
+    RakeFileUtils.verbose(false) do
+      has_changes = push('upstream', args[:user], args[:pass], true, false)
+      if not has_changes then
+        puts "No changes to be pushed to upstream repositories"
+      end      
+      exit(has_changes ? 0 : 1 )
+    end
   end
   task :'out-upstream' => :'setup'
 
@@ -88,7 +106,13 @@
 
   desc "Display changes to be pushed to staging repositores (use it to review what workflow:push-staging would do)"
   task :'out-staging', :user, :pass do | t, args |
-    push('staging', args[:user], args[:pass], true, true)
+    RakeFileUtils.verbose(false) do
+      has_changes = push('staging', args[:user], args[:pass], true, true)
+      if not has_changes then
+        puts "No changes to be pushed to staging repositories"
+      end
+      exit(has_changes ? 0 : 1 )
+    end
   end
   task :'out-staging' => :'setup'