astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.6k stars 466 forks source link

Add rye init --vcs option to set version control system. Defaults to git, adds mercurial and none options. #1289

Open adenyes opened 2 months ago

adenyes commented 2 months ago

This adds the --vcs option for rye init, which is intended to act just like cargo init --vcs option.

Usage:

rye init --vcs [git | mercurial | none]

Default can be configured in ~/.rye/config.toml

[default]
vcs = "mercurial"

When not specified, or when git specified, current behavior is preserved. When mercurial is specified, a mercurial VCS is initialized unless the WD is already in a mercurial VCS, and a hgignore file is created. If none is specified via option or default, no VCS is initialized and no ignore templates processed.

VCS dependent operations are factored into a vcs module. To add another VCS, implement the VCSInfo trait methods for it and add a new value to the ProjectVCS enum, mapping the new trait methods to the new match cases.

One new behavior is that if the VCS email is set but the username isn't, the username will be defaulted to "Unknown". If the username is set but the email isn't, I preserved the current behavior of setting email to "unknown@domain.invalid".

Test Plan

Tested on: Windows 11 Home Existing tests: 2 failed, 30 passed failures:

Unit tests check non-templating VCSInfo methods for Git and Mercurial.

Manually regressed behavior:

author and email metadata are set from local config values for mercurial, last returned values for git (which are local in my test case).