diff --git a/simple-git/src/lib/parsers/parse-fetch.ts b/simple-git/src/lib/parsers/parse-fetch.ts index 4cb70a15..7e97c155 100644 --- a/simple-git/src/lib/parsers/parse-fetch.ts +++ b/simple-git/src/lib/parsers/parse-fetch.ts @@ -32,17 +32,17 @@ const parsers: LineParser[] = [ from, }); } - ) + ), ]; -export function parseFetchResult (stdOut: string, stdErr: string): FetchResult { +export function parseFetchResult(stdOut: string, stdErr: string): FetchResult { const result: FetchResult = { raw: stdOut, remote: null, branches: [], tags: [], updated: [], - deleted: [] + deleted: [], }; return parseStringResponse(result, parsers, [stdOut, stdErr]); } diff --git a/simple-git/test/integration/fetch.spec.ts b/simple-git/test/integration/fetch.spec.ts index fd1a9bcf..7801b363 100644 --- a/simple-git/test/integration/fetch.spec.ts +++ b/simple-git/test/integration/fetch.spec.ts @@ -1,11 +1,4 @@ -// ./simple-git/test/integration/fetch.spec.ts - -import { - createTestContext, - newSimpleGit, - setUpInit, - SimpleGitTestContext -} from '../__fixtures__'; +import { createTestContext, newSimpleGit, setUpInit, SimpleGitTestContext } from '../__fixtures__'; describe('fetch', () => { let context: SimpleGitTestContext; @@ -35,8 +28,8 @@ describe('fetch', () => { branches: [ { name: 'delta', - tracking: 'origin/delta' - } + tracking: 'origin/delta', + }, ], deleted: [{ tracking: 'origin/charlie' }], raw: '', @@ -44,17 +37,17 @@ describe('fetch', () => { tags: [ { name: 'alpha', - tracking: 'alpha' - } + tracking: 'alpha', + }, ], updated: [ { from: bravoPriorHead.substring(0, 7), name: 'bravo', to: bravoCurrentHead.substring(0, 7), - tracking: 'origin/bravo' - } - ] + tracking: 'origin/bravo', + }, + ], }); }); diff --git a/simple-git/test/unit/fetch.spec.ts b/simple-git/test/unit/fetch.spec.ts index dcb95bc1..497e7447 100644 --- a/simple-git/test/unit/fetch.spec.ts +++ b/simple-git/test/unit/fetch.spec.ts @@ -1,5 +1,11 @@ import { promiseError } from '@kwsites/promise-result'; -import { assertExecutedCommands, assertGitError, closeWithSuccess, like, newSimpleGit } from './__fixtures__'; +import { + assertExecutedCommands, + assertGitError, + closeWithSuccess, + like, + newSimpleGit, +} from './__fixtures__'; import { SimpleGit } from '../../typings'; import { parseFetchResult } from '../../src/lib/parsers/parse-fetch'; @@ -15,7 +21,7 @@ describe('fetch', () => { it('runs escaped fetch', async () => { const branchPrefix = 'some-name'; const ref = `'refs/heads/${branchPrefix}*:refs/remotes/origin/${branchPrefix}*'`; - git.fetch(`origin`, ref, {'--depth': '2'}, callback); + git.fetch(`origin`, ref, { '--depth': '2' }, callback); await closeWithSuccess(); assertExecutedCommands('fetch', '--depth=2', 'origin', ref); }); @@ -29,11 +35,13 @@ describe('fetch', () => { `); assertExecutedCommands('fetch', '--depth=2', 'foo', 'bar'); - expect(await queue).toEqual(like({ - branches: [{name: 'master', tracking: 'origin/master'}], - remote: 'https://github.com/steveukx/git-js', - tags: [{name: '0.11.0', tracking: '0.11.0'}], - })); + expect(await queue).toEqual( + like({ + branches: [{ name: 'master', tracking: 'origin/master' }], + remote: 'https://github.com/steveukx/git-js', + tags: [{ name: '0.11.0', tracking: '0.11.0' }], + }) + ); }); it('git fetch with remote and branch', async () => { @@ -49,7 +57,7 @@ describe('fetch', () => { }); it('git fetch with options', async () => { - git.fetch({'--all': null}, callback); + git.fetch({ '--all': null }, callback); await closeWithSuccess(); assertExecutedCommands('fetch', '--all'); }); @@ -60,9 +68,7 @@ describe('fetch', () => { assertExecutedCommands('fetch', '--all', '-v'); }); - describe('failures', () => { - it('disallows upload-pack as remote/branch', async () => { const error = await promiseError(git.fetch('origin', '--upload-pack=touch ./foo')); @@ -70,56 +76,66 @@ describe('fetch', () => { }); it('disallows upload-pack as varargs', async () => { - const error = await promiseError(git.fetch('origin', 'main', { - '--upload-pack': 'touch ./foo' - })); + const error = await promiseError( + git.fetch('origin', 'main', { + '--upload-pack': 'touch ./foo', + }) + ); assertGitError(error, 'potential exploit argument blocked'); }); it('disallows upload-pack as varargs', async () => { - const error = await promiseError(git.fetch('origin', 'main', [ - '--upload-pack', 'touch ./foo' - ])); + const error = await promiseError( + git.fetch('origin', 'main', ['--upload-pack', 'touch ./foo']) + ); assertGitError(error, 'potential exploit argument blocked'); }); - }); describe('parser', () => { const REMOTE = '/tmp/x-remote'; it('parses updates', () => { - const result = parseFetchResult(` + const result = parseFetchResult( + ` From ${REMOTE} 7d11f0c..3de1250 main -> origin/main * [new branch] c -> origin/c -`, ''); - - expect(result).toEqual(like({ - remote: REMOTE, - branches: [{name: 'c', tracking: 'origin/c'}], - tags: [], - updated: [{name: 'main', tracking: 'origin/main', from: '7d11f0c', to: '3de1250'}], - deleted: [], - })); +`, + '' + ); + + expect(result).toEqual( + like({ + remote: REMOTE, + branches: [{ name: 'c', tracking: 'origin/c' }], + tags: [], + updated: [{ name: 'main', tracking: 'origin/main', from: '7d11f0c', to: '3de1250' }], + deleted: [], + }) + ); }); it('parses deletes', () => { - const result = parseFetchResult(` + const result = parseFetchResult( + ` From ${REMOTE} - [deleted] (none) -> origin/c -`, ''); - - expect(result).toEqual(like({ - remote: REMOTE, - branches: [], - tags: [], - updated: [], - deleted: [{tracking: 'origin/c'}], - })); +`, + '' + ); + + expect(result).toEqual( + like({ + remote: REMOTE, + branches: [], + tags: [], + updated: [], + deleted: [{ tracking: 'origin/c' }], + }) + ); }); }); - });