[5.3] Improve the diagnostics that are emitted when a package dependency specifies a non-existent branch or commit #2950
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a 5.3 nomination of a fix that is already in the main branch. The code is not exactly the same as the one in the main branch, since that made use of previous main-branch changes. It has also been trimmed down to reduce risk. So I'd like to ask for thorough code review on this one.
This improves the handling of errors thrown by Git, and is quite safe because it does not affect the successful code path. If the Git invocation fails, it checks for the common case of a missing branch name or commit hash, and if so, customizes the error message.
As a bonus, adds a specific check to provide a suggestion to use
main
if amaster
branch is requested but doesn't exist but ifmain
does exist.Instead of seeing:
we now see:
with the suggestion at the end only appearing if
main
exists andmaster
doesn’t.This is being nominated for SwiftPM 5.3.x since the
master
->main
renaming is happening in the Swift repositories right now, and people are particularly likely to run into this issue in the next few months.Note that tags go through different processing, since they are the inputs to the semantic versioning and missing tags are reported differently. There is no way in SwiftPM to define an explicit dependency on a non-semver tag, which is why this code only needs to handle branches and commits.
The error message does not list all the branches, since there can be many, but that could be another future improvement (or at least to list all the branches whose names are similar to what was requested).
The original PR was #2925
rdar://69413377