# HG changeset patch # User Jan Vrany # Date 1564048812 -3600 # Node ID 13ce86e80c300f531422b32582de017918aaedcf # Parent 19e6606943187d98a29ef5795fe1a91a4331c5c9 Rakefiles: raise (new) `HG::RepositoryNotFoundException` when remote repository is missing diff -r 19e660694318 -r 13ce86e80c30 rakelib/hglib.rb --- a/rakelib/hglib.rb Wed Jul 24 22:37:26 2019 +0100 +++ b/rakelib/hglib.rb Thu Jul 25 11:00:12 2019 +0100 @@ -38,6 +38,12 @@ module HG @@config = nil + class Exception < ::Exception + end + + class RepositoryNotFoundException < Exception + end + # Cross-platform way of finding an executable in the $PATH. # # which('ruby') #=> /usr/bin/ruby @@ -107,15 +113,23 @@ if block_given? stdout, stderr, status = Open3.capture3(*cmd) + # For command that deal with remotes, handle check whether the failure + # is because of missing remote repository. If so, raise exception. + if status.exitstatus == 255 + if stdout =~ /remote:\ *Repository.*not found/ or stderr =~ /abort:.*HTTP.*404/ + raise RepositoryNotFoundException.new("Remote repository not found!") + end + end + case block.arity when 1 STDOUT.print stdout if defined? RakeFileUtils and RakeFileUtils.verbose - STDERR.print stderr if defined? RakeFileUtils and RakeFileUtils.verbose + STDERR.print stderr if defined? RakeFileUtils and RakeFileUtils.verbose yield status - when 2 + when 2 STDERR.print stderr if defined? RakeFileUtils and RakeFileUtils.verbose yield status, stdout - when 3 + when 3 yield status, stdout, stderr else raise Exception.new("invalid arity of given block") @@ -300,7 +314,7 @@ raise Exception.new("Not a Mercurial repository (missing .hg directory): #{dir}") end @path = dir - initialize_config + initialize_config end def initialize_config @@ -436,7 +450,7 @@ end def pull1(remote = 'default', user: nil, pass: nil, rev: nil, bookmarks: nil) - hg('pull', remote, ssh: sshconf(remote), config: authconf(remote, user, pass), rev: rev, bookmark: bookmarks) do |status, stdout| + hg('pull', remote, ssh: sshconf(remote), config: authconf(remote, user, pass), rev: rev, bookmark: bookmarks) do |status, stdout, stderr | STDOUT.print stdout case status.exitstatus when 0 @@ -444,6 +458,7 @@ when 1 raise Exception.new("Failed to 'pull' from #{remote} (update had unresolved conflicts)") else + STDERR.print stderr raise Exception.new("Failed to 'pull' from #{remote} (exit code #{status.exitstatus})") end end @@ -459,6 +474,7 @@ when 1 puts "No new changes coming from #{remote}" else + STDERR.print stderr raise Exception.new("Failed to do 'incoming' from #{remote} (exit code #{status.exitstatus})") end end @@ -472,6 +488,8 @@ # again. See #shaky_remote?() begin pull1(remote, user: user, pass: pass, rev: rev, bookmarks: bookmarks) + rescue RepositoryNotFoundException => rnfe + raise rnfe rescue Exception delay = 30 + rand * 100 puts "Oops, remote is shaky, retrying after #{delay}" @@ -490,13 +508,15 @@ def outgoing(remote = 'default', user: nil, pass: nil, rev: nil, &block) if !block_given? - hg('outgoing', remote, ssh: sshconf(remote), config: authconf(remote, user, pass), rev: rev) do |status, stdout| + hg('outgoing', remote, ssh: sshconf(remote), config: authconf(remote, user, pass), rev: rev) do |status, stdout, stderr| + STDOUT.print stdout case status.exitstatus when 0 - STDOUT.print stdout + # notning when 1 puts "No new changes going to #{remote}" else + STDERR.print stderr raise Exception.new("Failed to do 'outgoing' from #{remote} (exit code #{status.exitstatus})") end end