Skip to content

Commit

Permalink
Make Dependabot tolerate new "ref not found" error message from Cargo…
Browse files Browse the repository at this point in the history
… 1.80+ (#10719)

* Handle new error message from Cargo 1.80+ when fetching nonexistent git ref.

* Separate out the diff.
  • Loading branch information
RobJellinghaus authored Oct 4, 2024
1 parent 0545963 commit 9e5838b
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 `(?<url>[^`]*)`.*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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9e5838b

Please sign in to comment.