mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-12 07:42:34 +02:00
fix(v2): read last update from inner git repositories (#5048)
This commit is contained in:
parent
aa79387e12
commit
f47826297c
2 changed files with 13 additions and 8 deletions
|
@ -31,15 +31,16 @@ describe('lastUpdate', () => {
|
||||||
test('non-existing file', async () => {
|
test('non-existing file', async () => {
|
||||||
const consoleMock = jest.spyOn(console, 'error');
|
const consoleMock = jest.spyOn(console, 'error');
|
||||||
consoleMock.mockImplementation();
|
consoleMock.mockImplementation();
|
||||||
|
const nonExistingFileName = '.nonExisting';
|
||||||
const nonExistingFilePath = path.join(
|
const nonExistingFilePath = path.join(
|
||||||
__dirname,
|
__dirname,
|
||||||
'__fixtures__',
|
'__fixtures__',
|
||||||
'.nonExisting',
|
nonExistingFileName,
|
||||||
);
|
);
|
||||||
expect(await getFileLastUpdate(nonExistingFilePath)).toBeNull();
|
expect(await getFileLastUpdate(nonExistingFilePath)).toBeNull();
|
||||||
expect(consoleMock).toHaveBeenCalledTimes(1);
|
expect(consoleMock).toHaveBeenCalledTimes(1);
|
||||||
expect(consoleMock.mock.calls[0][0].message).toContain(
|
expect(consoleMock.mock.calls[0][0].message).toContain(
|
||||||
`Command failed with exit code 128: git log -1 --format=%ct, %an ${nonExistingFilePath}`,
|
`Command failed with exit code 128: git log -1 --format=%ct, %an ${nonExistingFileName}`,
|
||||||
);
|
);
|
||||||
expect(await getFileLastUpdate(null)).toBeNull();
|
expect(await getFileLastUpdate(null)).toBeNull();
|
||||||
expect(await getFileLastUpdate(undefined)).toBeNull();
|
expect(await getFileLastUpdate(undefined)).toBeNull();
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
import shell from 'shelljs';
|
import shell from 'shelljs';
|
||||||
import execa from 'execa';
|
import execa from 'execa';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
type FileLastUpdateData = {timestamp?: number; author?: string};
|
type FileLastUpdateData = {timestamp?: number; author?: string};
|
||||||
|
|
||||||
|
@ -43,12 +44,15 @@ export async function getFileLastUpdate(
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {stdout} = await execa('git', [
|
const fileBasename = path.basename(filePath);
|
||||||
'log',
|
const fileDirname = path.dirname(filePath);
|
||||||
'-1',
|
const {stdout} = await execa(
|
||||||
'--format=%ct, %an',
|
'git',
|
||||||
filePath,
|
['log', '-1', '--format=%ct, %an', fileBasename],
|
||||||
]);
|
{
|
||||||
|
cwd: fileDirname,
|
||||||
|
},
|
||||||
|
);
|
||||||
return getTimestampAndAuthor(stdout);
|
return getTimestampAndAuthor(stdout);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue