【问题标题】:Rust - Failed to create packageRust - 无法创建包
【发布时间】:2021-01-03 23:14:35
【问题描述】:

我在这里遵循基本步骤:file:///Users/leongaban/.rustup/toolchains/stable-x86_64-apple-darwin/share/doc/rust/html/book/ch01-03-hello-货物.html

我检查了我的 cargo 版本,并 cd .. 备份到我的根项目文件夹并运行以下命令来创建一个新项目:

cargo new hello_cargo

它抛出了以下错误:

错误:无法在 /Users/leongaban/projects/rust_projects/hello_cargo 创建包 hello_cargo

但是,当我运行 ls 时,它确实创建了文件夹?所以我很好奇我以后如何避免这个错误?

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

【问题讨论】:

  • 默认情况下,cargo 会尝试在项目中创建 Git 存储库。如果您不需要它,只需运行cargo new --vcs none hello_cargo
  • 当然也可以安装 git。

标签: rust rust-cargo


【解决方案1】:

这可能是运行cargo new时调用git init命令引起的,the source code如下:

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())?;
}

.git-templates 记录在 git init TEMPLATE DIRECTORY 部分下。

模板目录将是以下之一(按顺序):

  1. 使用 --template 选项给出的参数;
  2. $GIT_TEMPLATE_DIR 环境变量的内容;
  3. init.templateDir 配置变量;或
  4. 默认模板目录:/usr/share/git-core/templates。

因此,您应该检查上述 4 个可能的原因,以便在运行 git init 时将不存在的文件夹 '/Users/leongaban/.git-templates/' 设置为 git tempalte 目录。

【讨论】:

    【解决方案2】:

    我也有这个问题。我的环境:

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

    解决方案:

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

    【讨论】:

      【解决方案3】:

      我在我的 gitconfig 中定义了一个模板

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

      我不确定这是什么时候添加的或为什么添加它,但评论它让我克服了这个错误

      【讨论】:

        猜你喜欢
        • 2022-01-11
        • 2016-11-21
        • 1970-01-01
        • 2014-05-26
        • 1970-01-01
        • 2014-08-28
        • 2019-03-26
        • 2019-09-09
        • 1970-01-01
        相关资源
        最近更新 更多