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

[RRFC] npm init should also initialise git repo if it git is installed or the folder is not a git repo already #411

Open
Rafi993 opened this issue Jul 10, 2021 · 4 comments

Comments

@Rafi993
Copy link

Rafi993 commented Jul 10, 2021

Motivation ("The Why")

  • Most of the time when developers do $ npm init in a project they usually run $ git init to set it as a git repo
  • In other eco systems like Rust in tools like cargo when you do cargo init checks if you have git installed if so initialises it as a git repo (it it already not a git repo)
  • If the developer does not want to use git but use other version controls (or none) they could specify it in a flag like
    $ cargo --vcs
  • We could do similar thing in npm. Even-though this is not a major change it does improve the developer experience little bit

Example

  • You go to a folder and run $ npm init -y it creates a package.json with default values and also initialises it as a git repo

How

Current Behaviour

  • Right now when you do $ npm init it asks you a set of questions then it initialises the package.json
  • Or when you do $ npm init -y it creates the package.json with default values

Desired Behaviour

  • When you run $ npm init ask question about version control (with git as default value)
  • Similarly when they run $ npm init -y it will create package.json and initialise the folder as git repo if it is already not a git repo and git is installed

References

  • n/a
@Rafi993 Rafi993 changed the title [RRFC] npm init should also run git init if it git is installed or the folder is not a git repo already [RRFC] npm init should also run initialise git repo if it git is installed or the folder is not a git repo already Jul 10, 2021
@Rafi993 Rafi993 changed the title [RRFC] npm init should also run initialise git repo if it git is installed or the folder is not a git repo already [RRFC] npm init should also initialise git repo if it git is installed or the folder is not a git repo already Jul 10, 2021
@ljharb
Copy link
Contributor

ljharb commented Jul 10, 2021

How would npm know if the dir is already in a repo or not? It might not be in a git repo - it might be mercurial, or svn, or perforce, or something invented next week.

@Rafi993
Copy link
Author

Rafi993 commented Jul 11, 2021

How would npm know if the dir is already in a repo or not? It might not be in a git repo - it might be mercurial, or svn, or perforce, or something invented next week.

We could do something similar to cargo https://github.com/rust-lang/cargo/blob/18f25982aeaf6ba77626621de91e65d3d6acaf0c/src/cargo/ops/cargo_new.rs#L674-L703

by default assume the version control is git if other version control needs to be used you may need to specify. This means it makes things easier for majority of users but for users who use other vcs they need to specify the flag (It also simplifies the logic).

@ljharb
Copy link
Contributor

ljharb commented Jul 11, 2021

What if it’s intended to be a subfolder in a not-yet-inited monorepo?

@Rafi993
Copy link
Author

Rafi993 commented Jul 11, 2021

What if it’s intended to be a subfolder in a not-yet-inited monorepo?

You are right it does complicate things rather than simplifying. Since cargo follows different approach to those issues replicating it might not be possible I did not think this through. Thanks for your time @ljharb. Feel free to close this RFC if this could not be taken further.

@darcyclarke darcyclarke added the Agenda will be discussed at the Open RFC call label Jul 21, 2021
@darcyclarke darcyclarke removed the Agenda will be discussed at the Open RFC call label Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants