@@ -750,40 +750,52 @@ def parse_resource_versions_arg
750750 ) . returns ( Symbol )
751751 }
752752 def update_resource_block! ( formula , resource , new_version )
753- ohai "Updating resource \" #{ resource . name } \" from #{ resource . version } to #{ new_version } "
753+ old_version = resource . version . to_s
754+ ohai "Updating resource \" #{ resource . name } \" from #{ old_version } to #{ new_version } "
754755
755756 old_url = resource . url
756757 raise ArgumentError , "resource \" #{ resource . name } \" has no URL" if old_url . nil?
757758
758- if ( old_tag = resource . specs [ :tag ] . presence ) && resource . download_strategy <= GitDownloadStrategy
759- tag = update_url ( old_tag , resource . version . to_s , new_version )
760- if tag == old_tag
761- opoo <<~EOS
762- You need to bump resource "#{ resource . name } " manually since the new tag
763- and old tag are both:
764- #{ tag }
765- EOS
766- return :tag_unchanged
767- end
759+ if resource . download_strategy <= GitDownloadStrategy
760+ old_tag = resource . specs [ :tag ] . presence
761+ old_revision = resource . specs [ :revision ] . presence
762+
763+ if old_tag
764+ tag = update_url ( old_tag , old_version , new_version )
765+ if tag == old_tag
766+ opoo <<~EOS
767+ You need to bump resource "#{ resource . name } " manually since the new tag
768+ and old tag are both:
769+ #{ tag }
770+ EOS
771+ return :tag_unchanged
772+ end
768773
769- # `specs` omits `using:`, so pass it through to keep an explicit strategy
770- git_specs = { tag : }
771- if ( using = resource . using . presence )
772- git_specs [ :using ] = using
773- end
774- resource_path , forced_version = fetch_resource_and_forced_version ( resource , new_version , old_url ,
775- **git_specs )
776- new_revision = Utils . popen_read ( "git" , "-C" , resource_path . to_s , "rev-parse" , "-q" , "--verify" ,
777- "HEAD" ) . strip
778- if new_revision . blank?
779- opoo "Could not resolve a revision for resource \" #{ resource . name } \" tag #{ tag } ."
774+ # `specs` omits `using:`, so pass it through to keep an explicit strategy
775+ git_specs = { tag : }
776+ if ( using = resource . using . presence )
777+ git_specs [ :using ] = using
778+ end
779+ resource_path , forced_version = fetch_resource_and_forced_version ( resource , new_version , old_url ,
780+ **git_specs )
781+ new_revision = Utils . popen_read ( "git" , "-C" , resource_path . to_s , "rev-parse" , "-q" , "--verify" ,
782+ "HEAD" ) . strip
783+ if new_revision . blank?
784+ opoo "Could not resolve a revision for resource \" #{ resource . name } \" tag #{ tag } ."
785+ return :revision_unresolved
786+ end
787+ elsif old_revision == old_version
788+ new_revision = new_version
789+ forced_version = true
790+ else
791+ opoo "Could not resolve a revision for resource \" #{ resource . name } \" version #{ new_version } ."
780792 return :revision_unresolved
781793 end
782794
783795 resource_name = resource . name . to_s
784796 formula_ast = Utils ::AST ::FormulaAST . new ( formula . path . read )
785- formula_ast . replace_resource_stanza_hash_value ( resource_name , :url , :tag , tag )
786- if resource . specs [ :revision ] . present?
797+ formula_ast . replace_resource_stanza_hash_value ( resource_name , :url , :tag , tag ) if tag
798+ if old_revision . present?
787799 formula_ast . replace_resource_stanza_hash_value ( resource_name , :url , :revision , new_revision )
788800 end
789801
0 commit comments