Skip to content

[5.3] Improve the diagnostics that are emitted when a package dependency specifies a non-existent branch or commit #2950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

abertelrud
Copy link
Contributor

@abertelrud abertelrud commented Sep 23, 2020

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 a master branch is requested but doesn't exist but if main does exist.

Instead of seeing:

git rev-parse --verify 'master^{commit}' output:
    fatal: Needed a single revision

we now see:

https://github.com/apple/swift-cluster-membership.git: error: could not find a branch named ‘master’ (did you mean ‘main’?)

with the suggestion at the end only appearing if main exists and master 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

@abertelrud
Copy link
Contributor Author

@swift-ci please test

@abertelrud
Copy link
Contributor Author

Investigating failure, marking as draft until I fix it.

@abertelrud abertelrud marked this pull request as draft September 23, 2020 21:06
…ncy specifies a non-existent branch or commit

This improves the handling of errors thrown by Git, and is quite safe because it does not affect the successful code path.  It checks for the common case of a missing branch name, and as a bonus, adds a specific check to provide a suggestion related to the `master` -> `main` renaming (if `master` is requested but doesn't exist, but if `main` does exist).

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.

A similar fix is already in the main branch (though the exact diff is not the same in order to keep the 5.3 patch minimal)

rdar://69413377
@abertelrud abertelrud force-pushed the eng/5.3-better-diagnostic-with-missing-branch branch from 0c8e9b6 to a3630fe Compare September 24, 2020 16:41
@abertelrud
Copy link
Contributor Author

@swift-ci please test

@abertelrud
Copy link
Contributor Author

I think the Linux build got stuck when the CI had problems. Restarting it.

@abertelrud
Copy link
Contributor Author

@swift-ci please test

@abertelrud
Copy link
Contributor Author

Test is not starting. I'll see what's going on (e.g. whether ci.swift.org is having issues).

@abertelrud
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@abertelrud
Copy link
Contributor Author

@swift-ci please test

@abertelrud abertelrud self-assigned this Sep 29, 2020
@abertelrud
Copy link
Contributor Author

We might be beyond the point at which we want to take this in 5.3 at this point.

@abertelrud abertelrud closed this Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant