Skip to content
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

Attempting to run cargo new hello_cargo gives an error, not finding safe.directory #11365

Closed
bismurphy opened this issue Nov 12, 2022 · 2 comments · Fixed by #11366
Closed

Attempting to run cargo new hello_cargo gives an error, not finding safe.directory #11365

bismurphy opened this issue Nov 12, 2022 · 2 comments · Fixed by #11366
Assignees
Labels
A-git Area: anything dealing with git C-bug Category: bug regression-from-stable-to-stable Regression in stable that worked in a previous stable release.

Comments

@bismurphy
Copy link

bismurphy commented Nov 12, 2022

Problem

Hello,

I'm attempting to start using Rust for the first time. I was going through this guide:

https://doc.rust-lang.org/book/ch01-03-hello-cargo.html

I ran the basic Hello World, and now when it was time to start using Cargo, I went into my projects directory (which currently holds only the hello_world directory), and, as per the guide, ran cargo new hello_cargo. When I run this, I get the following error:

error: Failed to create package 'hello_cargo' at '/home/bismurphy/Projects/Rust/hello_cargo'

Caused by:
  config value 'safe.directory' was not found; class=Config (7); code=NotFound (-3)

After this occurs, the hello_cargo directory has been created, but is empty.

Steps

Unable to provide any reliable reproducing steps.

Possible Solution(s)

No response

Notes

I'm running a fairly fresh installation of Mint 21. I just installed it last week. I'm not using Docker or anything like that, and I just installed Rust with the procedure listed in the guide I linked above.

Version

cargo 1.65.0 (4bc8f24d3 2022-10-20)
release: 1.65.0
commit-hash: 4bc8f24d3e899462e43621aab981f6383a370365
commit-date: 2022-10-20
host: x86_64-unknown-linux-gnu
libgit2: 1.5.0 (sys:0.15.0 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1q)
os: Linux Mint 21 (vanessa) [64-bit]
@bismurphy bismurphy added the C-bug Category: bug label Nov 12, 2022
@ehuss
Copy link
Contributor

ehuss commented Nov 12, 2022

Thanks for the report! I have identified what is causing the error and am preparing a fix.

As for getting you up and running now, we might need to do a little investigation to figure out why it is happening to you.

The problem is that git doesn't allow opening git repositories that are owned by a different user. If you are creating your project in a directory that is owned by a different user, that looks like it will trigger the error.

Can you check what your current user is (running id) and check the ownership of the directory you are creating your project in?

If the ownership is different, some things you can do:

  • Change the ownership so they are the same
  • Work in a different directory where you can ensure the ownership is the same
  • Alternatively, you can add the safe.directory config option to your global git config. There is more information here about this option and what it does.

And, finally, I think you can just ignore the error. IIUC, cargo new has completed successfully, it's just doing a check at the end that is failing. There should be a Cargo.toml and src directory with your new project. Scratch that, it isn't correct.

@ehuss ehuss added the A-git Area: anything dealing with git label Nov 12, 2022
@ehuss ehuss self-assigned this Nov 12, 2022
@bismurphy
Copy link
Author

Got it! I changed the ownership to be the same (the directory I was using was from an old Linux installation and it was still registered to the old user). Seems that this was just a matter of poorly-written error message.

I was now able to run the cargo command as expected.

@ehuss ehuss added the regression-from-stable-to-stable Regression in stable that worked in a previous stable release. label Nov 12, 2022
bors added a commit that referenced this issue Nov 12, 2022
Fix git2 safe-directory disable

The call to `set_verify_owner_validation` was not getting called unless a network configuration was found. This means in the common case that `cargo new` will fail when there is a safe-directory error. This fixes the issue by making sure that `set_verify_owner_validation` is called before the early-exits in `init_git_transports`.

Fixes #11365
bors added a commit that referenced this issue Nov 12, 2022
Fix git2 safe-directory disable

The call to `set_verify_owner_validation` was not getting called unless a network configuration was found. This means in the common case that `cargo new` will fail when there is a safe-directory error. This fixes the issue by making sure that `set_verify_owner_validation` is called before the early-exits in `init_git_transports`.

Fixes #11365
ehuss pushed a commit to ehuss/cargo that referenced this issue Nov 15, 2022
Fix git2 safe-directory disable

The call to `set_verify_owner_validation` was not getting called unless a network configuration was found. This means in the common case that `cargo new` will fail when there is a safe-directory error. This fixes the issue by making sure that `set_verify_owner_validation` is called before the early-exits in `init_git_transports`.

Fixes rust-lang#11365
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-git Area: anything dealing with git C-bug Category: bug regression-from-stable-to-stable Regression in stable that worked in a previous stable release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants