Add rye init --vcs option to set version control system. Defaults to git, adds mercurial and none options. #1289
+475
−101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds the --vcs option for rye init, which is intended to act just like cargo init --vcs option.
Usage:
Default can be configured in ~/.rye/config.toml
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 "[email protected]".
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:
Manually validated new behavior:
rye init --vcs mercurial when with vcs = "git" in ~/.rye/config.toml results in mercurial VCS, hgignore file
rye init --vcs unexpected causes error "error: one of the values isn't valid for an argument"
rye init with vcs = "unexpected" in ~/.rye/config.toml results in git VCS and gitignore file.
rye init with --vcs none results in no ignore files or VCS repo
author and email metadata are set from local config values for mercurial, last returned values for git (which are local in my test case).