|
| 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 | + // When instantiating a GitRepository, the repository will always point |
| 28 | + // to the .git folder in it's path. |
| 29 | + const targetRepositoryPath = path.join(nestedPath, '.git'); |
| 30 | + // Initialize the repository contents. |
| 31 | + fs.copySync(path.join(__dirname, 'fixtures', 'working-dir'), nestedPath); |
| 32 | + fs.moveSync( |
| 33 | + path.join(nestedPath, 'git.git'), |
| 34 | + path.join(nestedPath, '.git') |
| 35 | + ); |
| 36 | + |
| 37 | + atom.project.setPaths([projectPath]); |
| 38 | + |
| 39 | + jasmine.attachToDOM(atom.workspace.getElement()); |
| 40 | + |
| 41 | + waitsForPromise(async () => { |
| 42 | + await atom.workspace.open(path.join(nestedPath, 'sample.js')); |
| 43 | + await atom.packages.activatePackage('git-diff'); |
| 44 | + }); |
| 45 | + |
| 46 | + runs(() => { |
| 47 | + editor = atom.workspace.getActiveTextEditor(); |
| 48 | + editorElement = atom.views.getView(editor); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + afterEach(() => { |
| 53 | + temp.cleanup(); |
| 54 | + }); |
| 55 | + |
| 56 | + describe('When git-diff targets a file in a nested git-repository', () => { |
| 57 | + /*** |
| 58 | + * Non-hack regression prevention for nested repositories. If we know |
| 59 | + * that our project path contains two repositories, we can ensure that |
| 60 | + * git-diff is targeting the correct one by creating an artificial change |
| 61 | + * in the ancestor repository, which doesn't effect the target repository. |
| 62 | + * If our diff shows any kind of change to our target file, we're targeting |
| 63 | + * the incorrect repository. |
| 64 | + */ |
| 65 | + it("uses the innermost repository", () => { |
| 66 | + //waitsForPromise(async () => await new Promise(resolve => setTimeout(resolve, 4000))); |
| 67 | + //waitsFor(() => !! atom.packages.isPackageLoaded("git-diff")); |
| 68 | + waitsFor(() => screenUpdates > 0); |
| 69 | + runs(() => expect(editor.getMarkers().length).toBe(0)); |
| 70 | + }); |
| 71 | + }); |
| 72 | +}); |
0 commit comments