libvcs
libvcs copied to clipboard
More: `git init`
Changes
Cmd: Git.init improvements
This PR enhances the Git.init() method with improved parameter validation, comprehensive documentation, and extensive test coverage. Key improvements include:
-
Enhanced Parameter Support:
- Added support for
ref_formatparameter (files/reftable) - Added
defaultparameter for default permissions - Added
make_parentsparameter to control directory creation - Expanded
sharedparameter to support all git-supported values
- Added support for
-
Improved Type Handling:
- Enhanced
templateparameter to accept bothstrandpathlib.Path - Added comprehensive validation for all parameters
- Added proper type hints and validation for shared repository modes
- Enhanced
-
Documentation Improvements:
- Added detailed parameter descriptions
- Included comprehensive examples for each parameter
- Added proper return type and raises documentation
- Enhanced docstring with real-world usage examples
-
Validation & Error Handling:
- Added validation for template directories
- Added branch name validation
- Added shared repository mode validation
- Added proper error messages for invalid inputs
Examples
# Basic repository initialization
git = Git(path="/path/to/repo")
git.init()
# Create with custom branch name
git.init(branch="main")
# Create bare repository
git.init(bare=True)
# Create shared repository with group permissions
git.init(shared="group")
# Create with custom permissions
git.init(shared="0660")
# Create with separate git directory
git.init(separate_git_dir="/path/to/git/dir")
# Create with template
git.init(template="/path/to/template")
# Create with SHA-256 object format (git >= 2.29.0)
git.init(object_format="sha256")
Testing
The PR includes comprehensive test coverage. To run the tests:
# Run all tests
pytest tests/cmd/test_git.py
# Run specific test cases
pytest tests/cmd/test_git.py::test_git_init_basic
pytest tests/cmd/test_git.py::test_git_init_shared
pytest tests/cmd/test_git.py::test_git_init_validation_errors
Validation Tests
The PR includes tests for various validation scenarios:
# Invalid template
git.init(template=123) # Raises TypeError
# Non-existent template
git.init(template="/nonexistent") # Raises ValueError
# Invalid object format
git.init(object_format="invalid") # Raises ValueError
# Invalid branch name
git.init(branch="main branch") # Raises ValueError
# Invalid shared value
git.init(shared="invalid") # Raises ValueError
Breaking Changes
None. All changes are backward compatible while adding new functionality.
Dependencies
- No new dependencies required
- Some features (like
ref_format="reftable") require git >= 2.37.0 - SHA-256 object format requires git >= 2.29.0
Summary by Sourcery
Enhances the Git.init() method with improved parameter validation, comprehensive documentation, and extensive test coverage. It introduces new features such as support for ref_format, default, and make_parents parameters, and enhances existing parameters like template and shared with improved type handling and validation.
New Features:
- Adds support for the
ref_formatparameter to specify the reference storage format. - Adds support for the
defaultparameter to use default permissions for directories and files. - Adds support for the
make_parentsparameter to create parent directories if they don't exist.
Enhancements:
- Enhances the
templateparameter to accept bothstrandpathlib.Pathtypes. - Expands the
sharedparameter to support all git-supported values, including boolean, string literals, and octal number strings. - Improves parameter validation for
template,object_format,branch, andsharedparameters. - Adds type hints and validation for shared repository modes.
Tests:
- Adds comprehensive test coverage for the
git initcommand, including tests for various parameters and validation scenarios.
Reviewer's Guide by Sourcery
This PR enhances the Git.init() method with improved parameter validation, comprehensive documentation, and extensive test coverage. It introduces new parameters like ref_format, default, and make_parents, expands the functionality of the shared parameter, and improves type handling for the template parameter. The changes also include comprehensive validation and error handling, along with detailed documentation and examples.
No diagrams generated as the changes look simple and do not need a visual representation.
File-Level Changes
| Change | Details | Files |
|---|---|---|
Enhanced the git init method with improved parameter validation, comprehensive documentation, and extensive test coverage. |
|
tests/cmd/test_git.pysrc/libvcs/cmd/git.py |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review! - Generate a plan of action for an issue: Comment
@sourcery-ai planon an issue to generate a plan of action for it.
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Codecov Report
Attention: Patch coverage is 95.29412% with 8 lines in your changes missing coverage. Please review.
Project coverage is 56.30%. Comparing base (
0cf3504) to head (a565845).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/libvcs/cmd/git.py | 90.47% | 2 Missing and 2 partials :warning: |
| tests/cmd/test_git.py | 96.87% | 4 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #487 +/- ##
==========================================
+ Coverage 54.05% 56.30% +2.24%
==========================================
Files 40 40
Lines 3637 3799 +162
Branches 794 808 +14
==========================================
+ Hits 1966 2139 +173
+ Misses 1319 1306 -13
- Partials 352 354 +2
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.