Leon Gaban
Leon Gaban

Reputation: 39044

Rust - Failed to create package

I'm following the basic steps here: file:///Users/leongaban/.rustup/toolchains/stable-x86_64-apple-darwin/share/doc/rust/html/book/ch01-03-hello-cargo.html

I checked my cargo version, and cd .. back up to my root project folders and ran the following command to create a new project:

cargo new hello_cargo

And it threw the following error:

error: Failed to create package hello_cargo at /Users/leongaban/projects/rust_projects/hello_cargo

However when I run ls it did create the folder? So I'm curious how do I avoid that error in the future?

rust_projects % cargo new hello_cargo
error: Failed to create package `hello_cargo` at `/Users/leongaban/projects/rust_projects/hello_cargo`

Caused by:
  could not find '/Users/leongaban/.git-templates/' to stat: No such file or directory; class=Os (2); code=NotFound (-3)
rust_projects % ls
hello_cargo hello_world

Upvotes: 1

Views: 1524

Answers (3)

John T Dyer
John T Dyer

Reputation: 156

I had a template defined in my gitconfig

[init]
        templatedir = /Users/johndye/.git-templates

I am not sure when this got added or why but commenting it out got me past this error

Upvotes: 0

PLT
PLT

Reputation: 1

I also had this problem. My environment:

  System: MacOS Catalina (version: 10.15.7)
  Rustc version: rustc 1.51.0

Solution:

  1. rustup self install
  2. curl https://sh.rustup.rs -sSf | sh

Upvotes: 0

James Yang
James Yang

Reputation: 636

This maybe caused by git init command invoked when you run cargo new, the source code is as below:

if !path.join(".git").exists() {
    // Temporary fix to work around bug in libgit2 when creating a
    // directory in the root of a posix filesystem.
    // See: https://github.com/libgit2/libgit2/issues/5130
    paths::create_dir_all(path)?;
    GitRepo::init(path, config.cwd())?;
}

And the .git-templates is documented under git init TEMPLATE DIRECTORY section.

The template directory will be one of the following (in order):

  1. the argument given with the --template option;
  2. the contents of the $GIT_TEMPLATE_DIR environment variable;
  3. the init.templateDir configuration variable; or
  4. the default template directory: /usr/share/git-core/templates.

So you should check above 4 possible cause to setup the non-exists folder '/Users/leongaban/.git-templates/' as git tempalte dir when run git init.

Upvotes: 2

Related Questions