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