-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
rev = "refs/pull/𑑛/head" #9859
rev = "refs/pull/𑑛/head" #9859
Conversation
r? @ehuss (rust-highfive has picked a reviewer for you, use r? to override) |
Thanks for this! I've long-wanted to support this in Cargo and I'm glad to see it getting done! Internally the main other alternative route to support this would probably be to add new syntax, something like That being said I personally think I still don't know enough about Additionally I think that the "github fast path" when we're updating a repository should be able to work with |
https://git-scm.com/book/en/v2/Git-Internals-Git-References covers the relevant background on refs. The mental model is: a reference is a name given to an object (oid). The name is close to arbitrary — it must not contain There are some naming conventions in place for references. A name that begins with Tools can come up with their own reference naming conventions beyond this. As mentioned, GitHub uses You can make your own refs using $ git update-ref refs/some/thing c22756541
$ cat .git/refs/some/thing
c22756541acb9e4cb428e9fbca53610edba1c501 Even $ git update-ref xyz/uiop c22756541
$ cat .git/xyz/uiop
c22756541acb9e4cb428e9fbca53610edba1c501
I don't think so. Outside of the 3 naming conventions above (branches, tags, remote branches) it's just a string name. Branches and tags are already covered in Cargo.toml, and remote branches don't make sense for Cargo.toml because you would never fetch a remote-tracking branch from a remote repository. So for refs outside of those 3 groups, we need to either let you specify the full name of the ref ( If we make Cargo take the arbitrary name of the reference, then even if all references in practice start with
That's fair. I guess I put it in cargo/src/cargo/core/source/source_id.rs Lines 120 to 124 in c227565
Alternatively,
Yep, judging by |
Thanks for all that info! That definitely at least helps clear some stuff up for me. It sounds like I'd be curious to hear from some other Cargo folks about |
Ok we talked about this in the Cargo team meeting and the conclusion was that Can you also update the documentation for git dependencies too? Basically just call out that |
|
Yeah you got it right. Basically what the user types is exactly the name of the ref on the remote, which is not an implementation detail of Cargo. |
@rfcbot fcp merge Looks good to me, thanks again! |
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Thanks! @bors r+ |
📌 Commit 86276d4 has been approved by |
☀️ Test successful - checks-actions |
Update cargo 6 commits in 18751dd3f238d94d384a7fe967abfac06cbfe0b9..e515c3277bf0681bfc79a9e763861bfe26bb05db 2021-09-01 14:26:00 +0000 to 2021-09-08 14:32:15 +0000 - Remove log output that may leak tokens (rust-lang/cargo#9873) - rev = "refs/pull/𑑛/head" (rust-lang/cargo#9859) - Update suggestion message on bad project name error (rust-lang/cargo#9877) - clarify what goes into "*-sys" crates (rust-lang/cargo#9871) - Improve error message when unable to initialize git index repo (rust-lang/cargo#9869) - Use serde_json to generate cargo_vcs_info.json (rust-lang/cargo#9865)
Update cargo 6 commits in 18751dd3f238d94d384a7fe967abfac06cbfe0b9..e515c3277bf0681bfc79a9e763861bfe26bb05db 2021-09-01 14:26:00 +0000 to 2021-09-08 14:32:15 +0000 - Remove log output that may leak tokens (rust-lang/cargo#9873) - rev = "refs/pull/𑑛/head" (rust-lang/cargo#9859) - Update suggestion message on bad project name error (rust-lang/cargo#9877) - clarify what goes into "*-sys" crates (rust-lang/cargo#9871) - Improve error message when unable to initialize git index repo (rust-lang/cargo#9869) - Use serde_json to generate cargo_vcs_info.json (rust-lang/cargo#9865)
GitHub exposes a named reference associated with the head of every pull request. For example, you can fetch this pull request:
Usually when I care about pulling in a patch of one of my dependencies using
[patch.crates-io]
, this is the ref that I want to depend on. None of the alternatives are good:{ git = "the fork", branch = "the-pr-branch" }
— this is second closest to what I want, except that when the PR merges and the PR author deletes their fork, it'll breaks.{ git = "the fork", rev = "commithash" }
— same failure mode as the previous. Also doesn't stay up to date with PR, which is sometimes what I want.{ git = "the upstream", rev = "commithash" }
— doesn't work until the PR is merged or the repo owner creates a named branch or tag containing the PR commit among its ancestors, because otherwise the commit doesn't participate in Cargo's fetch.{ git = "my own fork of PR author's repo", branch = "the-pr-branch" }
— doesn't stay up to date with PR.This PR adds support for specifying a git dependency on the head of a pull request via the existing
rev
setting of git dependencies:{ git = "the upstream", rev = "refs/pull/9859/head" }
.Previously this would fail because the
cargo::sources::git::fetch
function touched in this pull request did not fetch the refspec that we care about. The failures look like:If dual purposing
rev
for this is not appealing, I would alternatively propose{ git = "the upstream", pull-request = "9859" }
which Cargo will interpret using GitHub's ref naming convention asrefs/pull/9859/head
.