mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-14 01:27:35 +02:00
fix: read last update from inner git repositories (#6592)
This commit is contained in:
parent
85351549fe
commit
b03431f139
2 changed files with 17 additions and 4 deletions
|
@ -55,7 +55,7 @@ describe('lastUpdate', () => {
|
||||||
await expect(getFileLastUpdate(nonExistingFilePath)).resolves.toBeNull();
|
await expect(getFileLastUpdate(nonExistingFilePath)).resolves.toBeNull();
|
||||||
expect(consoleMock).toHaveBeenCalledTimes(1);
|
expect(consoleMock).toHaveBeenCalledTimes(1);
|
||||||
expect(consoleMock).toHaveBeenLastCalledWith(
|
expect(consoleMock).toHaveBeenLastCalledWith(
|
||||||
expect.stringMatching(/with exit code 128/),
|
expect.stringMatching(/because the file does not exist./),
|
||||||
);
|
);
|
||||||
await expect(getFileLastUpdate(null)).resolves.toBeNull();
|
await expect(getFileLastUpdate(null)).resolves.toBeNull();
|
||||||
await expect(getFileLastUpdate(undefined)).resolves.toBeNull();
|
await expect(getFileLastUpdate(undefined)).resolves.toBeNull();
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
import shell from 'shelljs';
|
import shell from 'shelljs';
|
||||||
import logger from '@docusaurus/logger';
|
import logger from '@docusaurus/logger';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
type FileLastUpdateData = {timestamp?: number; author?: string};
|
type FileLastUpdateData = {timestamp?: number; author?: string};
|
||||||
|
|
||||||
|
@ -43,9 +44,21 @@ export async function getFileLastUpdate(
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = shell.exec(`git log -1 --format=%ct,%an "${filePath}"`, {
|
if (!shell.test('-f', filePath)) {
|
||||||
silent: true,
|
throw new Error(
|
||||||
});
|
`Retrieval of git history failed at "${filePath}" because the file does not exist.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileBasename = path.basename(filePath);
|
||||||
|
const fileDirname = path.dirname(filePath);
|
||||||
|
const result = shell.exec(
|
||||||
|
`git log --max-count=1 --format=%ct,%an -- "${fileBasename}"`,
|
||||||
|
{
|
||||||
|
cwd: fileDirname, // this is needed: https://github.com/facebook/docusaurus/pull/5048
|
||||||
|
silent: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
if (result.code !== 0) {
|
if (result.code !== 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Retrieval of git history failed at "${filePath}" with exit code ${result.code}: ${result.stderr}`,
|
`Retrieval of git history failed at "${filePath}" with exit code ${result.code}: ${result.stderr}`,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue