Skip to content

Cargo new does not follow "includeIf" in .gitconfig  #8882

Closed
@justfortherec

Description

@justfortherec

This is a trivial bug: The name and/or email address of the user may not be set correctly by cargo new.

Problem

cargo new sets the user name and email in the Cargo.toml file based on the values configured for Git. Since version 2.13, .gitconfig can include other configuration files based on the prefix of the repository. I use this to set separate email addresses for private and work projects based on where a repository is located in my file system. See this Stackoverflow answer for details.

Unfortunately, Cargo (version 1.48.0 (65cbdd2dc 2020-10-14)) seems to ignore these include directives.

Steps

  1. Add an includeIf directive to the global .gitconfig:
$ cat << END >> ~/.gitconfig
[includeIf "gitdir:~/test/"]
    path = ~/test/.gitconfig
END
  1. Set the user details in the included file:
$ mkdir ~/test
$ cat << END > ~/test/.gitconfig
[user]
    name = "John Doe"
    email = john@example.com
END
  1. Run cargo new in a directory with the prefix of the includeIf:
$ cd ~/test
$ cargo new example-project

Expected outcome:

The generated file ~/test/example-project/Cargo.toml uses the user details from ~/test/.gitconfig:

authors = ["John Doe <john@example.com"]

Actual outcome:

The Cargo.toml file does not include the set user details:

$ grep authors ~/test/example-project/Cargo.toml
authors = ["my-username"]

Possible Solution(s)

Updating whatever is parsing the .gitconfig files might solve the problem.

Notes

Output of cargo version:

$ cargo --version
cargo 1.48.0 (65cbdd2dc 2020-10-14)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions