Skip to content

Commit

Permalink
Run prettier on merged files
Browse files Browse the repository at this point in the history
  • Loading branch information
steveukx committed Jul 24, 2022
1 parent f53c17a commit 4f19f3b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 56 deletions.
6 changes: 3 additions & 3 deletions simple-git/src/lib/parsers/parse-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ const parsers: LineParser<FetchResult>[] = [
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]);
}
23 changes: 8 additions & 15 deletions simple-git/test/integration/fetch.spec.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,26 +28,26 @@ describe('fetch', () => {
branches: [
{
name: 'delta',
tracking: 'origin/delta'
}
tracking: 'origin/delta',
},
],
deleted: [{ tracking: 'origin/charlie' }],
raw: '',
remote: upstream,
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',
},
],
});
});

Expand Down
92 changes: 54 additions & 38 deletions simple-git/test/unit/fetch.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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);
});
Expand All @@ -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 () => {
Expand All @@ -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');
});
Expand All @@ -60,66 +68,74 @@ 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'));

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');
});

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' }],
})
);
});
});

});

0 comments on commit 4f19f3b

Please sign in to comment.