This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 395
Discard lines in file diff #487
Merged
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
5178dbf
Make Unstaged Changes div focusable
kuychaco e10790b
Rename command for discarding changes in file
kuychaco eb6dcbe
Add discardChangesInBuffer function with tests
kuychaco 476e12a
Modify buffer in transaction to allow undoing discard actions
kuychaco e3c4daf
Implement GitController#discardLines and test
kuychaco eb6d14e
Add discard selection context menu option for untaged file diff
kuychaco 6ff442f
Add TODO to handle no-new-line case
kuychaco 0263946
:fire: console.log
kuychaco 9bd128a
Add createBlob and restoreBlob to GitShellOutStrategy
kuychaco 569a1fa
Create FileDiscardHistory model
kuychaco 2044feb
Add ability to undo last discard action
kuychaco 4a5a489
Fix borked test
kuychaco 3d0df0f
Throw error if there's no match when discarding added lines
kuychaco 097782b
Add FilePatch-header
simurai 803e8d5
:shirt:
kuychaco 853b630
Merge remote-tracking branch 'origin/master' into ku-discard-lines
kuychaco 5093966
Wire up buttons in file diff header
kuychaco e2a9737
Move discard context menu items to separate section
kuychaco 8455e3f
Add to GitShellOutStrategy#isPartiallyStaged
kuychaco 2b1fdc0
Only show diff view button for viewing corresonding diff if one exists
kuychaco 42c6a61
Align FilePatchView-title
simurai d1862a8
Add `github:view-corresponding-diff` command
kuychaco 2650171
Add command `github:undo-last-file-diff-discard`
kuychaco d672567
:shirt:
kuychaco 3f4ce84
Undo discard with `cmd-z`
kuychaco 9a5747e
:fire: Remove toggle styles
simurai bba2bfc
Truncate FilePatchView-title
simurai cac3ccf
Merge branch 'ku-discard-lines' of https://github.com/atom/github int…
simurai 357a813
Perform safety check before performing destructive action to avoid races
kuychaco 2adf514
Dispose of newly created buffer after discard
kuychaco d72302d
:fire: comment
kuychaco fb0d10a
:art: use `until` in tests
kuychaco 038c09f
Fix test
kuychaco 2f218fd
Fix flakey tests using `until`
kuychaco 9c8a2e0
:art:
kuychaco 455cf45
:shirt:
kuychaco 9ebd6a7
Quietly select corresponding item in StagingView
kuychaco be5e400
Use `core:undo` instead of `cmd-z`
kuychaco 1738ea5
:art: Create `CannotRestoreError`
kuychaco 34bdd81
Log non-CannotRestoreError errors
kuychaco d6799a0
:art: use assert.async.isTrue rather than until
kuychaco 5281ad9
:art: use assert.async.equal instead of until
kuychaco 8073c37
:shirt:
kuychaco bb3d953
Allow blob creation with stdin in GSOS#createBlob
kuychaco 771c582
Fix test description
kuychaco 03a9a68
Add GSOS#getBlobContents(sha)
kuychaco 11960f9
Persist discard history in git config across refresh and Atom windows
kuychaco 3f3633d
Limit discard history to prevent unbounded growth
kuychaco 0a222b3
Merge remote-tracking branch 'origin/master' into ku-discard-lines
kuychaco 4057109
Clear discard history if snapshot is expired
kuychaco 18d768e
:shirt:
kuychaco 3dd6f96
Add button in file diff to stage or unstage all
kuychaco 1a048a0
Clean up window focus listener
kuychaco 7ffcfb4
Set default discard history to empty object
kuychaco 684d729
getHistoryForPath -> getLastHistorySnapshotsForPath
kuychaco 50b306d
Open pre-discard versin of file in new buffer
kuychaco a219518
Move hasUndoHistory method from GitController to FilePatchController
kuychaco 7e62f54
Add test for openFileInNewBuffer
kuychaco b788334
Fix tests
kuychaco 06cfcd5
:art:
kuychaco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export default function discardChangesInBuffer(buffer, filePatch, discardedLines) { | ||
buffer.transact(() => { | ||
let addedCount = 0; | ||
let removedCount = 0; | ||
let deletedCount = 0; | ||
filePatch.getHunks().forEach(hunk => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
hunk.getLines().forEach(line => { | ||
if (discardedLines.has(line)) { | ||
if (line.status === 'deleted') { | ||
const row = (line.oldLineNumber - deletedCount) + addedCount - removedCount - 1; | ||
buffer.insert([row, 0], line.text + '\n'); | ||
addedCount++; | ||
} else if (line.status === 'added') { | ||
const row = line.newLineNumber + addedCount - removedCount - 1; | ||
if (buffer.lineForRow(row) === line.text) { | ||
buffer.deleteRow(row); | ||
removedCount++; | ||
} else { | ||
throw new Error(buffer.lineForRow(row) + ' does not match ' + line.text); | ||
} | ||
} else if (line.status === 'nonewline') { | ||
// TODO: handle no new line case | ||
} else { | ||
throw new Error(`unrecognized status: ${line.status}. Must be 'added' or 'deleted'`); | ||
} | ||
} | ||
if (line.getStatus() === 'deleted') { | ||
deletedCount++; | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
buffer.save(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,14 @@ export function readFile(absoluteFilePath, encoding = 'utf8') { | |
}); | ||
} | ||
|
||
export function writeFile(absoluteFilePath, contents) { | ||
return new Promise((resolve, reject) => { | ||
fs.writeFile(absoluteFilePath, contents, err => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could swear I saw a pull request on node.js that would make Fake edit: here it is; nodejs/node#5020. Looks like it won't be in Node 6 in any case. |
||
if (err) { return reject(err); } else { return resolve(); } | ||
}); | ||
}); | ||
} | ||
|
||
export function deleteFileOrFolder(path) { | ||
return new Promise((resolve, reject) => { | ||
fs.remove(path, err => { | ||
|
Oops, something went wrong.
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.
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.
Good catch!