From 0f1fbf8ad4d2e5a6189f8e18beca6475b104c03c Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 15 Nov 2018 14:04:06 +0100 Subject: [PATCH 001/106] use new builder methods --- test/models/patch/file-patch.test.js | 152 ++++++++++++--------------- 1 file changed, 69 insertions(+), 83 deletions(-) diff --git a/test/models/patch/file-patch.test.js b/test/models/patch/file-patch.test.js index abc0b5551d..f1d0f4ce03 100644 --- a/test/models/patch/file-patch.test.js +++ b/test/models/patch/file-patch.test.js @@ -3,26 +3,16 @@ import {TextBuffer} from 'atom'; import FilePatch from '../../../lib/models/patch/file-patch'; import File, {nullFile} from '../../../lib/models/patch/file'; import Patch from '../../../lib/models/patch/patch'; +import {hunkBuilder, patchBuilder} from '../../builder/patch' import Hunk from '../../../lib/models/patch/hunk'; import {Unchanged, Addition, Deletion, NoNewline} from '../../../lib/models/patch/region'; import {assertInFilePatch} from '../../helpers'; describe('FilePatch', function() { it('delegates methods to its files and patch', function() { - const buffer = new TextBuffer({text: '0000\n0001\n0002\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 2, oldRowCount: 1, newStartRow: 2, newRowCount: 3, - marker: markRange(layers.hunk, 0, 2), - regions: [ - new Unchanged(markRange(layers.unchanged, 0)), - new Addition(markRange(layers.addition, 1, 2)), - ], - }), - ]; - const marker = markRange(layers.patch); - const patch = new Patch({status: 'modified', hunks, marker}); + const {patch} = patchBuilder().addHunk( + h => h.oldRow(2).unchanged('0').added('1', '2'), + ).build(); const oldFile = new File({path: 'a.txt', mode: '120000', symlink: 'dest.txt'}); const newFile = new File({path: 'b.txt', mode: '100755'}); @@ -38,16 +28,14 @@ describe('FilePatch', function() { assert.strictEqual(filePatch.getNewMode(), '100755'); assert.isUndefined(filePatch.getNewSymlink()); - assert.strictEqual(filePatch.getMarker(), marker); + assert.strictEqual(filePatch.getMarker(), patch.marker); assert.strictEqual(filePatch.getMaxLineNumberWidth(), 1); }); it('accesses a file path from either side of the patch', function() { const oldFile = new File({path: 'old-file.txt', mode: '100644'}); const newFile = new File({path: 'new-file.txt', mode: '100644'}); - const buffer = new TextBuffer(); - const layers = buildLayers(buffer); - const patch = new Patch({status: 'modified', hunks: [], buffer, layers}); + const {patch} = patchBuilder().addHunk().build(); assert.strictEqual(new FilePatch(oldFile, newFile, patch).getPath(), 'old-file.txt'); assert.strictEqual(new FilePatch(oldFile, nullFile, patch).getPath(), 'old-file.txt'); @@ -56,20 +44,24 @@ describe('FilePatch', function() { }); it('returns the starting range of the patch', function() { - const buffer = new TextBuffer({text: '0000\n0001\n0002\n0003\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 2, oldRowCount: 1, newStartRow: 2, newRowCount: 3, - marker: markRange(layers.hunk, 1, 3), - regions: [ - new Unchanged(markRange(layers.unchanged, 1)), - new Addition(markRange(layers.addition, 2, 3)), - ], - }), - ]; - const marker = markRange(layers.patch, 1, 3); - const patch = new Patch({status: 'modified', hunks, buffer, layers, marker}); + // const buffer = new TextBuffer({text: '0000\n0001\n0002\n0003\n'}); + // const layers = buildLayers(buffer); + // const hunks = [ + // new Hunk({ + // oldStartRow: 2, oldRowCount: 1, newStartRow: 2, newRowCount: 3, + // marker: markRange(layers.hunk, 1, 3), + // regions: [ + // new Unchanged(markRange(layers.unchanged, 1)), + // new Addition(markRange(layers.addition, 2, 3)), + // ], + // }), + // ]; + // const marker = markRange(layers.patch, 1, 3); + // const patch2 = new Patch({status: 'modified', hunks, buffer, layers, marker}); + + const {patch} = patchBuilder().status('modified').addHunk( + h => h.oldRow(2).unchanged('0000').added('0001', '0002'), + ).build(); const oldFile = new File({path: 'a.txt', mode: '100644'}); const newFile = new File({path: 'a.txt', mode: '100644'}); @@ -82,9 +74,7 @@ describe('FilePatch', function() { let emptyPatch; beforeEach(function() { - const buffer = new TextBuffer(); - const layers = buildLayers(buffer); - emptyPatch = new Patch({status: 'modified', hunks: [], buffer, layers}); + emptyPatch = patchBuilder().empty().build(); }); it('detects changes in executable mode', function() { @@ -135,12 +125,14 @@ describe('FilePatch', function() { const file01 = new File({path: 'file-01.txt', mode: '100644'}); const file10 = new File({path: 'file-10.txt', mode: '100644'}); const file11 = new File({path: 'file-11.txt', mode: '100644'}); - const buffer0 = new TextBuffer({text: '0'}); - const layers0 = buildLayers(buffer0); - const patch0 = new Patch({status: 'modified', hunks: [], buffer: buffer0, layers: layers0}); - const buffer1 = new TextBuffer({text: '1'}); - const layers1 = buildLayers(buffer1); - const patch1 = new Patch({status: 'modified', hunks: [], buffer: buffer1, layers: layers1}); + // const buffer0 = new TextBuffer({text: '0'}); + // const layers0 = buildLayers(buffer0); + // const patch0 = new Patch({status: 'modified', hunks: [], buffer: buffer0, layers: layers0}); + // const buffer1 = new TextBuffer({text: '1'}); + // const layers1 = buildLayers(buffer1); + // const patch1 = new Patch({status: 'modified', hunks: [], buffer: buffer1, layers: layers1}); + const {patch: patch0} = patchBuilder().addHunk().build(); + const {patch: patch1} = patchBuilder().addHunk().build(); const original = new FilePatch(file00, file01, patch0); @@ -179,22 +171,9 @@ describe('FilePatch', function() { }); it('returns a new FilePatch that applies only the selected lines', function() { - const buffer = new TextBuffer({text: '0000\n0001\n0002\n0003\n0004\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 5, oldRowCount: 3, newStartRow: 5, newRowCount: 4, - marker: markRange(layers.hunk, 0, 4), - regions: [ - new Unchanged(markRange(layers.unchanged, 0)), - new Addition(markRange(layers.addition, 1, 2)), - new Deletion(markRange(layers.deletion, 3)), - new Unchanged(markRange(layers.unchanged, 4)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 4); - const patch = new Patch({status: 'modified', hunks, marker}); + const {buffer, patch} = patchBuilder().addHunk( + h => h.oldRow(5).unchanged('0000').added('0001', '0002').deleted('0003').unchanged('0004'), + ).build(); const oldFile = new File({path: 'file.txt', mode: '100644'}); const newFile = new File({path: 'file.txt', mode: '100644'}); const filePatch = new FilePatch(oldFile, newFile, patch); @@ -224,19 +203,23 @@ describe('FilePatch', function() { let oldFile, deletionPatch; beforeEach(function() { - buffer = new TextBuffer({text: '0000\n0001\n0002\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, oldRowCount: 3, newStartRow: 1, newRowCount: 0, - marker: markRange(layers.hunk, 0, 2), - regions: [ - new Deletion(markRange(layers.deletion, 0, 2)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 2); - const patch = new Patch({status: 'deleted', hunks, marker}); + // buffer = new TextBuffer({text: '0000\n0001\n0002\n'}); + // const layers = buildLayers(buffer); + // const hunks = [ + // new Hunk({ + // oldStartRow: 1, oldRowCount: 3, newStartRow: 1, newRowCount: 0, + // marker: markRange(layers.hunk, 0, 2), + // regions: [ + // new Deletion(markRange(layers.deletion, 0, 2)), + // ], + // }), + // ]; + // const marker = markRange(layers.patch, 0, 2); + // const patch = new Patch({status: 'deleted', hunks, marker}); + const {patch, buffer: b} = patchBuilder().status('deleted').addHunk( + h => h.oldRow(1).deleted('0000', '0001', '0002'), + ).build(); + buffer = b; oldFile = new File({path: 'file.txt', mode: '100644'}); deletionPatch = new FilePatch(oldFile, nullFile, patch); }); @@ -280,19 +263,22 @@ describe('FilePatch', function() { }); it('unsets the newFile when a symlink is created where a file was deleted', function() { - const nBuffer = new TextBuffer({text: '0000\n0001\n0002\n'}); - const layers = buildLayers(nBuffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, oldRowCount: 3, newStartRow: 1, newRowCount: 0, - marker: markRange(layers.hunk, 0, 2), - regions: [ - new Deletion(markRange(layers.deletion, 0, 2)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 2); - const patch = new Patch({status: 'deleted', hunks, marker}); + // const nBuffer = new TextBuffer({text: '0000\n0001\n0002\n'}); + // const layers = buildLayers(nBuffer); + // const hunks = [ + // new Hunk({ + // oldStartRow: 1, oldRowCount: 3, newStartRow: 1, newRowCount: 0, + // marker: markRange(layers.hunk, 0, 2), + // regions: [ + // new Deletion(markRange(layers.deletion, 0, 2)), + // ], + // }), + // ]; + // const marker = markRange(layers.patch, 0, 2); + // const patch = new Patch({status: 'deleted', hunks, marker}); + const {patch, buffer: nBuffer} = patchBuilder().status('deleted').addHunk( + h => h.oldRow(1).deleted('0000', '0001', '0002'), + ).build(); oldFile = new File({path: 'file.txt', mode: '100644'}); const newFile = new File({path: 'file.txt', mode: '120000'}); const replacePatch = new FilePatch(oldFile, newFile, patch); From c3488126a42e59f65a6b59b6bdab7d0b0d0f835f Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 15 Nov 2018 14:21:06 +0100 Subject: [PATCH 002/106] found some mistakes in the old test logic --- test/models/patch/file-patch.test.js | 58 +++++++++++++++------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/test/models/patch/file-patch.test.js b/test/models/patch/file-patch.test.js index f1d0f4ce03..58a0122d05 100644 --- a/test/models/patch/file-patch.test.js +++ b/test/models/patch/file-patch.test.js @@ -480,31 +480,37 @@ describe('FilePatch', function() { describe('toStringIn()', function() { it('converts the patch to the standard textual format', function() { - const buffer = new TextBuffer({text: '0000\n0001\n0002\n0003\n0004\n0005\n0006\n0007\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 10, oldRowCount: 4, newStartRow: 10, newRowCount: 3, - marker: markRange(layers.hunk, 0, 4), - regions: [ - new Unchanged(markRange(layers.unchanged, 0)), - new Addition(markRange(layers.addition, 1)), - new Deletion(markRange(layers.deletion, 2, 3)), - new Unchanged(markRange(layers.unchanged, 4)), - ], - }), - new Hunk({ - oldStartRow: 20, oldRowCount: 2, newStartRow: 20, newRowCount: 3, - marker: markRange(layers.hunk, 5, 7), - regions: [ - new Unchanged(markRange(layers.unchanged, 5)), - new Addition(markRange(layers.addition, 6)), - new Unchanged(markRange(layers.unchanged, 7)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 7); - const patch = new Patch({status: 'modified', hunks, marker}); + // const buffer = new TextBuffer({text: '0000\n0001\n0002\n0003\n0004\n0005\n0006\n0007\n'}); + // const layers = buildLayers(buffer); + // const hunks = [ + // new Hunk({ + // oldStartRow: 10, oldRowCount: 4, newStartRow: 10, newRowCount: 3, + // marker: markRange(layers.hunk, 0, 4), + // regions: [ + // new Unchanged(markRange(layers.unchanged, 0)), + // new Addition(markRange(layers.addition, 1)), + // new Deletion(markRange(layers.deletion, 2, 3)), + // new Unchanged(markRange(layers.unchanged, 4)), + // ], + // }), + // new Hunk({ + // oldStartRow: 20, oldRowCount: 2, newStartRow: 20, newRowCount: 3, + // marker: markRange(layers.hunk, 5, 7), + // regions: [ + // new Unchanged(markRange(layers.unchanged, 5)), + // new Addition(markRange(layers.addition, 6)), + // new Unchanged(markRange(layers.unchanged, 7)), + // ], + // }), + // ]; + // const marker = markRange(layers.patch, 0, 7); + // const patch = new Patch({status: 'modified', hunks, marker}); + const {patch, buffer} = patchBuilder() + .addHunk(h => + h.oldRow(10).unchanged('0000').added('0001').deleted('0002', '0003').unchanged('0004')) + .addHunk(h => + h.oldRow(20).unchanged('0005').added('0006').unchanged('0007')) + .build(); const oldFile = new File({path: 'a.txt', mode: '100644'}); const newFile = new File({path: 'b.txt', mode: '100755'}); const filePatch = new FilePatch(oldFile, newFile, patch); @@ -519,7 +525,7 @@ describe('FilePatch', function() { '-0002\n' + '-0003\n' + ' 0004\n' + - '@@ -20,2 +20,3 @@\n' + + '@@ -20,2 +19,3 @@\n' + ' 0005\n' + '+0006\n' + ' 0007\n'; From 4b69eafec14270c5bc980686b02d5fab7ce616ba Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 15 Nov 2018 14:27:12 +0100 Subject: [PATCH 003/106] =?UTF-8?q?more=20new=20builders=20yay=20?= =?UTF-8?q?=F0=9F=94=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/models/patch/file-patch.test.js | 121 +++++++++++++++------------ 1 file changed, 67 insertions(+), 54 deletions(-) diff --git a/test/models/patch/file-patch.test.js b/test/models/patch/file-patch.test.js index 58a0122d05..647ec6d888 100644 --- a/test/models/patch/file-patch.test.js +++ b/test/models/patch/file-patch.test.js @@ -421,20 +421,24 @@ describe('FilePatch', function() { let oldFile, removedFilePatch, buffer; beforeEach(function() { - buffer = new TextBuffer({text: '0000\n0001\n0002\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, oldRowCount: 0, newStartRow: 1, newRowCount: 3, - marker: markRange(layers.hunk, 0, 2), - regions: [ - new Deletion(markRange(layers.deletion, 0, 2)), - ], - }), - ]; + // buffer = new TextBuffer({text: '0000\n0001\n0002\n'}); + // const layers = buildLayers(buffer); + // const hunks = [ + // new Hunk({ + // oldStartRow: 1, oldRowCount: 0, newStartRow: 1, newRowCount: 3, + // marker: markRange(layers.hunk, 0, 2), + // regions: [ + // new Deletion(markRange(layers.deletion, 0, 2)), + // ], + // }), + // ]; oldFile = new File({path: 'file.txt', mode: '100644'}); - const marker = markRange(layers.patch, 0, 2); - const removedPatch = new Patch({status: 'deleted', hunks, marker}); + // const marker = markRange(layers.patch, 0, 2); + // const removedPatch = new Patch({status: 'deleted', hunks, marker}); + const {patch: removedPatch, buffer: b} = patchBuilder().status('deleted').addHunk( + h => h.oldRow(1).deleted('0000', '0001', '0002') + ).build(); + buffer = b; removedFilePatch = new FilePatch(oldFile, nullFile, removedPatch); }); @@ -533,21 +537,24 @@ describe('FilePatch', function() { }); it('correctly formats a file with no newline at the end', function() { - const buffer = new TextBuffer({text: '0000\n0001\n No newline at end of file\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, oldRowCount: 1, newStartRow: 1, newRowCount: 2, - marker: markRange(layers.hunk, 0, 2), - regions: [ - new Unchanged(markRange(layers.unchanged, 0)), - new Addition(markRange(layers.addition, 1)), - new NoNewline(markRange(layers.noNewline, 2)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 2); - const patch = new Patch({status: 'modified', hunks, marker}); + // const buffer = new TextBuffer({text: '0000\n0001\n No newline at end of file\n'}); + // const layers = buildLayers(buffer); + // const hunks = [ + // new Hunk({ + // oldStartRow: 1, oldRowCount: 1, newStartRow: 1, newRowCount: 2, + // marker: markRange(layers.hunk, 0, 2), + // regions: [ + // new Unchanged(markRange(layers.unchanged, 0)), + // new Addition(markRange(layers.addition, 1)), + // new NoNewline(markRange(layers.noNewline, 2)), + // ], + // }), + // ]; + // const marker = markRange(layers.patch, 0, 2); + // const patch = new Patch({status: 'modified', hunks, marker}); + const {patch, buffer} = patchBuilder().addHunk( + h => h.oldRow(1).unchanged('0000').added('0001').noNewline(), + ).build(); const oldFile = new File({path: 'a.txt', mode: '100644'}); const newFile = new File({path: 'b.txt', mode: '100755'}); const filePatch = new FilePatch(oldFile, newFile, patch); @@ -565,19 +572,22 @@ describe('FilePatch', function() { describe('typechange file patches', function() { it('handles typechange patches for a symlink replaced with a file', function() { - const buffer = new TextBuffer({text: '0000\n0001\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, oldRowCount: 0, newStartRow: 1, newRowCount: 2, - marker: markRange(layers.hunk, 0, 1), - regions: [ - new Addition(markRange(layers.addition, 0, 1)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 1); - const patch = new Patch({status: 'added', hunks, marker}); + // const buffer = new TextBuffer({text: '0000\n0001\n'}); + // const layers = buildLayers(buffer); + // const hunks = [ + // new Hunk({ + // oldStartRow: 1, oldRowCount: 0, newStartRow: 1, newRowCount: 2, + // marker: markRange(layers.hunk, 0, 1), + // regions: [ + // new Addition(markRange(layers.addition, 0, 1)), + // ], + // }), + // ]; + // const marker = markRange(layers.patch, 0, 1); + // const patch = new Patch({status: 'added', hunks, marker}); + const {patch, buffer} = patchBuilder().status('added').addHunk( + h => h.oldRow(1).added('0000', '0001'), + ).build(); const oldFile = new File({path: 'a.txt', mode: '120000', symlink: 'dest.txt'}); const newFile = new File({path: 'a.txt', mode: '100644'}); const filePatch = new FilePatch(oldFile, newFile, patch); @@ -601,19 +611,22 @@ describe('FilePatch', function() { }); it('handles typechange patches for a file replaced with a symlink', function() { - const buffer = new TextBuffer({text: '0000\n0001\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, oldRowCount: 2, newStartRow: 1, newRowCount: 0, - markers: markRange(layers.hunk, 0, 1), - regions: [ - new Deletion(markRange(layers.deletion, 0, 1)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 1); - const patch = new Patch({status: 'deleted', hunks, marker}); + // const buffer = new TextBuffer({text: '0000\n0001\n'}); + // const layers = buildLayers(buffer); + // const hunks = [ + // new Hunk({ + // oldStartRow: 1, oldRowCount: 2, newStartRow: 1, newRowCount: 0, + // markers: markRange(layers.hunk, 0, 1), + // regions: [ + // new Deletion(markRange(layers.deletion, 0, 1)), + // ], + // }), + // ]; + // const marker = markRange(layers.patch, 0, 1); + // const patch = new Patch({status: 'deleted', hunks, marker}); + const {patch, buffer} = patchBuilder().status('deleted').addHunk( + h => h.oldRow(1).deleted('0000', '0001'), + ).build(); const oldFile = new File({path: 'a.txt', mode: '100644'}); const newFile = new File({path: 'a.txt', mode: '120000', symlink: 'dest.txt'}); const filePatch = new FilePatch(oldFile, newFile, patch); From 3e81788c0f5e6f6510e26a4f6708287c93c96ec4 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 15 Nov 2018 14:32:57 +0100 Subject: [PATCH 004/106] cleanup unused code --- test/models/patch/file-patch.test.js | 171 ++------------------------- 1 file changed, 12 insertions(+), 159 deletions(-) diff --git a/test/models/patch/file-patch.test.js b/test/models/patch/file-patch.test.js index 647ec6d888..f8d2ccc1ee 100644 --- a/test/models/patch/file-patch.test.js +++ b/test/models/patch/file-patch.test.js @@ -3,12 +3,12 @@ import {TextBuffer} from 'atom'; import FilePatch from '../../../lib/models/patch/file-patch'; import File, {nullFile} from '../../../lib/models/patch/file'; import Patch from '../../../lib/models/patch/patch'; -import {hunkBuilder, patchBuilder} from '../../builder/patch' +import {patchBuilder} from '../../builder/patch' import Hunk from '../../../lib/models/patch/hunk'; import {Unchanged, Addition, Deletion, NoNewline} from '../../../lib/models/patch/region'; import {assertInFilePatch} from '../../helpers'; -describe('FilePatch', function() { +describe.only('FilePatch', function() { it('delegates methods to its files and patch', function() { const {patch} = patchBuilder().addHunk( h => h.oldRow(2).unchanged('0').added('1', '2'), @@ -44,21 +44,6 @@ describe('FilePatch', function() { }); it('returns the starting range of the patch', function() { - // const buffer = new TextBuffer({text: '0000\n0001\n0002\n0003\n'}); - // const layers = buildLayers(buffer); - // const hunks = [ - // new Hunk({ - // oldStartRow: 2, oldRowCount: 1, newStartRow: 2, newRowCount: 3, - // marker: markRange(layers.hunk, 1, 3), - // regions: [ - // new Unchanged(markRange(layers.unchanged, 1)), - // new Addition(markRange(layers.addition, 2, 3)), - // ], - // }), - // ]; - // const marker = markRange(layers.patch, 1, 3); - // const patch2 = new Patch({status: 'modified', hunks, buffer, layers, marker}); - const {patch} = patchBuilder().status('modified').addHunk( h => h.oldRow(2).unchanged('0000').added('0001', '0002'), ).build(); @@ -125,12 +110,6 @@ describe('FilePatch', function() { const file01 = new File({path: 'file-01.txt', mode: '100644'}); const file10 = new File({path: 'file-10.txt', mode: '100644'}); const file11 = new File({path: 'file-11.txt', mode: '100644'}); - // const buffer0 = new TextBuffer({text: '0'}); - // const layers0 = buildLayers(buffer0); - // const patch0 = new Patch({status: 'modified', hunks: [], buffer: buffer0, layers: layers0}); - // const buffer1 = new TextBuffer({text: '1'}); - // const layers1 = buildLayers(buffer1); - // const patch1 = new Patch({status: 'modified', hunks: [], buffer: buffer1, layers: layers1}); const {patch: patch0} = patchBuilder().addHunk().build(); const {patch: patch1} = patchBuilder().addHunk().build(); @@ -203,19 +182,6 @@ describe('FilePatch', function() { let oldFile, deletionPatch; beforeEach(function() { - // buffer = new TextBuffer({text: '0000\n0001\n0002\n'}); - // const layers = buildLayers(buffer); - // const hunks = [ - // new Hunk({ - // oldStartRow: 1, oldRowCount: 3, newStartRow: 1, newRowCount: 0, - // marker: markRange(layers.hunk, 0, 2), - // regions: [ - // new Deletion(markRange(layers.deletion, 0, 2)), - // ], - // }), - // ]; - // const marker = markRange(layers.patch, 0, 2); - // const patch = new Patch({status: 'deleted', hunks, marker}); const {patch, buffer: b} = patchBuilder().status('deleted').addHunk( h => h.oldRow(1).deleted('0000', '0001', '0002'), ).build(); @@ -263,19 +229,6 @@ describe('FilePatch', function() { }); it('unsets the newFile when a symlink is created where a file was deleted', function() { - // const nBuffer = new TextBuffer({text: '0000\n0001\n0002\n'}); - // const layers = buildLayers(nBuffer); - // const hunks = [ - // new Hunk({ - // oldStartRow: 1, oldRowCount: 3, newStartRow: 1, newRowCount: 0, - // marker: markRange(layers.hunk, 0, 2), - // regions: [ - // new Deletion(markRange(layers.deletion, 0, 2)), - // ], - // }), - // ]; - // const marker = markRange(layers.patch, 0, 2); - // const patch = new Patch({status: 'deleted', hunks, marker}); const {patch, buffer: nBuffer} = patchBuilder().status('deleted').addHunk( h => h.oldRow(1).deleted('0000', '0001', '0002'), ).build(); @@ -300,22 +253,9 @@ describe('FilePatch', function() { }); it('returns a new FilePatch that unstages only the specified lines', function() { - const buffer = new TextBuffer({text: '0000\n0001\n0002\n0003\n0004\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 5, oldRowCount: 3, newStartRow: 5, newRowCount: 4, - marker: markRange(layers.hunk, 0, 4), - regions: [ - new Unchanged(markRange(layers.unchanged, 0)), - new Addition(markRange(layers.addition, 1, 2)), - new Deletion(markRange(layers.deletion, 3)), - new Unchanged(markRange(layers.unchanged, 4)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 4); - const patch = new Patch({status: 'modified', hunks, marker}); + const {patch, buffer} = patchBuilder().addHunk( + h => h.oldRow(5).unchanged('0000').added('0001', '0002').deleted('0003').unchanged('0004'), + ).build(); const oldFile = new File({path: 'file.txt', mode: '100644'}); const newFile = new File({path: 'file.txt', mode: '100644'}); const filePatch = new FilePatch(oldFile, newFile, patch); @@ -346,20 +286,12 @@ describe('FilePatch', function() { let newFile, addedPatch, addedFilePatch; beforeEach(function() { - buffer = new TextBuffer({text: '0000\n0001\n0002\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, oldRowCount: 0, newStartRow: 1, newRowCount: 3, - marker: markRange(layers.hunk, 0, 2), - regions: [ - new Addition(markRange(layers.addition, 0, 2)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 2); + const {patch, buffer: b} = patchBuilder().status('added').addHunk( + h => h.oldRow(1).added('0000', '0001', '0002'), + ).build(); + addedPatch = patch; + buffer = b; newFile = new File({path: 'file.txt', mode: '100644'}); - addedPatch = new Patch({status: 'added', hunks, marker}); addedFilePatch = new FilePatch(nullFile, newFile, addedPatch); }); @@ -421,24 +353,11 @@ describe('FilePatch', function() { let oldFile, removedFilePatch, buffer; beforeEach(function() { - // buffer = new TextBuffer({text: '0000\n0001\n0002\n'}); - // const layers = buildLayers(buffer); - // const hunks = [ - // new Hunk({ - // oldStartRow: 1, oldRowCount: 0, newStartRow: 1, newRowCount: 3, - // marker: markRange(layers.hunk, 0, 2), - // regions: [ - // new Deletion(markRange(layers.deletion, 0, 2)), - // ], - // }), - // ]; - oldFile = new File({path: 'file.txt', mode: '100644'}); - // const marker = markRange(layers.patch, 0, 2); - // const removedPatch = new Patch({status: 'deleted', hunks, marker}); const {patch: removedPatch, buffer: b} = patchBuilder().status('deleted').addHunk( - h => h.oldRow(1).deleted('0000', '0001', '0002') + h => h.oldRow(1).deleted('0000', '0001', '0002'), ).build(); buffer = b; + oldFile = new File({path: 'file.txt', mode: '100644'}); removedFilePatch = new FilePatch(oldFile, nullFile, removedPatch); }); @@ -484,31 +403,6 @@ describe('FilePatch', function() { describe('toStringIn()', function() { it('converts the patch to the standard textual format', function() { - // const buffer = new TextBuffer({text: '0000\n0001\n0002\n0003\n0004\n0005\n0006\n0007\n'}); - // const layers = buildLayers(buffer); - // const hunks = [ - // new Hunk({ - // oldStartRow: 10, oldRowCount: 4, newStartRow: 10, newRowCount: 3, - // marker: markRange(layers.hunk, 0, 4), - // regions: [ - // new Unchanged(markRange(layers.unchanged, 0)), - // new Addition(markRange(layers.addition, 1)), - // new Deletion(markRange(layers.deletion, 2, 3)), - // new Unchanged(markRange(layers.unchanged, 4)), - // ], - // }), - // new Hunk({ - // oldStartRow: 20, oldRowCount: 2, newStartRow: 20, newRowCount: 3, - // marker: markRange(layers.hunk, 5, 7), - // regions: [ - // new Unchanged(markRange(layers.unchanged, 5)), - // new Addition(markRange(layers.addition, 6)), - // new Unchanged(markRange(layers.unchanged, 7)), - // ], - // }), - // ]; - // const marker = markRange(layers.patch, 0, 7); - // const patch = new Patch({status: 'modified', hunks, marker}); const {patch, buffer} = patchBuilder() .addHunk(h => h.oldRow(10).unchanged('0000').added('0001').deleted('0002', '0003').unchanged('0004')) @@ -537,21 +431,6 @@ describe('FilePatch', function() { }); it('correctly formats a file with no newline at the end', function() { - // const buffer = new TextBuffer({text: '0000\n0001\n No newline at end of file\n'}); - // const layers = buildLayers(buffer); - // const hunks = [ - // new Hunk({ - // oldStartRow: 1, oldRowCount: 1, newStartRow: 1, newRowCount: 2, - // marker: markRange(layers.hunk, 0, 2), - // regions: [ - // new Unchanged(markRange(layers.unchanged, 0)), - // new Addition(markRange(layers.addition, 1)), - // new NoNewline(markRange(layers.noNewline, 2)), - // ], - // }), - // ]; - // const marker = markRange(layers.patch, 0, 2); - // const patch = new Patch({status: 'modified', hunks, marker}); const {patch, buffer} = patchBuilder().addHunk( h => h.oldRow(1).unchanged('0000').added('0001').noNewline(), ).build(); @@ -572,19 +451,6 @@ describe('FilePatch', function() { describe('typechange file patches', function() { it('handles typechange patches for a symlink replaced with a file', function() { - // const buffer = new TextBuffer({text: '0000\n0001\n'}); - // const layers = buildLayers(buffer); - // const hunks = [ - // new Hunk({ - // oldStartRow: 1, oldRowCount: 0, newStartRow: 1, newRowCount: 2, - // marker: markRange(layers.hunk, 0, 1), - // regions: [ - // new Addition(markRange(layers.addition, 0, 1)), - // ], - // }), - // ]; - // const marker = markRange(layers.patch, 0, 1); - // const patch = new Patch({status: 'added', hunks, marker}); const {patch, buffer} = patchBuilder().status('added').addHunk( h => h.oldRow(1).added('0000', '0001'), ).build(); @@ -611,19 +477,6 @@ describe('FilePatch', function() { }); it('handles typechange patches for a file replaced with a symlink', function() { - // const buffer = new TextBuffer({text: '0000\n0001\n'}); - // const layers = buildLayers(buffer); - // const hunks = [ - // new Hunk({ - // oldStartRow: 1, oldRowCount: 2, newStartRow: 1, newRowCount: 0, - // markers: markRange(layers.hunk, 0, 1), - // regions: [ - // new Deletion(markRange(layers.deletion, 0, 1)), - // ], - // }), - // ]; - // const marker = markRange(layers.patch, 0, 1); - // const patch = new Patch({status: 'deleted', hunks, marker}); const {patch, buffer} = patchBuilder().status('deleted').addHunk( h => h.oldRow(1).deleted('0000', '0001'), ).build(); From 63ac1ee13209da3e3d4060025b7acf121476b851 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 15 Nov 2018 14:33:35 +0100 Subject: [PATCH 005/106] clean up unused imports and :fire: `.only` --- test/models/patch/file-patch.test.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/models/patch/file-patch.test.js b/test/models/patch/file-patch.test.js index f8d2ccc1ee..506330766c 100644 --- a/test/models/patch/file-patch.test.js +++ b/test/models/patch/file-patch.test.js @@ -2,13 +2,10 @@ import {TextBuffer} from 'atom'; import FilePatch from '../../../lib/models/patch/file-patch'; import File, {nullFile} from '../../../lib/models/patch/file'; -import Patch from '../../../lib/models/patch/patch'; import {patchBuilder} from '../../builder/patch' -import Hunk from '../../../lib/models/patch/hunk'; -import {Unchanged, Addition, Deletion, NoNewline} from '../../../lib/models/patch/region'; import {assertInFilePatch} from '../../helpers'; -describe.only('FilePatch', function() { +describe('FilePatch', function() { it('delegates methods to its files and patch', function() { const {patch} = patchBuilder().addHunk( h => h.oldRow(2).unchanged('0').added('1', '2'), From f6b697f7dbd5729ad05de226416bd911c82043b0 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 15 Nov 2018 14:35:16 +0100 Subject: [PATCH 006/106] lint --- test/models/patch/file-patch.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/patch/file-patch.test.js b/test/models/patch/file-patch.test.js index 506330766c..1d3a961c8f 100644 --- a/test/models/patch/file-patch.test.js +++ b/test/models/patch/file-patch.test.js @@ -2,7 +2,7 @@ import {TextBuffer} from 'atom'; import FilePatch from '../../../lib/models/patch/file-patch'; import File, {nullFile} from '../../../lib/models/patch/file'; -import {patchBuilder} from '../../builder/patch' +import {patchBuilder} from '../../builder/patch'; import {assertInFilePatch} from '../../helpers'; describe('FilePatch', function() { From 285b935b7c3c9a1e8010ca3f6fe867a5d672de51 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 15 Nov 2018 14:38:39 +0100 Subject: [PATCH 007/106] don't need `markRange()` anymore --- test/models/patch/file-patch.test.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/models/patch/file-patch.test.js b/test/models/patch/file-patch.test.js index 1d3a961c8f..6cc0a8c449 100644 --- a/test/models/patch/file-patch.test.js +++ b/test/models/patch/file-patch.test.js @@ -536,7 +536,3 @@ function buildLayers(buffer) { noNewline: buffer.addMarkerLayer(), }; } - -function markRange(buffer, start, end = start) { - return buffer.markRange([[start, 0], [end, Infinity]]); -} From beb1db4d83a2d50047ff70b64c378f3686021234 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 15 Nov 2018 14:54:04 +0100 Subject: [PATCH 008/106] onto patch test --- test/models/patch/patch.test.js | 44 +++++++-------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/test/models/patch/patch.test.js b/test/models/patch/patch.test.js index b5989ab3fe..75e3452a12 100644 --- a/test/models/patch/patch.test.js +++ b/test/models/patch/patch.test.js @@ -3,9 +3,10 @@ import {TextBuffer} from 'atom'; import Patch from '../../../lib/models/patch/patch'; import Hunk from '../../../lib/models/patch/hunk'; import {Unchanged, Addition, Deletion, NoNewline} from '../../../lib/models/patch/region'; +import {patchBuilder} from '../../builder/patch'; import {assertInPatch} from '../../helpers'; -describe('Patch', function() { +describe.only('Patch', function() { it('has some standard accessors', function() { const buffer = new TextBuffer({text: 'bufferText'}); const layers = buildLayers(buffer); @@ -17,40 +18,13 @@ describe('Patch', function() { }); it('computes the total changed line count', function() { - const buffer = buildBuffer(15); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 0, newStartRow: 0, oldRowCount: 1, newRowCount: 1, - sectionHeading: 'zero', - marker: markRange(layers.hunk, 0, 5), - regions: [ - new Unchanged(markRange(layers.unchanged, 0)), - new Addition(markRange(layers.addition, 1)), - new Unchanged(markRange(layers.unchanged, 2)), - new Deletion(markRange(layers.deletion, 3, 4)), - new Unchanged(markRange(layers.unchanged, 5)), - ], - }), - new Hunk({ - oldStartRow: 0, newStartRow: 0, oldRowCount: 1, newRowCount: 1, - sectionHeading: 'one', - marker: markRange(layers.hunk, 6, 15), - regions: [ - new Unchanged(markRange(layers.unchanged, 6)), - new Deletion(markRange(layers.deletion, 7)), - new Unchanged(markRange(layers.unchanged, 8)), - new Deletion(markRange(layers.deletion, 9, 11)), - new Addition(markRange(layers.addition, 12, 14)), - new Unchanged(markRange(layers.unchanged, 15)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, Infinity); - - const p = new Patch({status: 'modified', hunks, marker}); - - assert.strictEqual(p.getChangedLineCount(), 10); + const {patch} = patchBuilder() + .addHunk( + h => h.oldRow(0).unchanged('0').added('1').unchanged('2').deleted('3', '4').unchanged('5')) + .addHunk( + h => h.oldRow(0).unchanged('6').deleted('7').unchanged('8').deleted('9', '10', '11').added('12', '13', '14').unchanged('15')) + .build(); + assert.strictEqual(patch.getChangedLineCount(), 10); }); it('computes the maximum number of digits needed to display a diff line number', function() { From d42a4ee3005ba827d5a91a6e795802da25c36448 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 15 Nov 2018 17:46:44 +0100 Subject: [PATCH 009/106] build fixture! --- test/models/patch/patch.test.js | 83 +++++++++++---------------------- 1 file changed, 28 insertions(+), 55 deletions(-) diff --git a/test/models/patch/patch.test.js b/test/models/patch/patch.test.js index 75e3452a12..c77726849e 100644 --- a/test/models/patch/patch.test.js +++ b/test/models/patch/patch.test.js @@ -714,64 +714,37 @@ function markRange(buffer, start, end = start) { } function buildPatchFixture() { - const buffer = buildBuffer(26, true); - buffer.append('\n\n\n\n\n\n'); - - const layers = buildLayers(buffer); - - const hunks = [ - new Hunk({ - oldStartRow: 3, oldRowCount: 4, newStartRow: 3, newRowCount: 5, - sectionHeading: 'zero', - marker: markRange(layers.hunk, 0, 6), - regions: [ - new Unchanged(markRange(layers.unchanged, 0)), - new Deletion(markRange(layers.deletion, 1, 2)), - new Addition(markRange(layers.addition, 3, 5)), - new Unchanged(markRange(layers.unchanged, 6)), - ], - }), - new Hunk({ - oldStartRow: 12, oldRowCount: 9, newStartRow: 13, newRowCount: 7, - sectionHeading: 'one', - marker: markRange(layers.hunk, 7, 18), - regions: [ - new Unchanged(markRange(layers.unchanged, 7)), - new Addition(markRange(layers.addition, 8, 9)), - new Unchanged(markRange(layers.unchanged, 10, 11)), - new Deletion(markRange(layers.deletion, 12, 16)), - new Addition(markRange(layers.addition, 17, 17)), - new Unchanged(markRange(layers.unchanged, 18)), - ], - }), - new Hunk({ - oldStartRow: 26, oldRowCount: 4, newStartRow: 25, newRowCount: 3, - sectionHeading: 'two', - marker: markRange(layers.hunk, 19, 23), - regions: [ - new Unchanged(markRange(layers.unchanged, 19)), - new Addition(markRange(layers.addition, 20)), - new Deletion(markRange(layers.deletion, 21, 22)), - new Unchanged(markRange(layers.unchanged, 23)), - ], - }), - new Hunk({ - oldStartRow: 32, oldRowCount: 1, newStartRow: 30, newRowCount: 2, - sectionHeading: 'three', - marker: markRange(layers.hunk, 24, 26), - regions: [ - new Unchanged(markRange(layers.unchanged, 24)), - new Addition(markRange(layers.addition, 25)), - new NoNewline(markRange(layers.noNewline, 26)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 26); + const {patch, buffer, layers} = patchBuilder() + .addHunk(h => + h.oldRow(3) + .unchanged('0000') + .deleted('0001', '0002') + .added('0003', '0004', '0005') + .unchanged('0006')) + .addHunk(h => + h.oldRow(12) + .unchanged('0007') + .added('0008', '0009') + .unchanged('0010', '0011') + .deleted('0012', '0013', '0014', '0015', '0016') + .added('0017').unchanged('0018')) + .addHunk(h => + h.oldRow(26) + .unchanged('0019') + .added('0020') + .deleted('0021', '0022') + .unchanged('0023')) + .addHunk(h => + h.oldRow(32) + .unchanged('0024') + .added('0025') + .noNewline()) + .build(); return { - patch: new Patch({status: 'modified', hunks, marker}), + patch, buffer, layers, - marker, + marker: layers.patch.getMarkers(), }; } From 0690ec8183ef8149c40a2815cf463f578e126130 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 15 Nov 2018 17:47:18 +0100 Subject: [PATCH 010/106] more builder tingss --- test/models/patch/patch.test.js | 35 ++++++--------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/test/models/patch/patch.test.js b/test/models/patch/patch.test.js index c77726849e..12257a6017 100644 --- a/test/models/patch/patch.test.js +++ b/test/models/patch/patch.test.js @@ -28,57 +28,34 @@ describe.only('Patch', function() { }); it('computes the maximum number of digits needed to display a diff line number', function() { - const buffer = buildBuffer(15); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 0, oldRowCount: 1, newStartRow: 0, newRowCount: 1, - sectionHeading: 'zero', - marker: markRange(layers.hunk, 0, 5), - regions: [], - }), - new Hunk({ - oldStartRow: 98, - oldRowCount: 5, - newStartRow: 95, - newRowCount: 3, - sectionHeading: 'one', - marker: markRange(layers.hunk, 6, 15), - regions: [], - }), - ]; - const p0 = new Patch({status: 'modified', hunks, buffer, layers}); + const {patch: p0} = patchBuilder().addHunk(h => h.oldRow(0)).addHunk(h => h.oldRow(98)).build(); assert.strictEqual(p0.getMaxLineNumberWidth(), 3); - const p1 = new Patch({status: 'deleted', hunks: [], buffer, layers}); + const {patch: p1} = patchBuilder().status('deleted').empty().build(); assert.strictEqual(p1.getMaxLineNumberWidth(), 0); }); it('clones itself with optionally overridden properties', function() { - const buffer = new TextBuffer({text: 'bufferText'}); - const layers = buildLayers(buffer); - const marker = markRange(layers.patch, 0, Infinity); - - const original = new Patch({status: 'modified', hunks: [], marker}); + const {patch: original, layers} = patchBuilder().empty().build(); const dup0 = original.clone(); assert.notStrictEqual(dup0, original); assert.strictEqual(dup0.getStatus(), 'modified'); assert.deepEqual(dup0.getHunks(), []); - assert.strictEqual(dup0.getMarker(), marker); + assert.strictEqual(dup0.getMarker(), layers.patch.getMarkers()[0]); const dup1 = original.clone({status: 'added'}); assert.notStrictEqual(dup1, original); assert.strictEqual(dup1.getStatus(), 'added'); assert.deepEqual(dup1.getHunks(), []); - assert.strictEqual(dup0.getMarker(), marker); + assert.strictEqual(dup0.getMarker(), layers.patch.getMarkers()[0]); const hunks = [new Hunk({regions: []})]; const dup2 = original.clone({hunks}); assert.notStrictEqual(dup2, original); assert.strictEqual(dup2.getStatus(), 'modified'); assert.deepEqual(dup2.getHunks(), hunks); - assert.strictEqual(dup0.getMarker(), marker); + assert.strictEqual(dup0.getMarker(), layers.patch.getMarkers()[0]); const nBuffer = new TextBuffer({text: 'changed'}); const nLayers = buildLayers(nBuffer); From c75efcf4d2a462b4603c5560166a22294ec3a1bf Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Tue, 13 Nov 2018 06:45:27 +0000 Subject: [PATCH 011/106] chore(package): update node-fetch to version 2.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5fa21e24d2..6978f1fd9f 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "mocha-junit-reporter": "1.18.0", "mocha-multi-reporters": "^1.1.7", "mocha-stress": "1.0.0", - "node-fetch": "2.2.1", + "node-fetch": "2.3.0", "nyc": "13.0.0", "relay-compiler": "1.6.2", "semver": "5.6.0", From 48c8bfbe527b50173f9d9018d034744be744bcd9 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Tue, 13 Nov 2018 06:45:31 +0000 Subject: [PATCH 012/106] chore(package): update lockfile package-lock.json --- package-lock.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1df9fb4073..06e0f6da07 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5083,7 +5083,7 @@ }, "load-json-file": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", "dev": true, "requires": { @@ -5526,9 +5526,9 @@ } }, "node-fetch": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.2.1.tgz", - "integrity": "sha512-ObXBpNCD3A/vYQiQtEWl7DuqjAXjfptYFuGHLdPl5U19/6kJuZV+8uMHLrkj3wJrJoyfg4nhgyFixZdaZoAiEQ==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.3.0.tgz", + "integrity": "sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA==", "dev": true }, "node-int64": { From 147ec748d1d4adb622d9cde51cc57ba67581be62 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Wed, 14 Nov 2018 11:33:22 -0500 Subject: [PATCH 013/106] Update Enzyme and its React 16 adapter --- package-lock.json | 174 +++++++++++++++++++++++++++++----------------- package.json | 4 +- 2 files changed, 111 insertions(+), 67 deletions(-) diff --git a/package-lock.json b/package-lock.json index 06e0f6da07..be0d4afb5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -214,36 +214,10 @@ "tmp": "0.0.31" } }, - "@smashwilson/enzyme-adapter-react-16": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@smashwilson/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.0.2.tgz", - "integrity": "sha512-YGotyPAPOwi9vbRzvTutDgqYbBo5gX8mELNHPICcAXilV9XMa0yxqCQ6OY4ItIO5dPiRkc9RkjSYBr2M1fFOZw==", - "dev": true, - "requires": { - "@smashwilson/enzyme-adapter-utils": "^1.0.0", - "lodash": "^4.17.4", - "object.assign": "^4.1.0", - "object.values": "^1.0.4", - "prop-types": "^15.6.0", - "react-reconciler": "^0.7.0", - "react-test-renderer": "^16.0.0-0" - } - }, - "@smashwilson/enzyme-adapter-utils": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@smashwilson/enzyme-adapter-utils/-/enzyme-adapter-utils-1.0.0.tgz", - "integrity": "sha512-/kQoTFU5bdbZbh6C9Ohxz1BgoHW+n2BX/kGUcS3DucGZfVNl4Em9lJqzd3aelyZSJz+cRX/FuE6ccnO6MnZc0Q==", - "dev": true, - "requires": { - "lodash": "^4.17.4", - "object.assign": "^4.1.0", - "prop-types": "^15.6.0" - } - }, "@types/node": { - "version": "10.7.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.7.1.tgz", - "integrity": "sha512-EGoI4ylB/lPOaqXqtzAyL8HcgOuCtH2hkEaLmkueOYufsTFWBn4VCvlCDC2HW8Q+9iF+QVC3sxjDKQYjHQeZ9w==", + "version": "10.12.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.7.tgz", + "integrity": "sha512-Zh5Z4kACfbeE8aAOYh9mqotRxaZMro8MbBQtR8vEXOMiZo2rGEh2LayJijKdlu48YnS6y2EFU/oo2NCe5P6jGw==", "dev": true }, "abstract-leveldown": { @@ -2247,9 +2221,9 @@ } }, "css-what": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/css-what/-/css-what-2.1.0.tgz", - "integrity": "sha1-lGfQMsOM+u+58teVASUwYvh/ob0=", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/css-what/-/css-what-2.1.2.tgz", + "integrity": "sha512-wan8dMWQ0GUeF7DGEPVjhHemVW/vy6xUYmFzRY8RYqgA0JtXC9rJmbScBjqSu6dg9q0lwPQy6ZAmJVr3PPTvqQ==", "dev": true }, "currently-unhandled": { @@ -2510,9 +2484,9 @@ "dev": true }, "domelementtype": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.0.tgz", - "integrity": "sha1-sXrtguirWeUt2cGbF1bg/BhyBMI=", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.2.1.tgz", + "integrity": "sha512-SQVCLFS2E7G5CRCMdn6K9bIhRj1bS6QBWZfF0TUPh4V/BbqrQ619IdSS3/izn0FZ+9l+uODzaZjb08fjOfablA==", "dev": true }, "domhandler": { @@ -2762,9 +2736,9 @@ } }, "entities": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.1.tgz", - "integrity": "sha1-blwtClYhtdra7O+AuQ7ftc13cvA=", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==", "dev": true }, "env-paths": { @@ -2774,9 +2748,9 @@ "dev": true }, "enzyme": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/enzyme/-/enzyme-3.4.1.tgz", - "integrity": "sha512-XBZbyUy36WipNSBVZKIR1sg9iF6zXfkfDEzwTc10T9zhB61UPnMo+c3WE17T/jyhfmPJOz6X073NXXsR7G/1rA==", + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/enzyme/-/enzyme-3.7.0.tgz", + "integrity": "sha512-QLWx+krGK6iDNyR1KlH5YPZqxZCQaVF6ike1eDJAOg0HvSkSCVImPsdWaNw6v+VrnK92Kg8jIOYhuOSS9sBpyg==", "dev": true, "requires": { "array.prototype.flat": "^1.2.1", @@ -2788,14 +2762,16 @@ "is-number-object": "^1.0.3", "is-string": "^1.0.4", "is-subset": "^0.1.1", - "lodash": "^4.17.4", + "lodash.escape": "^4.0.1", + "lodash.isequal": "^4.5.0", "object-inspect": "^1.6.0", "object-is": "^1.0.1", "object.assign": "^4.1.0", "object.entries": "^1.0.4", "object.values": "^1.0.4", "raf": "^3.4.0", - "rst-selector-parser": "^2.2.3" + "rst-selector-parser": "^2.2.3", + "string.prototype.trim": "^1.1.2" }, "dependencies": { "has": { @@ -2815,6 +2791,41 @@ } } }, + "enzyme-adapter-react-16": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.7.0.tgz", + "integrity": "sha512-rDr0xlnnFPffAPYrvG97QYJaRl9unVDslKee33wTStsBEwZTkESX1H7VHGT5eUc6ifNzPgOJGvSh2zpHT4gXjA==", + "dev": true, + "requires": { + "enzyme-adapter-utils": "^1.9.0", + "function.prototype.name": "^1.1.0", + "object.assign": "^4.1.0", + "object.values": "^1.0.4", + "prop-types": "^15.6.2", + "react-is": "^16.6.1", + "react-test-renderer": "^16.0.0-0" + }, + "dependencies": { + "react-is": { + "version": "16.6.3", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.6.3.tgz", + "integrity": "sha512-u7FDWtthB4rWibG/+mFbVd5FvdI20yde86qKGx4lVUTWmPlSWQ4QxbBIrrs+HnXGbxOUlUzTAP/VDmvCwaP2yA==", + "dev": true + } + } + }, + "enzyme-adapter-utils": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/enzyme-adapter-utils/-/enzyme-adapter-utils-1.9.0.tgz", + "integrity": "sha512-uMe4xw4l/Iloh2Fz+EO23XUYMEQXj5k/5ioLUXCNOUCI8Dml5XQMO9+QwUq962hBsY5qftfHHns+d990byWHvg==", + "dev": true, + "requires": { + "function.prototype.name": "^1.1.0", + "object.assign": "^4.1.0", + "prop-types": "^15.6.2", + "semver": "^5.6.0" + } + }, "errno": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz", @@ -4011,9 +4022,9 @@ "dev": true }, "htmlparser2": { - "version": "3.9.2", - "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.9.2.tgz", - "integrity": "sha1-G9+HrMoPP55T+k/M6w9LTLsAszg=", + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.0.tgz", + "integrity": "sha512-J1nEUGv+MkXS0weHNWVKJJ+UrLfePxRWpN3C9bEi9fLxL2+ggW94DQvgYVXsaT30PGwYRIZKNZXuyMhp3Di4bQ==", "dev": true, "requires": { "domelementtype": "^1.3.0", @@ -4021,7 +4032,35 @@ "domutils": "^1.5.1", "entities": "^1.1.1", "inherits": "^2.0.1", - "readable-stream": "^2.0.2" + "readable-stream": "^3.0.6" + }, + "dependencies": { + "domelementtype": { + "version": "1.3.0", + "resolved": "http://registry.npmjs.org/domelementtype/-/domelementtype-1.3.0.tgz", + "integrity": "sha1-sXrtguirWeUt2cGbF1bg/BhyBMI=", + "dev": true + }, + "readable-stream": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.0.6.tgz", + "integrity": "sha512-9E1oLoOWfhSXHGv6QlwXJim7uNzd9EVlWK+21tCU9Ju/kR0/p2AZYPz4qSchgO8PlLIH4FpZYfzwS+rEksZjIg==", + "dev": true, + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "http-signature": { @@ -4901,6 +4940,12 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz", "integrity": "sha1-maktZcAnLevoyWtgV7yPv6O+1RE=" }, + "lodash.escape": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.escape/-/lodash.escape-4.0.1.tgz", + "integrity": "sha1-yQRGkMIeBClL6qUXcS/e0fqI3pg=", + "dev": true + }, "lodash.flattendeep": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", @@ -5585,9 +5630,9 @@ } }, "nth-check": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.1.tgz", - "integrity": "sha1-mSms32KPwsQQmN6rgqxYDPFJquQ=", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.2.tgz", + "integrity": "sha512-WeBOdju8SnzPN5vTUJYxYUxLeXpCaVP5i5e0LF8fg7WORF2Wd7wFX/pk0tYZk7s8T+J7VLy0Da6J1+wCT0AtHg==", "dev": true, "requires": { "boolbase": "~1.0.0" @@ -6384,9 +6429,9 @@ "dev": true }, "raf": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/raf/-/raf-3.4.0.tgz", - "integrity": "sha512-pDP/NMRAXoTfrhCfyfSEwJAKLaxBU9eApMeBPB1TkDouZmvPerIClV8lTAd+uF8ZiTaVl69e1FCxQrAd/VTjGw==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/raf/-/raf-3.4.1.tgz", + "integrity": "sha512-Sq4CW4QhwOHE8ucn6J34MqtZCeWFP2aQSmrlroYgqAV1PjStIhJXxYuTgUIfkEk7zTLjmIjLmU5q+fbD1NnOJA==", "dev": true, "requires": { "performance-now": "^2.1.0" @@ -6471,18 +6516,6 @@ "integrity": "sha512-xpb0PpALlFWNw/q13A+1aHeyJyLYCg0/cCHPUA43zYluZuIPHaHL3k8OBsTgQtxqW0FhyDEMvi8fZ/+7+r4OSQ==", "dev": true }, - "react-reconciler": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/react-reconciler/-/react-reconciler-0.7.0.tgz", - "integrity": "sha512-50JwZ3yNyMS8fchN+jjWEJOH3Oze7UmhxeoJLn2j6f3NjpfCRbcmih83XTWmzqtar/ivd5f7tvQhvvhism2fgg==", - "dev": true, - "requires": { - "fbjs": "^0.8.16", - "loose-envify": "^1.1.0", - "object-assign": "^4.1.1", - "prop-types": "^15.6.0" - } - }, "react-relay": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/react-relay/-/react-relay-1.6.0.tgz", @@ -7566,6 +7599,17 @@ "regexp.prototype.flags": "^1.2.0" } }, + "string.prototype.trim": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.1.2.tgz", + "integrity": "sha1-0E3iyJ4Tf019IG8Ia17S+ua+jOo=", + "dev": true, + "requires": { + "define-properties": "^1.1.2", + "es-abstract": "^1.5.0", + "function-bind": "^1.0.2" + } + }, "string_decoder": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", diff --git a/package.json b/package.json index 6978f1fd9f..b6f52b0e0a 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,6 @@ }, "devDependencies": { "@smashwilson/atom-mocha-test-runner": "1.4.0", - "@smashwilson/enzyme-adapter-react-16": "1.0.2", "babel-plugin-istanbul": "4.1.6", "chai": "4.1.2", "chai-as-promised": "7.1.1", @@ -86,7 +85,8 @@ "electron-devtools-installer": "2.2.4", "electron-link": "0.2.2", "electron-mksnapshot": "3.0.0-beta.1", - "enzyme": "3.4.1", + "enzyme": "3.7.0", + "enzyme-adapter-react-16": "1.7.0", "eslint": "5.0.1", "eslint-config-fbjs-opensource": "1.0.0", "eslint-plugin-jsx-a11y": "^6.1.1", From c857bb7b11f5112c6283af32de1da435ac4921d7 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Wed, 14 Nov 2018 11:33:36 -0500 Subject: [PATCH 014/106] Require Enzyme's React adapter correctly --- test/runner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runner.js b/test/runner.js index 101f08fc55..431f8f4036 100644 --- a/test/runner.js +++ b/test/runner.js @@ -101,7 +101,7 @@ module.exports = createRunner({ } const Enzyme = require('enzyme'); - const Adapter = require('@smashwilson/enzyme-adapter-react-16'); + const Adapter = require('enzyme-adapter-react-16'); Enzyme.configure({adapter: new Adapter()}); require('mocha-stress'); From 96e770280866fc910fc0a6a8823da9aa82a79d27 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Wed, 14 Nov 2018 11:46:25 -0500 Subject: [PATCH 015/106] Enzyme's shallow renderer can't track render props --- test/atom/pane-item.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/atom/pane-item.test.js b/test/atom/pane-item.test.js index d85f5b42de..388fb9cff8 100644 --- a/test/atom/pane-item.test.js +++ b/test/atom/pane-item.test.js @@ -89,7 +89,7 @@ describe('PaneItem', function() { describe('when opened with a matching URI', function() { it('calls its render prop', async function() { let called = false; - shallow( + mount( {() => { called = true; From fe33a3d5d8dc73d9a5c5a3f0903fba3d0de75398 Mon Sep 17 00:00:00 2001 From: Tilde Ann Thurium Date: Wed, 14 Nov 2018 13:24:00 -0800 Subject: [PATCH 016/106] Fix error where getFilePath is not a function on a CommitPreviewItem Just early return if it's not a ChangedFileItem, to avoid doing the check in the first place. Co-Authored-By: Katrina Uychaco --- lib/views/staging-view.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/views/staging-view.js b/lib/views/staging-view.js index fb4587ea0a..8629ff8953 100644 --- a/lib/views/staging-view.js +++ b/lib/views/staging-view.js @@ -762,11 +762,13 @@ export default class StagingView extends React.Component { const pendingItem = pane.getPendingItem(); if (!pendingItem || !pendingItem.getRealItem) { return false; } const realItem = pendingItem.getRealItem(); - const isDiffViewItem = realItem instanceof ChangedFileItem; + if (!(realItem instanceof ChangedFileItem)) { + return false; + } // We only want to update pending diff views for currently active repo const isInActiveRepo = realItem.getWorkingDirectory() === this.props.workingDirectoryPath; const isStale = !this.changedFileExists(realItem.getFilePath(), realItem.getStagingStatus()); - return isDiffViewItem && isInActiveRepo && isStale; + return isInActiveRepo && isStale; }); } From 094ef451bba2b51eea644b585cea4c9868649dd2 Mon Sep 17 00:00:00 2001 From: Tilde Ann Thurium Date: Wed, 14 Nov 2018 13:33:55 -0800 Subject: [PATCH 017/106] props only work if you pass them to child components Co-Authored-By: Katrina Uychaco --- lib/containers/changed-file-container.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/containers/changed-file-container.js b/lib/containers/changed-file-container.js index eb6a8a7f8a..d4661a8ac1 100644 --- a/lib/containers/changed-file-container.js +++ b/lib/containers/changed-file-container.js @@ -52,10 +52,13 @@ export default class ChangedFileContainer extends React.Component { return ; } + const {multiFilePatch, hasUndoHistory, isPartiallyStaged} = data; + return ( ); From 3a6f38cea114f806a5e9df87555d1d85d7006330 Mon Sep 17 00:00:00 2001 From: Tilde Ann Thurium Date: Wed, 14 Nov 2018 13:45:17 -0800 Subject: [PATCH 018/106] :art: Make UI more consistent Co-Authored-By: Katrina Uychaco --- lib/views/file-patch-header-view.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/views/file-patch-header-view.js b/lib/views/file-patch-header-view.js index 7b37cf810f..a01e01c5f1 100644 --- a/lib/views/file-patch-header-view.js +++ b/lib/views/file-patch-header-view.js @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'; import cx from 'classnames'; import RefHolder from '../models/ref-holder'; -import Tooltip from '../atom/tooltip'; export default class FilePatchHeaderView extends React.Component { static propTypes = { @@ -76,11 +75,11 @@ export default class FilePatchHeaderView extends React.Component { const attrs = this.props.stagingStatus === 'unstaged' ? { iconClass: 'icon-tasklist', - tooltipText: 'View staged changes', + buttonText: 'View Staged', } : { iconClass: 'icon-list-unordered', - tooltipText: 'View unstaged changes', + buttonText: 'View Unstaged', }; return ( @@ -88,19 +87,15 @@ export default class FilePatchHeaderView extends React.Component { ); } renderOpenFileButton() { - let buttonText = 'Jump to file'; + let buttonText = 'Jump To File'; if (this.props.hasMultipleFileSelections) { buttonText += 's'; } @@ -113,11 +108,6 @@ export default class FilePatchHeaderView extends React.Component { onClick={this.props.openFile}> {buttonText} - ); } From 7a429f0c56e06ff97778b37992e5ea5aa7cd16e9 Mon Sep 17 00:00:00 2001 From: Tilde Ann Thurium Date: Wed, 14 Nov 2018 16:10:43 -0800 Subject: [PATCH 019/106] we don't need to test for no stinkin tooltips --- test/views/file-patch-header-view.test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/views/file-patch-header-view.test.js b/test/views/file-patch-header-view.test.js index 93d647748b..d626ecfee0 100644 --- a/test/views/file-patch-header-view.test.js +++ b/test/views/file-patch-header-view.test.js @@ -76,8 +76,6 @@ describe('FilePatchHeaderView', function() { wrapper.find(`button.${buttonClass}`).simulate('click'); assert.isTrue(diveIntoMirrorPatch.called, `${buttonClass} click did nothing`); - - assert.isTrue(wrapper.find('Tooltip').someWhere(n => n.prop('title') === tooltip)); }; } @@ -128,12 +126,12 @@ describe('FilePatchHeaderView', function() { it('is singular when selections exist within a single file patch', function() { const wrapper = shallow(buildApp({hasMultipleFileSelections: false})); - assert.strictEqual(wrapper.find('button.icon-code').text(), 'Jump to file'); + assert.strictEqual(wrapper.find('button.icon-code').text(), 'Jump To File'); }); it('is plural when selections exist within multiple file patches', function() { const wrapper = shallow(buildApp({hasMultipleFileSelections: true})); - assert.strictEqual(wrapper.find('button.icon-code').text(), 'Jump to files'); + assert.strictEqual(wrapper.find('button.icon-code').text(), 'Jump To Files'); }); }); From 41672b661a296ca27d29e60d94ef2b175f6b1f81 Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Wed, 14 Nov 2018 18:12:36 -0800 Subject: [PATCH 020/106] Explicitly only render Undo Discard button if ChangedFileItem --- lib/items/changed-file-item.js | 1 + lib/items/commit-preview-item.js | 1 + lib/views/file-patch-header-view.js | 10 ++++++++-- lib/views/multi-file-patch-view.js | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/items/changed-file-item.js b/lib/items/changed-file-item.js index 57ddc3302b..bff241401c 100644 --- a/lib/items/changed-file-item.js +++ b/lib/items/changed-file-item.js @@ -78,6 +78,7 @@ export default class ChangedFileItem extends React.Component { return ( Date: Wed, 14 Nov 2018 18:14:38 -0800 Subject: [PATCH 021/106] Explicitly only render Undo Discard button if ChangedFileItem --- lib/views/file-patch-header-view.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/views/file-patch-header-view.js b/lib/views/file-patch-header-view.js index 20bb1e2e27..5d7bbd6eda 100644 --- a/lib/views/file-patch-header-view.js +++ b/lib/views/file-patch-header-view.js @@ -62,15 +62,16 @@ export default class FilePatchHeaderView extends React.Component { } renderUndoDiscardButton() { - if (!this.props.hasUndoHistory || this.props.stagingStatus !== 'unstaged') { + const unstagedChangedFileItem = this.props.itemType === ChangedFileItem && this.props.stagingStatus === 'unstaged'; + if (unstagedChangedFileItem && this.props.hasUndoHistory) { + return ( + + ); + } else { return null; } - - return ( - - ); } renderMirrorPatchButton() { From f465b659ce2eb30b465b4d1f296a19711b0c38cc Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Wed, 14 Nov 2018 18:15:12 -0800 Subject: [PATCH 022/106] Add `itemType` prop types for :shirt: --- lib/views/file-patch-header-view.js | 2 ++ lib/views/multi-file-patch-view.js | 3 +++ 2 files changed, 5 insertions(+) diff --git a/lib/views/file-patch-header-view.js b/lib/views/file-patch-header-view.js index 5d7bbd6eda..348d5efbd2 100644 --- a/lib/views/file-patch-header-view.js +++ b/lib/views/file-patch-header-view.js @@ -21,6 +21,8 @@ export default class FilePatchHeaderView extends React.Component { diveIntoMirrorPatch: PropTypes.func.isRequired, openFile: PropTypes.func.isRequired, toggleFile: PropTypes.func.isRequired, + + itemType: PropTypes.oneOf([ChangedFileItem, CommitPreviewItem]).isRequired, }; constructor(props) { diff --git a/lib/views/multi-file-patch-view.js b/lib/views/multi-file-patch-view.js index 14e2385b5b..4f0fdb015c 100644 --- a/lib/views/multi-file-patch-view.js +++ b/lib/views/multi-file-patch-view.js @@ -16,6 +16,8 @@ import FilePatchHeaderView from './file-patch-header-view'; import FilePatchMetaView from './file-patch-meta-view'; import HunkHeaderView from './hunk-header-view'; import RefHolder from '../models/ref-holder'; +import ChangedFileItem from '../items/changed-file-item'; +import CommitPreviewItem from '../items/commit-preview-item'; const executableText = { 100644: 'non executable', @@ -57,6 +59,7 @@ export default class MultiFilePatchView extends React.Component { discardRows: PropTypes.func.isRequired, refInitialFocus: RefHolderPropType, + itemType: PropTypes.oneOf([ChangedFileItem, CommitPreviewItem]).isRequired, } static defaultProps = { From e4dfdfc949c3ffc0e1a0142f5a7441915462bb1e Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Wed, 14 Nov 2018 18:41:28 -0800 Subject: [PATCH 023/106] Make basename bold in FilePatchHeaderView --- lib/views/file-patch-header-view.js | 25 +++++++++++++++++++++++-- styles/file-patch-view.less | 4 ++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/views/file-patch-header-view.js b/lib/views/file-patch-header-view.js index 348d5efbd2..b157e70230 100644 --- a/lib/views/file-patch-header-view.js +++ b/lib/views/file-patch-header-view.js @@ -1,3 +1,5 @@ +import path from 'path'; + import React, {Fragment} from 'react'; import PropTypes from 'prop-types'; import cx from 'classnames'; @@ -46,9 +48,28 @@ export default class FilePatchHeaderView extends React.Component { renderTitle() { if (this.props.itemType === ChangedFileItem) { const status = this.props.stagingStatus; - return `${status[0].toUpperCase()}${status.slice(1)} Changes for ${this.props.relPath}`; + return ( + {status[0].toUpperCase()}{status.slice(1)} Changes for {this.renderPath()} + ); } else { - return this.props.relPath; + return this.renderPath(); + } + } + + renderPath() { + const dirname = path.dirname(this.props.relPath); + const basename = path.basename(this.props.relPath); + + if (dirname === '.') { + return {basename}; + } else { + // TODO: double check that the forward-slash works cross-platform... + // iirc git always uses `/` for paths, even on Windows + return ( + + {dirname}/{basename} + + ); } } diff --git a/styles/file-patch-view.less b/styles/file-patch-view.less index 63a42c5ef1..f20069c650 100644 --- a/styles/file-patch-view.less +++ b/styles/file-patch-view.less @@ -261,3 +261,7 @@ } } } + +.gitub-FilePatchHeaderView-basename { + font-weight: bold; +} From b37857bf5929b76294a3260b68c5de9acdcb2769 Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Wed, 14 Nov 2018 18:50:30 -0800 Subject: [PATCH 024/106] Fix tests to include itemType --- test/views/file-patch-header-view.test.js | 30 +++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/test/views/file-patch-header-view.test.js b/test/views/file-patch-header-view.test.js index d626ecfee0..8e8d514e66 100644 --- a/test/views/file-patch-header-view.test.js +++ b/test/views/file-patch-header-view.test.js @@ -2,6 +2,7 @@ import React from 'react'; import {shallow} from 'enzyme'; import FilePatchHeaderView from '../../lib/views/file-patch-header-view'; +import ChangedFileItem from '../../lib/items/changed-file-item'; describe('FilePatchHeaderView', function() { let atomEnv; @@ -17,6 +18,7 @@ describe('FilePatchHeaderView', function() { function buildApp(overrideProps = {}) { return ( Date: Wed, 14 Nov 2018 19:54:15 -0800 Subject: [PATCH 025/106] Update docs/react-component-atlas.md Co-Authored-By: annthurium --- docs/react-component-atlas.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/react-component-atlas.md b/docs/react-component-atlas.md index 81c80e0a43..7341d3cec0 100644 --- a/docs/react-component-atlas.md +++ b/docs/react-component-atlas.md @@ -75,7 +75,7 @@ This is a high-level overview of the structure of the React component tree that > > [``](/lib/controllers/multi-file-patch-controller.js) > > [``](/lib/views/multi-file-patch-view.js) > > -> > The workspace-center pane that appears when looking at the staged or unstaged changes associated with one or more files. +> > The workspace-center pane that appears when looking at the staged or unstaged changes associated with a file. > > > > > From 4238f9818d6de6c63860ad51e85430e58fa3f5ce Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 15 Nov 2018 11:16:00 -0500 Subject: [PATCH 026/106] Update docs/react-component-atlas.md Co-Authored-By: smashwilson --- docs/react-component-atlas.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/react-component-atlas.md b/docs/react-component-atlas.md index 7341d3cec0..d40cd142de 100644 --- a/docs/react-component-atlas.md +++ b/docs/react-component-atlas.md @@ -37,7 +37,7 @@ This is a high-level overview of the structure of the React component tree that > > > [``](/lig/items/commit-preview-item.js) > > > [``](/lib/containers/commit-preview-container.js) > > > -> > > Allows users to view all unstaged commits in one pane. +> > > The workspace-center pane that appears when looking at _all_ the staged changes that will be going into the next commit. > > > > > > [``](/lib/views/remote-selector-view.js) > > > From 5afc6d60e822dbb10e47634d796fc3fd7f9a7254 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 15 Nov 2018 11:38:34 -0500 Subject: [PATCH 027/106] :world: CommitPreviewItem is beneath RootController, not GitHubTabItem Separate MultiFilePatchController and MultiFilePatchView and replicate them --- docs/react-component-atlas.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/react-component-atlas.md b/docs/react-component-atlas.md index d40cd142de..a4ae15f3e2 100644 --- a/docs/react-component-atlas.md +++ b/docs/react-component-atlas.md @@ -34,11 +34,6 @@ This is a high-level overview of the structure of the React component tree that > > > > The "GitHub" tab that appears in the right dock (by default). > > -> > > [``](/lig/items/commit-preview-item.js) -> > > [``](/lib/containers/commit-preview-container.js) -> > > -> > > The workspace-center pane that appears when looking at _all_ the staged changes that will be going into the next commit. -> > > > > > [``](/lib/views/remote-selector-view.js) > > > > > > Shown if the current repository has more than one remote that's identified as a github.com remote. @@ -71,13 +66,24 @@ This is a high-level overview of the structure of the React component tree that > > > > > > > > > > > > Render a list of issueish results as rows within the result list of a specific search. > -> > [ ``](/lib/containers/changed-file-container.js) -> > [``](/lib/controllers/multi-file-patch-controller.js) -> > [``](/lib/views/multi-file-patch-view.js) +> > [``](/lib/items/changed-file-item.js) +> > [``](/lib/containers/changed-file-container.js) > > > > The workspace-center pane that appears when looking at the staged or unstaged changes associated with a file. > > +> > > [``](/lib/controllers/multi-file-patch-controller.js) +> > > [``](/lib/views/multi-file-patch-view.js) +> > > +> > > Render a sequence of git-generated file patches within a TextEditor, using decorations to include contextually +> > > relevant controls. +> +> > [``](/lig/items/commit-preview-item.js) +> > [``](/lib/containers/commit-preview-container.js) +> > +> > The workspace-center pane that appears when looking at _all_ the staged changes that will be going into the next commit. > > +> > > [``](/lib/controllers/multi-file-patch-controller.js) +> > > [``](/lib/views/multi-file-patch-view.js) > > > [``](/lib/items/issueish-detail-item.js) > > [``](/lib/containers/issueish-detail-container.js) From e05cd5493a5d3bd57e1d1ae65ab3850015280ca2 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 15 Nov 2018 11:40:13 -0500 Subject: [PATCH 028/106] Use an object spread for that data why not --- lib/containers/changed-file-container.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/containers/changed-file-container.js b/lib/containers/changed-file-container.js index d4661a8ac1..1c3ed45a70 100644 --- a/lib/containers/changed-file-container.js +++ b/lib/containers/changed-file-container.js @@ -52,13 +52,9 @@ export default class ChangedFileContainer extends React.Component { return ; } - const {multiFilePatch, hasUndoHistory, isPartiallyStaged} = data; - return ( ); From 7de5c5e262525016093e981d1a6d6add45618ab8 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 15 Nov 2018 11:57:07 -0500 Subject: [PATCH 029/106] Pass a Decoration's className to the created DOM element --- lib/atom/decoration.js | 3 ++- test/atom/decoration.test.js | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/atom/decoration.js b/lib/atom/decoration.js index 841b8bd22e..9e3049f1a2 100644 --- a/lib/atom/decoration.js +++ b/lib/atom/decoration.js @@ -2,6 +2,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; import {Disposable} from 'event-kit'; +import cx from 'classnames'; import {createItem, autobind, extractProps} from '../helpers'; import {RefHolderPropType} from '../prop-types'; @@ -49,7 +50,7 @@ class BareDecoration extends React.Component { this.item = null; if (['gutter', 'overlay', 'block'].includes(this.props.type)) { this.domNode = document.createElement('div'); - this.domNode.className = 'react-atom-decoration'; + this.domNode.className = cx('react-atom-decoration', this.props.className); } } diff --git a/test/atom/decoration.test.js b/test/atom/decoration.test.js index dcde9c4412..2e9fd4fdcd 100644 --- a/test/atom/decoration.test.js +++ b/test/atom/decoration.test.js @@ -44,7 +44,7 @@ describe('Decoration', function() { it('creates a block decoration', function() { const app = ( - +
This is a subtree
@@ -55,7 +55,9 @@ describe('Decoration', function() { const args = editor.decorateMarker.firstCall.args; assert.equal(args[0], marker); assert.equal(args[1].type, 'block'); - const child = args[1].item.getElement().firstElementChild; + const element = args[1].item.getElement(); + assert.strictEqual(element.className, 'react-atom-decoration parent'); + const child = element.firstElementChild; assert.equal(child.className, 'decoration-subtree'); assert.equal(child.textContent, 'This is a subtree'); }); From efbecd7d3d4d5419551de8e29eab00de63b884db Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 15 Nov 2018 11:57:27 -0500 Subject: [PATCH 030/106] Set and style a more specific CSS class for control blocks --- lib/views/multi-file-patch-view.js | 4 ++-- styles/file-patch-view.less | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/views/multi-file-patch-view.js b/lib/views/multi-file-patch-view.js index 4f0fdb015c..6990f98ba6 100644 --- a/lib/views/multi-file-patch-view.js +++ b/lib/views/multi-file-patch-view.js @@ -306,7 +306,7 @@ export default class MultiFilePatchView extends React.Component { return ( - + {this.renderExecutableModeChangeMeta(filePatch)} {this.renderSymlinkChangeMeta(filePatch)} @@ -484,7 +484,7 @@ export default class MultiFilePatchView extends React.Component { return ( - + Date: Thu, 15 Nov 2018 12:24:27 -0500 Subject: [PATCH 031/106] File.modes constants for well-known file modes --- lib/models/patch/file.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/models/patch/file.js b/lib/models/patch/file.js index c9017ec56f..0c893ca4f1 100644 --- a/lib/models/patch/file.js +++ b/lib/models/patch/file.js @@ -1,4 +1,18 @@ export default class File { + static modes = { + // Non-executable, non-symlink + NORMAL: '100644', + + // +x bit set + EXECUTABLE: '100755', + + // Soft link to another filesystem location + SYMLINK: '120000', + + // Submodule mount point + GITLINK: '160000', + } + constructor({path, mode, symlink}) { this.path = path; this.mode = mode; @@ -18,15 +32,15 @@ export default class File { } isSymlink() { - return this.getMode() === '120000'; + return this.getMode() === this.constructor.modes.SYMLINK; } isRegularFile() { - return this.getMode() === '100644' || this.getMode() === '100755'; + return this.getMode() === this.constructor.modes.NORMAL || this.getMode() === this.constructor.modes.EXECUTABLE; } isExecutable() { - return this.getMode() === '100755'; + return this.getMode() === this.constructor.modes.EXECUTABLE; } isPresent() { From 9b94c2e0b918f9c3ac80b859329156f35f64606b Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 15 Nov 2018 12:24:41 -0500 Subject: [PATCH 032/106] Use File mode constants where possible --- lib/git-shell-out-strategy.js | 15 ++++++++------- lib/models/patch/builder.js | 6 +++--- lib/views/multi-file-patch-view.js | 5 +++-- test/builder/patch.js | 4 ++-- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/git-shell-out-strategy.js b/lib/git-shell-out-strategy.js index 3f152c5f58..19b422f502 100644 --- a/lib/git-shell-out-strategy.js +++ b/lib/git-shell-out-strategy.js @@ -20,6 +20,7 @@ import { normalizeGitHelperPath, toNativePathSep, toGitPathSep, LINE_ENDING_REGEX, CO_AUTHOR_REGEX, } from './helpers'; import GitTimingsView from './views/git-timings-view'; +import File from './models/patch/file'; import WorkerManager from './worker-manager'; const MAX_STATUS_OUTPUT_LENGTH = 1024 * 1024 * 10; @@ -640,12 +641,12 @@ export default class GitShellOutStrategy { let mode; let realpath; if (executable) { - mode = '100755'; + mode = File.modes.EXECUTABLE; } else if (symlink) { - mode = '120000'; + mode = File.modes.SYMLINK; realpath = await fs.realpath(absPath); } else { - mode = '100644'; + mode = File.modes.NORMAL; } rawDiffs.push(buildAddedFilePatch(filePath, binary ? null : contents, mode, realpath)); @@ -1061,11 +1062,11 @@ export default class GitShellOutStrategy { const executable = await isFileExecutable(path.join(this.workingDir, filePath)); const symlink = await isFileSymlink(path.join(this.workingDir, filePath)); if (executable) { - return '100755'; + return File.modes.EXECUTABLE; } else if (symlink) { - return '120000'; + return File.modes.SYMLINK; } else { - return '100644'; + return File.modes.NORMAL; } } } @@ -1080,7 +1081,7 @@ function buildAddedFilePatch(filePath, contents, mode, realpath) { if (contents) { const noNewLine = contents[contents.length - 1] !== '\n'; let lines; - if (mode === '120000') { + if (mode === File.modes.SYMLINK) { lines = [`+${toGitPathSep(realpath)}`, '\\ No newline at end of file']; } else { lines = contents.trim().split(LINE_ENDING_REGEX).map(line => `+${line}`); diff --git a/lib/models/patch/builder.js b/lib/models/patch/builder.js index 061745f443..aea6acae74 100644 --- a/lib/models/patch/builder.js +++ b/lib/models/patch/builder.js @@ -68,8 +68,8 @@ function emptyDiffFilePatch() { } function singleDiffFilePatch(diff, layeredBuffer) { - const wasSymlink = diff.oldMode === '120000'; - const isSymlink = diff.newMode === '120000'; + const wasSymlink = diff.oldMode === File.modes.SYMLINK; + const isSymlink = diff.newMode === File.modes.SYMLINK; const [hunks, patchMarker] = buildHunks(diff, layeredBuffer); @@ -97,7 +97,7 @@ function singleDiffFilePatch(diff, layeredBuffer) { function dualDiffFilePatch(diff1, diff2, layeredBuffer) { let modeChangeDiff, contentChangeDiff; - if (diff1.oldMode === '120000' || diff1.newMode === '120000') { + if (diff1.oldMode === File.modes.SYMLINK || diff1.newMode === File.modes.SYMLINK) { modeChangeDiff = diff1; contentChangeDiff = diff2; } else { diff --git a/lib/views/multi-file-patch-view.js b/lib/views/multi-file-patch-view.js index 6990f98ba6..47f41dcaeb 100644 --- a/lib/views/multi-file-patch-view.js +++ b/lib/views/multi-file-patch-view.js @@ -18,10 +18,11 @@ import HunkHeaderView from './hunk-header-view'; import RefHolder from '../models/ref-holder'; import ChangedFileItem from '../items/changed-file-item'; import CommitPreviewItem from '../items/commit-preview-item'; +import File from '../models/patch/file'; const executableText = { - 100644: 'non executable', - 100755: 'executable', + [File.modes.NORMAL]: 'non executable', + [File.modes.EXECUTABLE]: 'executable', }; const NBSP_CHARACTER = '\u00a0'; diff --git a/test/builder/patch.js b/test/builder/patch.js index ee863bc262..18ff5067b5 100644 --- a/test/builder/patch.js +++ b/test/builder/patch.js @@ -82,7 +82,7 @@ class FilePatchBuilder { constructor(layeredBuffer = null) { this.layeredBuffer = layeredBuffer; - this.oldFile = new File({path: 'file', mode: '100644'}); + this.oldFile = new File({path: 'file', mode: File.modes.NORMAL}); this.newFile = null; this.patchBuilder = new PatchBuilder(this.layeredBuffer); @@ -143,7 +143,7 @@ class FilePatchBuilder { class FileBuilder { constructor() { this._path = 'file.txt'; - this._mode = '100644'; + this._mode = File.modes.NORMAL; this._symlink = null; } From ec5081a35d5ab597ba8b1b57bd5b769e65d2d014 Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 15 Nov 2018 09:35:56 -0800 Subject: [PATCH 033/106] Add Release Notes section --- PULL_REQUEST_TEMPLATE.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index a51a32ed8a..c6d8eb658e 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -54,6 +54,24 @@ Write "N/A" if not applicable. +### Release Notes + + + ### User Experience Research (Optional) From 9617073a93fb5cbed6393e6b256bd3ebf58cc358 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 15 Nov 2018 12:37:24 -0500 Subject: [PATCH 034/106] Go into more detail on why that opener is necessary --- test/controllers/commit-controller.test.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/controllers/commit-controller.test.js b/test/controllers/commit-controller.test.js index 9a35a22eb6..19b307dc1a 100644 --- a/test/controllers/commit-controller.test.js +++ b/test/controllers/commit-controller.test.js @@ -30,7 +30,14 @@ describe('CommitController', function() { const noop = () => {}; const store = new UserStore({config}); - // Ensure the Workspace doesn't mangle atom-github://... URIs + // Ensure the Workspace doesn't mangle atom-github://... URIs. + // If you don't have an opener registered for a non-standard URI protocol, the Workspace coerces it into a file URI + // and tries to open it with a TextEditor. In the process, the URI gets mangled: + // + // atom.workspace.open('atom-github://unknown/whatever').then(item => console.log(item.getURI())) + // > 'atom-github:/unknown/whatever' + // + // Adding an opener that creates fake items prevents it from doing this and keeps the URIs unchanged. const pattern = new URIPattern(CommitPreviewItem.uriPattern); workspace.addOpener(uri => { if (pattern.matches(uri).ok()) { From 3a526e72c23a8dcc871c006a2e1a5059b98ed7e0 Mon Sep 17 00:00:00 2001 From: Tilde Ann Thurium Date: Thu, 15 Nov 2018 09:57:39 -0800 Subject: [PATCH 035/106] tweak symlink changes styles - The meta title text was weirdly big. Now it's not. - The meta title text should render underneath the file name, to make it clear which file it belongs to. --- lib/views/multi-file-patch-view.js | 2 +- styles/file-patch-view.less | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/views/multi-file-patch-view.js b/lib/views/multi-file-patch-view.js index 47f41dcaeb..1155432903 100644 --- a/lib/views/multi-file-patch-view.js +++ b/lib/views/multi-file-patch-view.js @@ -310,7 +310,6 @@ export default class MultiFilePatchView extends React.Component { {this.renderExecutableModeChangeMeta(filePatch)} - {this.renderSymlinkChangeMeta(filePatch)} this.didOpenFile({selectedFilePatch: filePatch})} toggleFile={() => this.props.toggleFile(filePatch)} /> + {this.renderSymlinkChangeMeta(filePatch)} diff --git a/styles/file-patch-view.less b/styles/file-patch-view.less index 037b2b5bc7..3b4fec51bb 100644 --- a/styles/file-patch-view.less +++ b/styles/file-patch-view.less @@ -112,14 +112,14 @@ &-metaHeader { display: flex; align-items: center; - padding: @component-padding; + padding: @component-padding / 2; background-color: @background-color-highlight; } &-metaTitle { flex: 1; margin: 0; - font-size: 1.25em; + font-size: 1.0em; line-height: 1.5; overflow: hidden; text-overflow: ellipsis; From 8fa79dfcf86fdc139488b74c2bfcb9d94f134eea Mon Sep 17 00:00:00 2001 From: Tilde Ann Thurium Date: Thu, 15 Nov 2018 10:12:19 -0800 Subject: [PATCH 036/106] executable mode change styling tweaks Executable mode changes should also go under the FilePatchView title so it's clear which file the mode change belongs to. --- lib/views/multi-file-patch-view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/views/multi-file-patch-view.js b/lib/views/multi-file-patch-view.js index 1155432903..f94658c2bf 100644 --- a/lib/views/multi-file-patch-view.js +++ b/lib/views/multi-file-patch-view.js @@ -309,7 +309,6 @@ export default class MultiFilePatchView extends React.Component { - {this.renderExecutableModeChangeMeta(filePatch)} this.didOpenFile({selectedFilePatch: filePatch})} toggleFile={() => this.props.toggleFile(filePatch)} /> + {this.renderExecutableModeChangeMeta(filePatch)} {this.renderSymlinkChangeMeta(filePatch)} From a3051cda23e58b280d26730b941ab477da838d35 Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 15 Nov 2018 13:03:23 -0800 Subject: [PATCH 037/106] :fire: unused cache key for stagedChangesSinceParentCommit --- lib/models/repository-states/present.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/models/repository-states/present.js b/lib/models/repository-states/present.js index 22a803c9e9..7ef7879840 100644 --- a/lib/models/repository-states/present.js +++ b/lib/models/repository-states/present.js @@ -120,8 +120,6 @@ export default class Present extends State { if (filePathEndsWith(fullPath, '.git', 'index')) { keys.add(Keys.stagedChanges); - // todo: stagedChangesSinceParentCommit appears to be dead code and can be removed - keys.add(Keys.stagedChangesSinceParentCommit); keys.add(Keys.filePatch.all); keys.add(Keys.index.all); keys.add(Keys.statusBundle); @@ -348,7 +346,6 @@ export default class Present extends State { () => [ Keys.statusBundle, Keys.stagedChanges, - Keys.stagedChangesSinceParentCommit, Keys.filePatch.all, Keys.index.all, ], @@ -371,7 +368,6 @@ export default class Present extends State { return this.invalidate( () => [ Keys.statusBundle, - Keys.stagedChangesSinceParentCommit, Keys.stagedChanges, ...Keys.filePatch.eachWithFileOpts([filePath], [{staged: false}, {staged: true}]), Keys.index.oneWith(filePath), @@ -386,7 +382,6 @@ export default class Present extends State { return this.invalidate( () => [ Keys.stagedChanges, - Keys.stagedChangesSinceParentCommit, Keys.lastCommit, Keys.recentCommits, Keys.authors, @@ -408,7 +403,6 @@ export default class Present extends State { () => [ Keys.statusBundle, Keys.stagedChanges, - Keys.stagedChangesSinceParentCommit, ...paths.map(fileName => Keys.index.oneWith(fileName)), ...Keys.filePatch.eachWithFileOpts(paths, [{staged: true}]), ], @@ -421,7 +415,6 @@ export default class Present extends State { undoLastCommit() { return this.invalidate( () => [ - Keys.stagedChangesSinceParentCommit, Keys.lastCommit, Keys.recentCommits, Keys.authors, @@ -1036,8 +1029,6 @@ const Keys = { stagedChanges: new CacheKey('staged-changes'), - stagedChangesSinceParentCommit: new CacheKey('staged-changes-since-parent-commit'), - filePatch: { _optKey: ({staged}) => { return staged ? 's' : 'u'; @@ -1116,12 +1107,10 @@ const Keys = { ...Keys.filePatch.eachWithFileOpts(fileNames, [{staged: true}]), ...fileNames.map(Keys.index.oneWith), Keys.stagedChanges, - Keys.stagedChangesSinceParentCommit, ], headOperationKeys: () => [ ...Keys.filePatch.eachWithOpts({staged: true}), - Keys.stagedChangesSinceParentCommit, Keys.lastCommit, Keys.recentCommits, Keys.authors, From 44d297167812c4a69dbdeb5516c679a67774d7b8 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 15 Nov 2018 19:33:54 -0500 Subject: [PATCH 038/106] Use `path.sep` to join dirname and basename --- lib/views/file-patch-header-view.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/views/file-patch-header-view.js b/lib/views/file-patch-header-view.js index b157e70230..8f7db7d8e2 100644 --- a/lib/views/file-patch-header-view.js +++ b/lib/views/file-patch-header-view.js @@ -63,11 +63,9 @@ export default class FilePatchHeaderView extends React.Component { if (dirname === '.') { return {basename}; } else { - // TODO: double check that the forward-slash works cross-platform... - // iirc git always uses `/` for paths, even on Windows return ( - {dirname}/{basename} + {dirname}{path.sep}{basename} ); } From 10b661cdbf0edb52197333cc5064294cd4d391d4 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 15 Nov 2018 22:11:35 -0500 Subject: [PATCH 039/106] Avoid double "\\ No newline at end of file" --- lib/git-shell-out-strategy.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/git-shell-out-strategy.js b/lib/git-shell-out-strategy.js index 19b422f502..25d0122a32 100644 --- a/lib/git-shell-out-strategy.js +++ b/lib/git-shell-out-strategy.js @@ -1079,11 +1079,13 @@ export default class GitShellOutStrategy { function buildAddedFilePatch(filePath, contents, mode, realpath) { const hunks = []; if (contents) { - const noNewLine = contents[contents.length - 1] !== '\n'; + let noNewLine; let lines; if (mode === File.modes.SYMLINK) { + noNewLine = false; lines = [`+${toGitPathSep(realpath)}`, '\\ No newline at end of file']; } else { + noNewLine = contents[contents.length - 1] !== '\n'; lines = contents.trim().split(LINE_ENDING_REGEX).map(line => `+${line}`); } if (noNewLine) { lines.push('\\ No newline at end of file'); } From 7d552e9a2c0407205ea7fc48b78e8b517fa6131c Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 15 Nov 2018 22:11:45 -0500 Subject: [PATCH 040/106] Skip filesystem events with no path --- lib/models/repository-states/present.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/models/repository-states/present.js b/lib/models/repository-states/present.js index 7ef7879840..cc3ef01db9 100644 --- a/lib/models/repository-states/present.js +++ b/lib/models/repository-states/present.js @@ -184,6 +184,10 @@ export default class Present extends State { for (let i = 0; i < events.length; i++) { const event = events[i]; + if (!event.path) { + continue; + } + if (filePathEndsWith(event.path, '.git', 'MERGE_HEAD')) { if (event.action === 'created') { if (this.isCommitMessageClean()) { From ad8c198350fd4fe8378c901c462475717fb201cf Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 15 Nov 2018 22:12:38 -0500 Subject: [PATCH 041/106] Remove unnecessary --- lib/views/multi-file-patch-view.js | 39 ++++++++++++++---------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/views/multi-file-patch-view.js b/lib/views/multi-file-patch-view.js index f94658c2bf..65dd925e12 100644 --- a/lib/views/multi-file-patch-view.js +++ b/lib/views/multi-file-patch-view.js @@ -308,27 +308,24 @@ export default class MultiFilePatchView extends React.Component { - - - 0} - hasUndoHistory={this.props.hasUndoHistory} - hasMultipleFileSelections={this.props.hasMultipleFileSelections} - - tooltips={this.props.tooltips} - - undoLastDiscard={() => this.undoLastDiscardFromButton(filePatch)} - diveIntoMirrorPatch={() => this.props.diveIntoMirrorPatch(filePatch)} - openFile={() => this.didOpenFile({selectedFilePatch: filePatch})} - toggleFile={() => this.props.toggleFile(filePatch)} - /> - {this.renderExecutableModeChangeMeta(filePatch)} - {this.renderSymlinkChangeMeta(filePatch)} - + 0} + hasUndoHistory={this.props.hasUndoHistory} + hasMultipleFileSelections={this.props.hasMultipleFileSelections} + + tooltips={this.props.tooltips} + + undoLastDiscard={() => this.undoLastDiscardFromButton(filePatch)} + diveIntoMirrorPatch={() => this.props.diveIntoMirrorPatch(filePatch)} + openFile={() => this.didOpenFile({selectedFilePatch: filePatch})} + toggleFile={() => this.props.toggleFile(filePatch)} + /> + {this.renderSymlinkChangeMeta(filePatch)} + {this.renderExecutableModeChangeMeta(filePatch)} From 6e9699723df1de9693d1d3286dc46be426ed27f2 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 15 Nov 2018 22:12:53 -0500 Subject: [PATCH 042/106] Wait for new unstaged patch to arrive --- test/integration/file-patch.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/integration/file-patch.test.js b/test/integration/file-patch.test.js index 9cd3dfdcde..7cd7d714a8 100644 --- a/test/integration/file-patch.test.js +++ b/test/integration/file-patch.test.js @@ -511,6 +511,12 @@ describe('integration: file patches', function() { getPatchEditor('unstaged', 'sample.js').selectAll(); getPatchItem('unstaged', 'sample.js').find('.github-HunkHeaderView-stageButton').simulate('click'); + await patchContent( + 'unstaged', 'sample.js', + [repoPath('target.txt'), 'selected'], + [' No newline at end of file'], + ); + assert.isTrue(getPatchItem('unstaged', 'sample.js').find('.github-FilePatchView-metaTitle').exists()); await clickFileInGitTab('staged', 'sample.js'); From c44901285fd5aefa0f22ab12df2419eee1b2b92f Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Thu, 15 Nov 2018 22:39:30 -0500 Subject: [PATCH 043/106] Adapt the expected path separator to the current platform --- test/views/file-patch-header-view.test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/views/file-patch-header-view.test.js b/test/views/file-patch-header-view.test.js index 8e8d514e66..6dae9a60a1 100644 --- a/test/views/file-patch-header-view.test.js +++ b/test/views/file-patch-header-view.test.js @@ -1,10 +1,12 @@ import React from 'react'; import {shallow} from 'enzyme'; +import path from 'path'; import FilePatchHeaderView from '../../lib/views/file-patch-header-view'; import ChangedFileItem from '../../lib/items/changed-file-item'; describe('FilePatchHeaderView', function() { + const relPath = path.join('dir', 'a.txt'); let atomEnv; beforeEach(function() { @@ -19,7 +21,7 @@ describe('FilePatchHeaderView', function() { return ( Date: Thu, 15 Nov 2018 22:42:54 -0500 Subject: [PATCH 044/106] Default itemType to avoid the PropTypes warning --- test/views/file-patch-header-view.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/views/file-patch-header-view.test.js b/test/views/file-patch-header-view.test.js index 6dae9a60a1..2d4e0acb65 100644 --- a/test/views/file-patch-header-view.test.js +++ b/test/views/file-patch-header-view.test.js @@ -4,6 +4,7 @@ import path from 'path'; import FilePatchHeaderView from '../../lib/views/file-patch-header-view'; import ChangedFileItem from '../../lib/items/changed-file-item'; +import CommitPreviewItem from '../../lib/items/commit-preview-item'; describe('FilePatchHeaderView', function() { const relPath = path.join('dir', 'a.txt'); @@ -20,7 +21,7 @@ describe('FilePatchHeaderView', function() { function buildApp(overrideProps = {}) { return ( Date: Thu, 15 Nov 2018 16:35:03 -0800 Subject: [PATCH 045/106] Workspace item watcher only cares about active items So we can drop the option, and rename the class --- lib/controllers/commit-controller.js | 1 - lib/watch-workspace-item.js | 7 +++---- test/watch-workspace-item.test.js | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/controllers/commit-controller.js b/lib/controllers/commit-controller.js index f74e936503..94175cbe66 100644 --- a/lib/controllers/commit-controller.js +++ b/lib/controllers/commit-controller.js @@ -60,7 +60,6 @@ export default class CommitController extends React.Component { CommitPreviewItem.buildURI(this.props.repository.getWorkingDirectoryPath()), this, 'commitPreviewActive', - {active: true}, ); this.subscriptions.add(this.previewWatcher); } diff --git a/lib/watch-workspace-item.js b/lib/watch-workspace-item.js index fafe8028a8..bff7714121 100644 --- a/lib/watch-workspace-item.js +++ b/lib/watch-workspace-item.js @@ -2,13 +2,12 @@ import {CompositeDisposable} from 'atom'; import URIPattern from './atom/uri-pattern'; -class ActiveItemWatcher { - constructor(workspace, pattern, component, stateKey, opts) { +class ItemWatcher { + constructor(workspace, pattern, component, stateKey) { this.workspace = workspace; this.pattern = pattern instanceof URIPattern ? pattern : new URIPattern(pattern); this.component = component; this.stateKey = stateKey; - this.opts = opts; this.activeItem = this.isActiveItem(); this.subs = new CompositeDisposable(); @@ -67,7 +66,7 @@ class ActiveItemWatcher { } export function watchWorkspaceItem(workspace, pattern, component, stateKey) { - return new ActiveItemWatcher(workspace, pattern, component, stateKey) + return new ItemWatcher(workspace, pattern, component, stateKey) .setInitialState() .subscribeToWorkspace(); } diff --git a/test/watch-workspace-item.test.js b/test/watch-workspace-item.test.js index f233f0ca40..1df9ca25c9 100644 --- a/test/watch-workspace-item.test.js +++ b/test/watch-workspace-item.test.js @@ -67,14 +67,14 @@ describe('watchWorkspaceItem', function() { assert.isTrue(component.state.theKey); }); - it('is true when the pane is open and active in any pane', async function() { + it.only('is true when the pane is open and active in any pane', async function() { await workspace.open('atom-github://some-item', {location: 'right'}); await workspace.open('atom-github://nonmatching'); assert.strictEqual(workspace.getRightDock().getActivePaneItem().getURI(), 'atom-github://some-item'); assert.strictEqual(workspace.getActivePaneItem().getURI(), 'atom-github://nonmatching'); - sub = watchWorkspaceItem(workspace, 'atom-github://some-item', component, 'someKey', {active: true}); + sub = watchWorkspaceItem(workspace, 'atom-github://some-item', component, 'someKey'); assert.isTrue(component.state.someKey); }); From 399e3f3e9dc7721c2531c06c44f4f0bfe6730022 Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 15 Nov 2018 16:58:55 -0800 Subject: [PATCH 046/106] :fire: props that aren't used in `CommitPreviewItem` --- lib/controllers/root-controller.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/controllers/root-controller.js b/lib/controllers/root-controller.js index 6fd7dbb3ac..e1f73588de 100644 --- a/lib/controllers/root-controller.js +++ b/lib/controllers/root-controller.js @@ -355,9 +355,6 @@ export default class RootController extends React.Component { keymaps={this.props.keymaps} tooltips={this.props.tooltips} config={this.props.config} - discardLines={this.discardLines} - undoLastDiscard={this.undoLastDiscard} - surfaceFileAtPath={this.surfaceFromFileAtPath} /> )}
From 7fc9da2bf868aa556c72b50c37b15539004c983f Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 15 Nov 2018 16:59:24 -0800 Subject: [PATCH 047/106] :fire: mysterious handleClick prop in MultiFilePatchController --- lib/controllers/multi-file-patch-controller.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/controllers/multi-file-patch-controller.js b/lib/controllers/multi-file-patch-controller.js index 6df6e91821..d5d0c25425 100644 --- a/lib/controllers/multi-file-patch-controller.js +++ b/lib/controllers/multi-file-patch-controller.js @@ -25,7 +25,6 @@ export default class MultiFilePatchController extends React.Component { discardLines: PropTypes.func, undoLastDiscard: PropTypes.func, surfaceFileAtPath: PropTypes.func, - handleClick: PropTypes.func, } constructor(props) { From 699199a6dbab2e4eb8a891aab4cb473cf14d1403 Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 15 Nov 2018 18:28:52 -0800 Subject: [PATCH 048/106] Invalidate `stagedChanges` key when undoing last commit or head moves --- lib/models/repository-states/present.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/models/repository-states/present.js b/lib/models/repository-states/present.js index cc3ef01db9..a9f9691a2a 100644 --- a/lib/models/repository-states/present.js +++ b/lib/models/repository-states/present.js @@ -419,6 +419,7 @@ export default class Present extends State { undoLastCommit() { return this.invalidate( () => [ + Keys.stagedChanges, Keys.lastCommit, Keys.recentCommits, Keys.authors, @@ -1115,6 +1116,7 @@ const Keys = { headOperationKeys: () => [ ...Keys.filePatch.eachWithOpts({staged: true}), + Keys.stagedChanges, Keys.lastCommit, Keys.recentCommits, Keys.authors, From 2387ce9aaf9b0c53dd1b90d3845f0b25b3e3768d Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 15 Nov 2018 19:39:11 -0800 Subject: [PATCH 049/106] :fire: useEditorAutoHeight since we are now using a single editor --- lib/views/multi-file-patch-view.js | 6 ------ test/views/multi-file-patch-view.test.js | 9 --------- 2 files changed, 15 deletions(-) diff --git a/lib/views/multi-file-patch-view.js b/lib/views/multi-file-patch-view.js index 65dd925e12..2cc6f06acc 100644 --- a/lib/views/multi-file-patch-view.js +++ b/lib/views/multi-file-patch-view.js @@ -39,7 +39,6 @@ export default class MultiFilePatchView extends React.Component { hasMultipleFileSelections: PropTypes.bool.isRequired, repository: PropTypes.object.isRequired, hasUndoHistory: PropTypes.bool, - useEditorAutoHeight: PropTypes.bool, workspace: PropTypes.object.isRequired, commands: PropTypes.object.isRequired, @@ -63,10 +62,6 @@ export default class MultiFilePatchView extends React.Component { itemType: PropTypes.oneOf([ChangedFileItem, CommitPreviewItem]).isRequired, } - static defaultProps = { - useEditorAutoHeight: false, - } - constructor(props) { super(props); autobind( @@ -236,7 +231,6 @@ export default class MultiFilePatchView extends React.Component { buffer={this.props.multiFilePatch.getBuffer()} lineNumberGutterVisible={false} autoWidth={false} - autoHeight={this.props.useEditorAutoHeight} readOnly={true} softWrapped={true} diff --git a/test/views/multi-file-patch-view.test.js b/test/views/multi-file-patch-view.test.js index 021a1b055b..11cf5037c2 100644 --- a/test/views/multi-file-patch-view.test.js +++ b/test/views/multi-file-patch-view.test.js @@ -137,15 +137,6 @@ describe('MultiFilePatchView', function() { assert.strictEqual(editor.instance().getModel().getText(), filePatches.getBuffer().getText()); }); - it('enables autoHeight on the editor when requested', function() { - const wrapper = mount(buildApp({useEditorAutoHeight: true})); - - assert.isTrue(wrapper.find('AtomTextEditor').prop('autoHeight')); - - wrapper.setProps({useEditorAutoHeight: false}); - assert.isFalse(wrapper.find('AtomTextEditor').prop('autoHeight')); - }); - it('sets the root class when in hunk selection mode', function() { const wrapper = shallow(buildApp({selectionMode: 'line'})); assert.isFalse(wrapper.find('.github-FilePatchView--hunkMode').exists()); From 80d7bfc0b6d6256f31137262cae01648fcaec29d Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 15 Nov 2018 20:02:22 -0800 Subject: [PATCH 050/106] Actually we want autoHeight set to false on AtomTextEditor --- lib/views/multi-file-patch-view.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/views/multi-file-patch-view.js b/lib/views/multi-file-patch-view.js index 2cc6f06acc..16399a227d 100644 --- a/lib/views/multi-file-patch-view.js +++ b/lib/views/multi-file-patch-view.js @@ -231,6 +231,7 @@ export default class MultiFilePatchView extends React.Component { buffer={this.props.multiFilePatch.getBuffer()} lineNumberGutterVisible={false} autoWidth={false} + autoHeight={false} readOnly={true} softWrapped={true} From 1e002b0f7b5d6ac0a1c87ffb206523a160027345 Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 15 Nov 2018 21:13:08 -0800 Subject: [PATCH 051/106] :fire: .only --- test/watch-workspace-item.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/watch-workspace-item.test.js b/test/watch-workspace-item.test.js index 1df9ca25c9..0d63a4c95d 100644 --- a/test/watch-workspace-item.test.js +++ b/test/watch-workspace-item.test.js @@ -67,7 +67,7 @@ describe('watchWorkspaceItem', function() { assert.isTrue(component.state.theKey); }); - it.only('is true when the pane is open and active in any pane', async function() { + it('is true when the pane is open and active in any pane', async function() { await workspace.open('atom-github://some-item', {location: 'right'}); await workspace.open('atom-github://nonmatching'); From aecae83a8558ddf140c4f068185b2a24db921e3f Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Fri, 16 Nov 2018 15:48:57 +0100 Subject: [PATCH 052/106] =?UTF-8?q?=F0=9F=93=9D=20comment=20for=20`interse?= =?UTF-8?q?ctRows`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/models/patch/region.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/models/patch/region.js b/lib/models/patch/region.js index f08901772f..3afaef844d 100644 --- a/lib/models/patch/region.js +++ b/lib/models/patch/region.js @@ -25,6 +25,16 @@ class Region { return this.getRange().intersectsRow(row); } + /* + * intersectRows breaks a Region into runs of rows that are included in + * rowSet and rows that are not. For example: + * @this Region row 10-20 + * @param rowSet row 11, 12, 13, 17, 19 + * @param includeGaps true (whether the result will include gaps or not) + * @return an array of regions like this: + * (10, gap = true) (11, 12, 13, gap = false) (14, 15, 16, gap = true) + * (17, gap = false) (18, gap = true) (19, gap = false) (20, gap = true) + */ intersectRows(rowSet, includeGaps) { const intersections = []; let withinIntersection = false; From 8fd80028e62da40692fb3423017f65d9ae8ada73 Mon Sep 17 00:00:00 2001 From: Tilde Ann Thurium Date: Fri, 16 Nov 2018 08:57:48 -0800 Subject: [PATCH 053/106] :fire: unnecessary button class name `btn-secondary` does nothing --- lib/views/commit-view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/views/commit-view.js b/lib/views/commit-view.js index fdfa143ef4..de83bee13f 100644 --- a/lib/views/commit-view.js +++ b/lib/views/commit-view.js @@ -164,7 +164,7 @@ export default class CommitView extends React.Component {
diff --git a/styles/file-patch-view.less b/styles/file-patch-view.less index 7f3f9f21ac..3de411746a 100644 --- a/styles/file-patch-view.less +++ b/styles/file-patch-view.less @@ -98,10 +98,11 @@ } // Meta section + // Used for mode changes &-meta { - padding: @component-padding; - border-bottom: 1px solid @base-border-color; + font-family: @font-family; + padding-top: @component-padding; } &-metaContainer { @@ -112,15 +113,14 @@ &-metaHeader { display: flex; align-items: center; - padding: @component-padding / 2; - background-color: @background-color-highlight; + font-size: .9em; + border-bottom: 1px solid @base-border-color; } &-metaTitle { flex: 1; margin: 0; - font-size: 1.0em; - line-height: 1.5; + padding-left: @component-padding; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; @@ -128,14 +128,25 @@ &-metaControls { margin-left: @component-padding; + } - .btn { - &.icon-move-up::before, - &.icon-move-down::before { - font-size: 1em; - margin-right: .5em; - vertical-align: baseline; - } + &-metaButton { + line-height: 1.9; // Magic number to match the hunk height + padding-left: @component-padding; + padding-right: @component-padding; + font-family: @font-family; + border: none; + border-left: 1px solid @base-border-color; + background-color: transparent; + cursor: default; + &:hover { background-color: mix(@syntax-text-color, @syntax-background-color, 4%); } + &:active { background-color: mix(@syntax-text-color, @syntax-background-color, 2%); } + + &.icon-move-up::before, + &.icon-move-down::before { + font-size: 1em; + margin-right: .25em; + vertical-align: baseline; } } From 978ef15e4bfac2088531030c0d044b560bab7ad9 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Fri, 16 Nov 2018 15:00:37 +0100 Subject: [PATCH 098/106] just press the button --- test/models/patch/patch.test.js | 35 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/test/models/patch/patch.test.js b/test/models/patch/patch.test.js index 12257a6017..5deb1e599f 100644 --- a/test/models/patch/patch.test.js +++ b/test/models/patch/patch.test.js @@ -260,21 +260,26 @@ describe.only('Patch', function() { }); it('returns a modification patch if original patch is a deletion', function() { - const buffer = new TextBuffer({text: 'line-0\nline-1\nline-2\nline-3\nline-4\nline-5\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, oldRowCount: 5, newStartRow: 1, newRowCount: 0, - sectionHeading: 'zero', - marker: markRange(layers.hunk, 0, 5), - regions: [ - new Deletion(markRange(layers.deletion, 0, 5)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 5); - - const patch = new Patch({status: 'deleted', hunks, marker}); + // const buffer = new TextBuffer({text: 'line-0\nline-1\nline-2\nline-3\nline-4\nline-5\n'}); + // const layers = buildLayers(buffer); + // const hunks = [ + // new Hunk({ + // oldStartRow: 1, oldRowCount: 5, newStartRow: 1, newRowCount: 0, + // sectionHeading: 'zero', + // marker: markRange(layers.hunk, 0, 5), + // regions: [ + // new Deletion(markRange(layers.deletion, 0, 5)), + // ], + // }), + // ]; + // const marker = markRange(layers.patch, 0, 5); + + // const patch = new Patch({status: 'deleted', hunks, marker}); + const {buffer, patch} = patchBuilder().status('deleted').addHunk( + h => h.oldRow(1).deleted('line-0', 'line-1', 'line-2', 'line-3', 'line-4', 'line-5'), + ).build(); + + console.log(patch) const stagedPatch = patch.buildStagePatchForLines(buffer, stageLayeredBuffer, new Set([1, 3, 4])); assert.strictEqual(stagedPatch.getStatus(), 'modified'); From a56ad3b2cfeb8be673e101e1e7bf753300d67ae4 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Wed, 21 Nov 2018 22:29:28 +0100 Subject: [PATCH 099/106] add empty method to hunkbuilder --- test/builder/patch.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/builder/patch.js b/test/builder/patch.js index 18ff5067b5..a7691eb64e 100644 --- a/test/builder/patch.js +++ b/test/builder/patch.js @@ -237,6 +237,7 @@ class HunkBuilder { this.newRowCount = null; this.sectionHeading = "don't care"; + this.explicitlyEmpty = false; this.hunkStartPoint = this.layeredBuffer.getInsertionPoint(); this.regions = []; @@ -267,8 +268,13 @@ class HunkBuilder { return this; } + empty() { + this.explicitlyEmpty = true; + return this; + } + build() { - if (this.regions.length === 0) { + if (this.regions.length === 0 && !this.explicitlyEmpty) { this.unchanged('0000').added('0001').deleted('0002').unchanged('0003'); } From 1a2b80fad12fa071375f160a73a786e2dd5c4ff9 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Wed, 21 Nov 2018 22:57:09 +0100 Subject: [PATCH 100/106] finish up patch test --- test/models/patch/patch.test.js | 139 +++++--------------------------- 1 file changed, 20 insertions(+), 119 deletions(-) diff --git a/test/models/patch/patch.test.js b/test/models/patch/patch.test.js index 5deb1e599f..07219f6835 100644 --- a/test/models/patch/patch.test.js +++ b/test/models/patch/patch.test.js @@ -260,34 +260,17 @@ describe.only('Patch', function() { }); it('returns a modification patch if original patch is a deletion', function() { - // const buffer = new TextBuffer({text: 'line-0\nline-1\nline-2\nline-3\nline-4\nline-5\n'}); - // const layers = buildLayers(buffer); - // const hunks = [ - // new Hunk({ - // oldStartRow: 1, oldRowCount: 5, newStartRow: 1, newRowCount: 0, - // sectionHeading: 'zero', - // marker: markRange(layers.hunk, 0, 5), - // regions: [ - // new Deletion(markRange(layers.deletion, 0, 5)), - // ], - // }), - // ]; - // const marker = markRange(layers.patch, 0, 5); - - // const patch = new Patch({status: 'deleted', hunks, marker}); const {buffer, patch} = patchBuilder().status('deleted').addHunk( h => h.oldRow(1).deleted('line-0', 'line-1', 'line-2', 'line-3', 'line-4', 'line-5'), ).build(); - console.log(patch) - const stagedPatch = patch.buildStagePatchForLines(buffer, stageLayeredBuffer, new Set([1, 3, 4])); assert.strictEqual(stagedPatch.getStatus(), 'modified'); assertInPatch(stagedPatch, stageLayeredBuffer.buffer).hunks( { startRow: 0, endRow: 5, - header: '@@ -1,5 +1,3 @@', + header: '@@ -1,6 +1,3 @@', regions: [ {kind: 'unchanged', string: ' line-0\n', range: [[0, 0], [0, 6]]}, {kind: 'deletion', string: '-line-1\n', range: [[1, 0], [1, 6]]}, @@ -300,19 +283,9 @@ describe.only('Patch', function() { }); it('returns an deletion when staging an entire deletion patch', function() { - const buffer = new TextBuffer({text: '0000\n0001\n0002\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, oldRowCount: 3, newStartRow: 1, newRowCount: 0, - marker: markRange(layers.hunk, 0, 2), - regions: [ - new Deletion(markRange(layers.deletion, 0, 2)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 2); - const patch = new Patch({status: 'deleted', hunks, marker}); + const {patch, buffer} = patchBuilder().status('deleted').addHunk( + h => h.deleted('0000', '0001', '0002'), + ).build(); const stagePatch0 = patch.buildStagePatchForLines(buffer, stageLayeredBuffer, new Set([0, 1, 2])); assert.strictEqual(stagePatch0.getStatus(), 'deleted'); @@ -466,19 +439,9 @@ describe.only('Patch', function() { }); it('returns a modification if original patch is an addition', function() { - const buffer = new TextBuffer({text: '0000\n0001\n0002\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, oldRowCount: 0, newStartRow: 1, newRowCount: 3, - marker: markRange(layers.hunk, 0, 2), - regions: [ - new Addition(markRange(layers.addition, 0, 2)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 2); - const patch = new Patch({status: 'added', hunks, marker}); + const {patch, buffer} = patchBuilder().status('added').addHunk( + h => h.oldRow(1).added('0000', '0001', '0002'), + ).build(); const unstagePatch = patch.buildUnstagePatchForLines(buffer, unstageLayeredBuffer, new Set([1, 2])); assert.strictEqual(unstagePatch.getStatus(), 'modified'); assert.strictEqual(unstageLayeredBuffer.buffer.getText(), '0000\n0001\n0002\n'); @@ -496,44 +459,18 @@ describe.only('Patch', function() { }); it('returns a deletion when unstaging an entire addition patch', function() { - const buffer = new TextBuffer({text: '0000\n0001\n0002\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, - oldRowCount: 0, - newStartRow: 1, - newRowCount: 3, - marker: markRange(layers.hunk, 0, 2), - regions: [ - new Addition(markRange(layers.addition, 0, 2)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 2); - const patch = new Patch({status: 'added', hunks, marker}); + const {patch, buffer} = patchBuilder().status('added').addHunk( + h => h.oldRow(1).added('0000', '0001', '0002'), + ).build(); const unstagePatch = patch.buildUnstagePatchForLines(buffer, unstageLayeredBuffer, new Set([0, 1, 2])); assert.strictEqual(unstagePatch.getStatus(), 'deleted'); }); it('returns an addition when unstaging a deletion', function() { - const buffer = new TextBuffer({text: '0000\n0001\n0002\n'}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, - oldRowCount: 0, - newStartRow: 1, - newRowCount: 3, - marker: markRange(layers.hunk, 0, 2), - regions: [ - new Addition(markRange(layers.addition, 0, 2)), - ], - }), - ]; - const marker = markRange(layers.patch, 0, 2); - const patch = new Patch({status: 'deleted', hunks, marker}); + const {patch, buffer} = patchBuilder().status('deleted').addHunk( + h => h.oldRow(1).added('0000', '0001', '0002'), + ).build(); const unstagePatch = patch.buildUnstagePatchForLines(buffer, unstageLayeredBuffer, new Set([0, 1, 2])); assert.strictEqual(unstagePatch.getStatus(), 'added'); @@ -552,57 +489,21 @@ describe.only('Patch', function() { }); it('returns the origin if the first hunk is empty', function() { - const buffer = new TextBuffer({text: ''}); - const layers = buildLayers(buffer); - const hunks = [ - new Hunk({ - oldStartRow: 1, oldRowCount: 0, newStartRow: 1, newRowCount: 0, - marker: markRange(layers.hunk, 0), - regions: [], - }), - ]; - const marker = markRange(layers.patch, 0); - const patch = new Patch({status: 'modified', hunks, marker}); + const {patch} = patchBuilder().addHunk(h => h.empty()).build(); assert.deepEqual(patch.getFirstChangeRange().serialize(), [[0, 0], [0, 0]]); }); it('returns the origin if the patch is empty', function() { - const buffer = new TextBuffer({text: ''}); - const layers = buildLayers(buffer); - const marker = markRange(layers.patch, 0); - const patch = new Patch({status: 'modified', hunks: [], marker}); + const {patch} = patchBuilder().empty().build(); assert.deepEqual(patch.getFirstChangeRange().serialize(), [[0, 0], [0, 0]]); }); }); it('prints itself as an apply-ready string', function() { - const buffer = buildBuffer(10); - const layers = buildLayers(buffer); - - const hunk0 = new Hunk({ - oldStartRow: 0, newStartRow: 0, oldRowCount: 2, newRowCount: 3, - sectionHeading: 'zero', - marker: markRange(layers.hunk, 0, 2), - regions: [ - new Unchanged(markRange(layers.unchanged, 0)), - new Addition(markRange(layers.addition, 1)), - new Unchanged(markRange(layers.unchanged, 2)), - ], - }); - - const hunk1 = new Hunk({ - oldStartRow: 5, newStartRow: 6, oldRowCount: 4, newRowCount: 2, - sectionHeading: 'one', - marker: markRange(layers.hunk, 6, 9), - regions: [ - new Unchanged(markRange(layers.unchanged, 6)), - new Deletion(markRange(layers.deletion, 7, 8)), - new Unchanged(markRange(layers.unchanged, 9)), - ], - }); - const marker = markRange(layers.patch, 0, 9); - - const p = new Patch({status: 'modified', hunks: [hunk0, hunk1], marker}); + const {patch: p, buffer} = patchBuilder() + .addHunk(h => h.unchanged('0000').added('0001').unchanged('0002')) + .addHunk(h => h.oldRow(5).unchanged('0006').deleted('0007', '0008').unchanged('0009')) + .build(); assert.strictEqual(p.toStringIn(buffer), [ '@@ -0,2 +0,3 @@\n', @@ -617,7 +518,7 @@ describe.only('Patch', function() { ].join('')); }); - it('correctly handles blank lines in added, removed, and unchanged regions', function() { + it.only('correctly handles blank lines in added, removed, and unchanged regions', function() { const buffer = new TextBuffer({text: '\n\n\n\n\n\n'}); const layers = buildLayers(buffer); From 1355b7f969b0b8fa323d76bc232c3ab8c302a974 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Wed, 21 Nov 2018 22:57:30 +0100 Subject: [PATCH 101/106] remove unused helper method --- test/models/patch/patch.test.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/test/models/patch/patch.test.js b/test/models/patch/patch.test.js index 07219f6835..445f3ca84c 100644 --- a/test/models/patch/patch.test.js +++ b/test/models/patch/patch.test.js @@ -563,24 +563,6 @@ describe.only('Patch', function() { }); }); -function buildBuffer(lines, noNewline = false) { - const buffer = new TextBuffer(); - for (let i = 0; i < lines; i++) { - const iStr = i.toString(10); - let padding = ''; - for (let p = iStr.length; p < 4; p++) { - padding += '0'; - } - buffer.append(padding); - buffer.append(iStr); - buffer.append('\n'); - } - if (noNewline) { - buffer.append(' No newline at end of file\n'); - } - return buffer; -} - function buildLayers(buffer) { return { patch: buffer.addMarkerLayer(), From 53ea203e3f24f4ace74053378192b1454366da3d Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Wed, 21 Nov 2018 23:02:12 +0100 Subject: [PATCH 102/106] =?UTF-8?q?=F0=9F=94=A5=20`.only`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/models/patch/patch.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/models/patch/patch.test.js b/test/models/patch/patch.test.js index 445f3ca84c..c15ce364b4 100644 --- a/test/models/patch/patch.test.js +++ b/test/models/patch/patch.test.js @@ -2,11 +2,11 @@ import {TextBuffer} from 'atom'; import Patch from '../../../lib/models/patch/patch'; import Hunk from '../../../lib/models/patch/hunk'; -import {Unchanged, Addition, Deletion, NoNewline} from '../../../lib/models/patch/region'; +import {Unchanged, Addition, Deletion} from '../../../lib/models/patch/region'; import {patchBuilder} from '../../builder/patch'; import {assertInPatch} from '../../helpers'; -describe.only('Patch', function() { +describe('Patch', function() { it('has some standard accessors', function() { const buffer = new TextBuffer({text: 'bufferText'}); const layers = buildLayers(buffer); @@ -518,7 +518,7 @@ describe.only('Patch', function() { ].join('')); }); - it.only('correctly handles blank lines in added, removed, and unchanged regions', function() { + it('correctly handles blank lines in added, removed, and unchanged regions', function() { const buffer = new TextBuffer({text: '\n\n\n\n\n\n'}); const layers = buildLayers(buffer); From 2add2b3b95b65ac47977e618621dbe34be903128 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 22 Nov 2018 18:57:27 +0100 Subject: [PATCH 103/106] this test doesn't work :/ --- test/models/patch/patch.test.js | 40 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/test/models/patch/patch.test.js b/test/models/patch/patch.test.js index c15ce364b4..0ed7fae11b 100644 --- a/test/models/patch/patch.test.js +++ b/test/models/patch/patch.test.js @@ -519,24 +519,28 @@ describe('Patch', function() { }); it('correctly handles blank lines in added, removed, and unchanged regions', function() { - const buffer = new TextBuffer({text: '\n\n\n\n\n\n'}); - const layers = buildLayers(buffer); - - const hunk = new Hunk({ - oldStartRow: 1, oldRowCount: 5, newStartRow: 1, newRowCount: 5, - sectionHeading: 'only', - marker: markRange(layers.hunk, 0, 5), - regions: [ - new Unchanged(markRange(layers.unchanged, 0, 1)), - new Addition(markRange(layers.addition, 1, 2)), - new Deletion(markRange(layers.deletion, 3, 4)), - new Unchanged(markRange(layers.unchanged, 5)), - ], - }); - const marker = markRange(layers.patch, 0, 5); - - const p = new Patch({status: 'modified', hunks: [hunk], marker}); - assert.strictEqual(p.toStringIn(buffer), [ + // const buffer = new TextBuffer({text: '\n\n\n\n\n\n'}); + // const layers = buildLayers(buffer); + // + // const hunk = new Hunk({ + // oldStartRow: 1, oldRowCount: 5, newStartRow: 1, newRowCount: 5, + // sectionHeading: 'only', + // marker: markRange(layers.hunk, 0, 5), + // regions: [ + // new Unchanged(markRange(layers.unchanged, 0, 1)), + // new Addition(markRange(layers.addition, 1, 2)), + // new Deletion(markRange(layers.deletion, 3, 4)), + // new Unchanged(markRange(layers.unchanged, 5)), + // ], + // }); + // const marker = markRange(layers.patch, 0, 5); + // + // const p = new Patch({status: 'modified', hunks: [hunk], marker}); + const {patch, buffer} = patchBuilder().addHunk( + h => h.oldRow(1).unchanged('', '').added('', '').deleted('', '').unchanged(''), + ).build(); + + assert.strictEqual(patch.toStringIn(buffer), [ '@@ -1,5 +1,5 @@\n', ' \n', ' \n', From a067c40a0ff88c6b13db028b10f776f0d226dcc8 Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 31 Jan 2019 20:21:24 +0100 Subject: [PATCH 104/106] put the original test back in --- test/models/patch/patch.test.js | 41 +++++++++++++++------------------ 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/test/models/patch/patch.test.js b/test/models/patch/patch.test.js index 0ed7fae11b..c906f5a876 100644 --- a/test/models/patch/patch.test.js +++ b/test/models/patch/patch.test.js @@ -6,7 +6,7 @@ import {Unchanged, Addition, Deletion} from '../../../lib/models/patch/region'; import {patchBuilder} from '../../builder/patch'; import {assertInPatch} from '../../helpers'; -describe('Patch', function() { +describe.only('Patch', function() { it('has some standard accessors', function() { const buffer = new TextBuffer({text: 'bufferText'}); const layers = buildLayers(buffer); @@ -518,27 +518,24 @@ describe('Patch', function() { ].join('')); }); - it('correctly handles blank lines in added, removed, and unchanged regions', function() { - // const buffer = new TextBuffer({text: '\n\n\n\n\n\n'}); - // const layers = buildLayers(buffer); - // - // const hunk = new Hunk({ - // oldStartRow: 1, oldRowCount: 5, newStartRow: 1, newRowCount: 5, - // sectionHeading: 'only', - // marker: markRange(layers.hunk, 0, 5), - // regions: [ - // new Unchanged(markRange(layers.unchanged, 0, 1)), - // new Addition(markRange(layers.addition, 1, 2)), - // new Deletion(markRange(layers.deletion, 3, 4)), - // new Unchanged(markRange(layers.unchanged, 5)), - // ], - // }); - // const marker = markRange(layers.patch, 0, 5); - // - // const p = new Patch({status: 'modified', hunks: [hunk], marker}); - const {patch, buffer} = patchBuilder().addHunk( - h => h.oldRow(1).unchanged('', '').added('', '').deleted('', '').unchanged(''), - ).build(); + it.only('correctly handles blank lines in added, removed, and unchanged regions', function() { + const buffer = new TextBuffer({text: '\n\n\n\n\n\n'}); + const layers = buildLayers(buffer); + + const hunk = new Hunk({ + oldStartRow: 1, oldRowCount: 5, newStartRow: 1, newRowCount: 5, + sectionHeading: 'only', + marker: markRange(layers.hunk, 0, 5), + regions: [ + new Unchanged(markRange(layers.unchanged, 0, 1)), + new Addition(markRange(layers.addition, 1, 2)), + new Deletion(markRange(layers.deletion, 3, 4)), + new Unchanged(markRange(layers.unchanged, 5)), + ], + }); + const marker = markRange(layers.patch, 0, 5); + + const patch = new Patch({status: 'modified', hunks: [hunk], marker}); assert.strictEqual(patch.toStringIn(buffer), [ '@@ -1,5 +1,5 @@\n', From a02b76d6642ed4a1b6e5a4fc842904617a23e95a Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 31 Jan 2019 20:21:38 +0100 Subject: [PATCH 105/106] fix the startrange test --- test/models/patch/file-patch.test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/models/patch/file-patch.test.js b/test/models/patch/file-patch.test.js index 6cc0a8c449..a19b9484b2 100644 --- a/test/models/patch/file-patch.test.js +++ b/test/models/patch/file-patch.test.js @@ -41,15 +41,14 @@ describe('FilePatch', function() { }); it('returns the starting range of the patch', function() { - const {patch} = patchBuilder().status('modified').addHunk( + const {patch} = patchBuilder().addHunk( h => h.oldRow(2).unchanged('0000').added('0001', '0002'), ).build(); const oldFile = new File({path: 'a.txt', mode: '100644'}); const newFile = new File({path: 'a.txt', mode: '100644'}); const filePatch = new FilePatch(oldFile, newFile, patch); - - assert.deepEqual(filePatch.getStartRange().serialize(), [[1, 0], [1, 0]]); + assert.deepEqual(filePatch.getStartRange().serialize(), [[0, 0], [0, 0]]); }); describe('file-level change detection', function() { From aedcd407b6da6fd86a2ffe62c205bd7e70633e4e Mon Sep 17 00:00:00 2001 From: Vanessa Yuen Date: Thu, 31 Jan 2019 20:22:02 +0100 Subject: [PATCH 106/106] :fire: `.only` --- test/models/patch/patch.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/models/patch/patch.test.js b/test/models/patch/patch.test.js index c906f5a876..d76cd63690 100644 --- a/test/models/patch/patch.test.js +++ b/test/models/patch/patch.test.js @@ -6,7 +6,7 @@ import {Unchanged, Addition, Deletion} from '../../../lib/models/patch/region'; import {patchBuilder} from '../../builder/patch'; import {assertInPatch} from '../../helpers'; -describe.only('Patch', function() { +describe('Patch', function() { it('has some standard accessors', function() { const buffer = new TextBuffer({text: 'bufferText'}); const layers = buildLayers(buffer); @@ -518,7 +518,7 @@ describe.only('Patch', function() { ].join('')); }); - it.only('correctly handles blank lines in added, removed, and unchanged regions', function() { + it('correctly handles blank lines in added, removed, and unchanged regions', function() { const buffer = new TextBuffer({text: '\n\n\n\n\n\n'}); const layers = buildLayers(buffer);