Skip to content

Conversation

Xiphoseer
Copy link
Contributor

I was seeing an error like the following in my rust-analyzer output.

error: failed to load source for dependency `fontdue`

Caused by:
  Unable to update https://github.com/xiphseer/fontdue.git?rev=67b963af0d5ca9e09bfeb0b5a9adf85c302d0a67

Caused by:
  failed to fetch into: /home/daniel/.local/share/cargo/git/db/fontdue-4d0b06b88bb2e092

Caused by:
  revision 67b963af0d5ca9e09bfeb0b5a9adf85c302d0a67 not found

Caused by:
  failed to authenticate when downloading repository

  * attempted to find username/password via git's `credential.helper` support, but failed

  if the git CLI succeeds then `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  failed to acquire username/password from local configuration

I spent about 10 minutes reading the docs on git authentication, before realizing I had just typo'ed my own GitHub username. This PR adds a note to the reference that explicitly mentions wrong (not malformed) URLs as a cause of authentication errors.

It's not directly on the linked https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli mainly because Git Authentication is already linked there, so it may catch more people and that's meant as the more detailed explanation anyway.

@rustbot
Copy link
Collaborator

rustbot commented Mar 12, 2025

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-documenting-cargo-itself Area: Cargo's documentation S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 12, 2025
Comment on lines +13 to +15
> **Note:** Cargo does not require authentication for public git dependencies
> so if you see an authentication failure in that context, ensure that the
> URL is correct.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request!

I think the problem is more like libgit2 doesn't provide a prompt and ask for credentials. Cargo may still require credentials if a Git repo is specified with SSH protocol. The sentences here are great but a bit imprecise. Not sure how to rephrase it. Maybe something like this?

Suggested change
> **Note:** Cargo does not require authentication for public git dependencies
> so if you see an authentication failure in that context, ensure that the
> URL is correct.
> **Note:** Cargo does not provide a prompt for Git authentication.
> If you see an authentication failure, first ensure that the URL is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I feel like that leaves out the specific case I was thinking about, which is an intentionally public repo not needing authentication and thus not benefiting from a prompt. I usually use SSH, but intentionally put a git = 'https://github.com/xiphoseer/fontdue.git' URL there for it to work in CI without extra steps.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yeah my suggestion did lose the most important point of your patch. This note doesn't need to be 100% perfect reflecting every technical detail.

Thanks for the help. Going to merge this now!

@weihanglo weihanglo added this pull request to the merge queue Mar 15, 2025
Merged via the queue into rust-lang:master with commit 3e96f1a Mar 15, 2025
21 checks passed
@Xiphoseer Xiphoseer deleted the patch-1 branch March 15, 2025 06:03
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 22, 2025
Update cargo

14 commits in 6cf8267012570f63d6b86e85a2ae5627de52df9e..307cbfda3119f06600e43cd38283f4a746fe1f8b
2025-03-14 15:25:36 +0000 to 2025-03-20 20:00:39 +0000
- feat: Add custom completer for cargo <TAB> to complete aliases defined in config.toml (rust-lang/cargo#15319)
- fix(build-dir): Renamed workspace-manifest-path-hash to workspace-path-hash (rust-lang/cargo#15334)
- feat: vcs, color, and message format native completion (rust-lang/cargo#15322)
- Fix `[env]` `relative` description in reference (rust-lang/cargo#15332)
- chore: fix some typos (rust-lang/cargo#15329)
- Cleanup for rustc-link-arg-cdylib (rust-lang/cargo#15326)
- fix(toml): Report '<target>.edition' deprecation to users (rust-lang/cargo#15321)
- test(build-std): address overly-matched snapshot (rust-lang/cargo#15325)
- Added `build.build_dir` templating support (rust-lang/cargo#15236)
- docs: make it clearer that `rust_version` is enforced during compile (rust-lang/cargo#15303)
- feat: Add custom completer for cargo +<TAB> to complete toolchain name (rust-lang/cargo#15301)
- chore: fix some typos (rust-lang/cargo#15316)
- fix: deduplicate crate types in cargo rustc command (rust-lang/cargo#15314)
- docs: mention wrong URLs as a cause of git authentication errors (rust-lang/cargo#15304)

r? ghost
@rustbot rustbot added this to the 1.87.0 milestone Mar 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documenting-cargo-itself Area: Cargo's documentation S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants