|
| 1 | +const path = require('path'); |
| 2 | +const fs = require('fs-plus'); |
| 3 | +const temp = require('temp').track(); |
| 4 | + |
| 5 | +describe('GitDiff when targeting nested repository', () => { |
| 6 | + let editor, editorElement, projectPath, screenUpdates; |
| 7 | + |
| 8 | + beforeEach(() => { |
| 9 | + screenUpdates = 0; |
| 10 | + spyOn(window, 'requestAnimationFrame').andCallFake(fn => { |
| 11 | + fn(); |
| 12 | + screenUpdates++; |
| 13 | + }); |
| 14 | + spyOn(window, 'cancelAnimationFrame').andCallFake(i => null); |
| 15 | + |
| 16 | + projectPath = temp.mkdirSync('git-diff-spec-'); |
| 17 | + |
| 18 | + fs.copySync(path.join(__dirname, 'fixtures', 'working-dir'), projectPath); |
| 19 | + fs.moveSync( |
| 20 | + path.join(projectPath, 'git.git'), |
| 21 | + path.join(projectPath, '.git') |
| 22 | + ); |
| 23 | + |
| 24 | + // The nested repo doesn't need to be managed by the temp module because |
| 25 | + // it's a part of our test environment. |
| 26 | + const nestedPath = path.join(projectPath, 'nested-repository'); |
| 27 | + // Initialize the repository contents. |
| 28 | + fs.copySync(path.join(__dirname, 'fixtures', 'working-dir'), nestedPath); |
| 29 | + fs.moveSync( |
| 30 | + path.join(nestedPath, 'git.git'), |
| 31 | + path.join(nestedPath, '.git') |
| 32 | + ); |
| 33 | + |
| 34 | + atom.project.setPaths([projectPath]); |
| 35 | + |
| 36 | + jasmine.attachToDOM(atom.workspace.getElement()); |
| 37 | + |
| 38 | + waitsForPromise(async () => { |
| 39 | + await atom.workspace.open(path.join(nestedPath, 'sample.js')); |
| 40 | + await atom.packages.activatePackage('git-diff'); |
| 41 | + }); |
| 42 | + |
| 43 | + runs(() => { |
| 44 | + editor = atom.workspace.getActiveTextEditor(); |
| 45 | + editorElement = atom.views.getView(editor); |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + afterEach(() => { |
| 50 | + temp.cleanup(); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('When git-diff targets a file in a nested git-repository', () => { |
| 54 | + /*** |
| 55 | + * Non-hack regression prevention for nested repositories. If we know |
| 56 | + * that our project path contains two repositories, we can ensure that |
| 57 | + * git-diff is targeting the correct one by creating an artificial change |
| 58 | + * in the ancestor repository, which is percieved differently within the |
| 59 | + * child. In this case, creating a new file will not generate markers in |
| 60 | + * the ancestor repo, even if there are changes; but changes will be |
| 61 | + * marked within the child repo. So all we have to do is check if |
| 62 | + * markers exist and we know we're targeting the proper repository, |
| 63 | + * If no markers exist, we're targeting an ancestor repo. |
| 64 | + */ |
| 65 | + it('uses the innermost repository', () => { |
| 66 | + editor.insertText('a'); |
| 67 | + waitsFor(() => screenUpdates > 0); |
| 68 | + runs(() => { |
| 69 | + expect( |
| 70 | + editorElement.querySelectorAll('.git-line-modified').length |
| 71 | + ).toBe(1); |
| 72 | + }); |
| 73 | + }); |
| 74 | + }); |
| 75 | +}); |
0 commit comments