From 9e5838bfffb88babbc9ca391f1663ba170eaae12 Mon Sep 17 00:00:00 2001 From: Rob Jellinghaus Date: Fri, 4 Oct 2024 10:20:51 -0700 Subject: [PATCH] Make Dependabot tolerate new "ref not found" error message from Cargo 1.80+ (#10719) * Handle new error message from Cargo 1.80+ when fetching nonexistent git ref. * Separate out the diff. --- .../dependabot/cargo/update_checker/version_resolver.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cargo/lib/dependabot/cargo/update_checker/version_resolver.rb b/cargo/lib/dependabot/cargo/update_checker/version_resolver.rb index f30d12ae507..5f224313824 100644 --- a/cargo/lib/dependabot/cargo/update_checker/version_resolver.rb +++ b/cargo/lib/dependabot/cargo/update_checker/version_resolver.rb @@ -20,6 +20,12 @@ class VersionResolver REF_NOT_FOUND_REGEX = /#{UNABLE_TO_UPDATE}.*(#{REVSPEC_PATTERN}|#{OBJECT_PATTERN})/m GIT_REF_NOT_FOUND_REGEX = /Updating git repository `(?[^`]*)`.*fatal: couldn't find remote ref/m + # Note that as of Rust 1.80, git error message handling in the `cargo update` command changed. + # This change causes the NOT_OUR_REF error to appear *before* the UNABLE_TO_UPDATE error. + # Issue filed in Cargo project: https://github.com/rust-lang/cargo/issues/14621 + NOT_OUR_REF = /fatal: remote error: upload-pack: not our ref/ + NOT_OUR_REF_REGEX = /#{NOT_OUR_REF}.*#{UNABLE_TO_UPDATE}/m + def initialize(dependency:, credentials:, original_dependency_files:, prepared_dependency_files:) @dependency = dependency @@ -223,7 +229,7 @@ def handle_cargo_errors(error) raise Dependabot::GitDependenciesNotReachable, urls end - [BRANCH_NOT_FOUND_REGEX, REF_NOT_FOUND_REGEX, GIT_REF_NOT_FOUND_REGEX].each do |regex| + [BRANCH_NOT_FOUND_REGEX, REF_NOT_FOUND_REGEX, GIT_REF_NOT_FOUND_REGEX, NOT_OUR_REF_REGEX].each do |regex| next unless error.message.match?(regex) dependency_url = error.message.match(regex).named_captures.fetch("url").split(/[#?]/).first