-
Notifications
You must be signed in to change notification settings - Fork 7
Fix stage this hunk #132
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 stage this hunk #132
Conversation
This reverts commit f42c4bf.
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.
Pull Request Overview
This PR fixes issues with staging file and chunk diffs by improving how optional values are handled and updating patch outputs.
- Changes optional checks from shorthand binding to explicit nil checks in cachedDiff and diff.
- Updates patch handling to safely unwrap optional values before processing.
- Explicitly ignores the output of the GitAddPatch process.
if cachedDiff != nil { | ||
StagedView( | ||
fileDiffs: $cachedExpandableFileDiffs, | ||
onSelectFileDiff: { fileDiff in | ||
let newDiff = cachedDiff.updateFileDiffStage(fileDiff, stage: false) | ||
restorePatch(newDiff) | ||
if let newDiff = self.cachedDiff?.updateFileDiffStage(fileDiff, stage: false) { | ||
restorePatch(newDiff) | ||
} | ||
}, | ||
onSelectChunk: { fileDiff, chunk in | ||
let newDiff = cachedDiff.updateChunkStage(chunk, in: fileDiff, stage: false) | ||
restorePatch(newDiff) | ||
if let newDiff = self.cachedDiff?.updateChunkStage(chunk, in: fileDiff, stage: false) { |
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.
Consider using optional binding (e.g., 'if let cached = self.cachedDiff') instead of checking 'cachedDiff != nil' to avoid redundant optional chaining when calling updateFileDiffStage.
Copilot uses AI. Check for mistakes.
if diff != nil { | ||
UnstagedView( | ||
fileDiffs: $expandableFileDiffs, | ||
untrackedFiles: status?.untrackedFiles ?? [], | ||
onSelectFileDiff: { fileDiff in | ||
let newDiff = diff.updateFileDiffStage(fileDiff, stage: true) | ||
addPatch(newDiff) | ||
if let newDiff = self.diff?.updateFileDiffStage(fileDiff, stage: true) { | ||
addPatch(newDiff) | ||
} | ||
}, | ||
onSelectChunk: { fileDiff, chunk in | ||
let newDiff = diff.updateChunkStage(chunk, in: fileDiff, stage: true) | ||
addPatch(newDiff) | ||
if let newDiff = self.diff?.updateChunkStage(chunk, in: fileDiff, stage: true) { |
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.
Utilize optional binding (e.g., 'if let diffValue = diff') to safely unwrap and reuse the value for updateFileDiffStage, rather than checking for nil separately.
Copilot uses AI. Check for mistakes.
No description provided.