PROTOTYPE: feat(init): git init features - #1149
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prototypes VCS (Git) support for the init command by adding a --vcs flag, initializing a Git repository during project initialization, and extending Testcraft to customize generated .gitignore entries.
Changes:
- Add
--vcs {git,none}tocraft_application’sinitcommand and run VCS setup during initialization. - Rename
GitRepo._init_repo()toGitRepo.init_repo()and update unit tests accordingly. - Add Testcraft
InitCommandoverride plus unit/spread tests covering VCS behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/services/test_remotebuild.py | Updates mocks/assertions for the init_repo rename. |
| tests/unit/git/test_git.py | Updates patch targets from _init_repo to init_repo. |
| tests/unit/commands/test_init.py | Adds vcs arg coverage and new tests for VCS initialization and .gitignore creation. |
| tests/spread/testcraft/init-vcs/task.yaml | Adds spread test coverage for Testcraft init with/without VCS. |
| testcraft/commands/init.py | Introduces Testcraft-specific InitCommand overriding vcs_ignore_globs. |
| testcraft/commands/init.py | Exports the new InitCommand. |
| testcraft/cli.py | Registers Testcraft InitCommand (overriding default init). |
| craft_application/git/_git_repo.py | Renames repository initialization method to init_repo. |
| craft_application/commands/init.py | Implements --vcs flag, VCS initialization, and .gitignore appending logic. |
| return sorted([template.name for template in template_dirs]) | ||
|
|
||
| @property | ||
| def vcs_ignore_globs(self) -> list[str]: |
There was a problem hiding this comment.
The intention here was to create an easy way to customize what entries appear in a generated gitignore. For example, if Snapcraft overrides this to return ["*.snap", "*.comp"], it would add this to a gitignore file:
# Added by Snapcraft
*.snap
*.comp
| parser.add_argument( | ||
| "--vcs", | ||
| type=str, | ||
| choices=["git", "none"], |
There was a problem hiding this comment.
This copies how uv handles it, which is certainly future-proof, but I'm considering doing --no-vcs as an opt-out flag and removing --vcs as a flag since I doubt we'll support anything other than git any time soon.
make lint && make test?docs/reference/changelog.rst)?A prototype to add Git features to the init command.
CRAFT-5060