-
Couldn't load subscription status.
- Fork 3
fix(smart-mode): detect renames #450
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
fix(smart-mode): detect renames #450
Conversation
WalkthroughThe changes update the methods that process Git command outputs in the project. In Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Caller
participant GitCmd as Git Commands
participant DiffConv as convertDiffToChangedFiles
participant StatusConv as convertStatusToChangedFiles
participant Merger as maps.Copy
Caller->>GitCmd: Execute "git diff --name-status -z"
GitCmd-->>Caller: Return diff output (null-terminated)
Caller->>DiffConv: Process diff output
Caller->>GitCmd: Execute "git status -z --untracked-files"
GitCmd-->>Caller: Return status output (null-terminated)
Caller->>StatusConv: Process status output
DiffConv->>Merger: Merge diff results
StatusConv->>Merger: Merge status results
Merger-->>Caller: Return combined ChangedFiles map
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
internal/myks/git.go (2)
44-68: Well-implemented parsing logic for git diff outputsThe function correctly handles parsing the null-terminated output from
git diff --name-status -z, including the special case of rename operations. The comment documentation is clear and the parsing logic is robust.Consider adding more detailed comments about the specific format of the git diff output with
-zflag to improve maintainability, especially explaining the pattern of status codes followed by filenames in null-terminated sequences.
70-95: Well-designed parsing for git status outputsThe function correctly handles the different format of the
git status -zoutput, which has a different structure than the git diff output. The logic appropriately extracts status codes and filenames, including handling renames correctly.Similar to the diff function, consider adding more detailed comments about the specific format of git status output with
-zflag, particularly explaining the position of status codes and how they differ from git diff output.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (4)
internal/myks/git.go(2 hunks)internal/myks/git_test.go(2 hunks)internal/myks/smart_mode.go(0 hunks)internal/myks/smart_mode_test.go(0 hunks)
💤 Files with no reviewable changes (2)
- internal/myks/smart_mode_test.go
- internal/myks/smart_mode.go
🧰 Additional context used
🧬 Code Definitions (1)
internal/myks/git_test.go (1)
internal/myks/git.go (1)
ChangedFiles(10-10)
🔇 Additional comments (5)
internal/myks/git_test.go (3)
5-5: LGTM: Required import for string manipulationThe
stringspackage is necessary for usingstrings.Joinin the test functions to create input data with null terminators.
32-68: Well-structured tests for git diff parsingThe function has been renamed from
Test_convertToChangedFilestoTest_convertDiffToChangedFilesto align with the new underlying function. The test constructs input with null terminators and tests a comprehensive range of cases:
- Standard changes (Add, Modify, Delete)
- Renames with similarity index (R100, R066)
- Filenames with special characters (spaces, arrows, tabs)
- The special case of the second filename in a rename operation
The error reporting is also well implemented with pretty-printed output for easier debugging.
70-108: Comprehensive tests for git status parsingThis new test function effectively validates the
convertStatusToChangedFilesfunction by:
- Testing various git status codes (A, M, D, R, ?)
- Handling compound statuses (AM, AD)
- Testing untracked files (??)
- Using the same robust error reporting structure for better debugging
The test structure mirrors the diff test structure, which provides consistency across the test suite.
internal/myks/git.go (2)
4-4: LGTM: Required import for map operationsThe
mapspackage is necessary for using themaps.Copyfunction to merge the results from different Git commands.
28-28: Improved file path handling and map operationsThese changes enhance robustness in two ways:
- Using the
-zflag for Git commands to get null-terminated output, which handles filenames with special characters more reliably- Using
maps.Copyfor merging results, which is cleaner and less error-prone than manual map mergingThis approach is particularly important for detecting renamed files with paths containing spaces or special characters.
Also applies to: 32-32, 35-35, 39-39
Docstrings generation was requested by @Zebradil. * #450 (comment) The following files were modified: * `internal/myks/git.go` * `internal/myks/smart_mode.go`
|
Note Generated docstrings for this pull request at #451 |
Summary by CodeRabbit