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

Cargo init does not respect git config default branch variable #8588

Closed
Wtoll opened this issue Aug 5, 2020 · 9 comments · Fixed by #8778
Closed

Cargo init does not respect git config default branch variable #8588

Wtoll opened this issue Aug 5, 2020 · 9 comments · Fixed by #8778
Labels
A-git Area: anything dealing with git C-bug Category: bug Command-init Command-new S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix

Comments

@Wtoll
Copy link

Wtoll commented Aug 5, 2020

Introduction

This issue affects the most recent version of cargo pulled from rustup: version 1.45.1 commit f242df6. I tried to look through the issues page to see if this has been fixed since, and also the commit history but I didn't see anything to do with this specific issue. If it has already been dealt with I apologize for the unnecessary issue.

The problem

In an effort to try and minimize the use of racially insensitive language, as of Git version 2.28.0 there is now the option to set a git config variable (init.defaultBranch) to rename the default branch generated when using git init to something other than "master." Despite this change, using cargo init still generates the git repository using the default branch "master" regardless of the git config variable.

Some more specifics

If git init is called and then cargo init is called afterwards, git init will create a git repository with the default branch being defined according to init.defaultBranch, and cargo init will not overwrite that. This ends with the branch being equal to init.defaultBranch as it is intended.

If cargo init is called by itself without a git repository already initialized it will create a git repository with the default branch always being "master." This ends with the branch being "master" which is unintended functionality.

If cargo init is called and then git init is called afterwards, cargo init will create a git repository with the default branch always being "master," and git init will not overwrite that. This ends with the branch being "master" which is unintended functionality (unintended in the sense that as a whole the proper branch name is not used. I expected git init to not overwrite the repository created by cargo init, so this is not a surprise).

My opinion

To me it seems pretty reasonable that cargo should follow the git config init.defaultBranch variable when creating the git repository for a new project. I know the rust community is actively working on moving away from racially insensitive language as a whole, but obviously that takes time. That being said, this change seems like a fairly minor stepping stone change that would be pretty easy to quickly implement, but would allow people to start new projects off on the right foot.

It might seem kind of stupid because it's really easy to simply switch branches before the initial commit, but because of cargo's ability to quickly and easily spin up projects, it's often that I forget my branch name is not correct despite setting the git config variable.

Needless to say this isn't an urgent change, but it seems like a really easy one to make that would be both a step in the right direction to minimizing racially insensitive language, and fixing cargo so it doesn't violate intended git functionality.

@Wtoll Wtoll added the C-bug Category: bug label Aug 5, 2020
@Wtoll Wtoll changed the title Cargo init does not respect git default branch config variable Cargo init does not respect git config default branch variable Aug 5, 2020
@Wtoll
Copy link
Author

Wtoll commented Aug 5, 2020

I also just tested on version 1.47.0-nightly (commit aa68721) and I can confirm the bug still persists.

@Eh2406
Copy link
Contributor

Eh2406 commented Aug 5, 2020 via email

@ehuss
Copy link
Contributor

ehuss commented Aug 5, 2020

Yea, this is blocked on libgit2/libgit2#5581.

@ehuss ehuss added A-git Area: anything dealing with git S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix Command-init Command-new labels Aug 5, 2020
@ghost
Copy link

ghost commented Aug 6, 2020

I though cargo just runs git init in the root folder.

@sfackler
Copy link
Member

sfackler commented Aug 6, 2020

It does not - it uses libgit2 which is not the same thing as git-the-cli-program.

@pyropeter
Copy link

libgit2/libgit2#5581 was merged, so this is fixed, right?

@de-vri-es
Copy link

de-vri-es commented Oct 13, 2020

Not yet, but once rust-lang/git2-rs#627 is merged and released, and the dependency is updated here, it should be fixed :)

@ehuss ehuss mentioned this issue Oct 14, 2020
@bors bors closed this as completed in 60194f2 Oct 14, 2020
ehuss pushed a commit to ehuss/cargo that referenced this issue Oct 14, 2020
Update git2.

Closes rust-lang#8517
Closes rust-lang#8588
Closes rust-lang#8352
Closes rust-lang#4777
Closes rust-lang#8746

I only added a test for one of these. I can add for the others if you want.
@songyang-dev
Copy link

I still have this issue on the latest release. I just installed Rust and its toolchain today.

rustc 1.81.0 (eeb90cda1 2024-09-04)
cargo 1.81.0 (2dbb1af80 2024-08-20)

@weihanglo
Copy link
Member

@songyang-dev thanks for the report! Note that this is a 4-year-old closed issue. I just checked and it works. If you don't mind providing a minimal reproducible example, please open a new issue. We can figure it out together then.

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 Command-init Command-new S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants