mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-30 02:37:59 +02:00
fix(utils): getFileCommitDate should support log.showSignature=true
(#10022)
This commit is contained in:
parent
5bb4832869
commit
6e1364bb8a
1 changed files with 16 additions and 6 deletions
|
@ -107,21 +107,29 @@ export async function getFileCommitDate(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We add a "RESULT:" prefix to make parsing easier
|
||||||
|
// See why: https://github.com/facebook/docusaurus/pull/10022
|
||||||
|
const resultFormat = includeAuthor ? 'RESULT:%ct,%an' : 'RESULT:%ct';
|
||||||
|
|
||||||
const args = [
|
const args = [
|
||||||
`--format=%ct${includeAuthor ? ',%an' : ''}`,
|
`--format=${resultFormat}`,
|
||||||
'--max-count=1',
|
'--max-count=1',
|
||||||
age === 'oldest' ? '--follow --diff-filter=A' : undefined,
|
age === 'oldest' ? '--follow --diff-filter=A' : undefined,
|
||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(' ');
|
.join(' ');
|
||||||
|
|
||||||
|
const command = `git -c log.showSignature=false log ${args} -- "${path.basename(
|
||||||
|
file,
|
||||||
|
)}"`;
|
||||||
|
|
||||||
const result = await new Promise<{
|
const result = await new Promise<{
|
||||||
code: number;
|
code: number;
|
||||||
stdout: string;
|
stdout: string;
|
||||||
stderr: string;
|
stderr: string;
|
||||||
}>((resolve) => {
|
}>((resolve) => {
|
||||||
shell.exec(
|
shell.exec(
|
||||||
`git log ${args} -- "${path.basename(file)}"`,
|
command,
|
||||||
{
|
{
|
||||||
// Setting cwd is important, see: https://github.com/facebook/docusaurus/pull/5048
|
// Setting cwd is important, see: https://github.com/facebook/docusaurus/pull/5048
|
||||||
cwd: path.dirname(file),
|
cwd: path.dirname(file),
|
||||||
|
@ -138,10 +146,12 @@ export async function getFileCommitDate(
|
||||||
`Failed to retrieve the git history for file "${file}" with exit code ${result.code}: ${result.stderr}`,
|
`Failed to retrieve the git history for file "${file}" with exit code ${result.code}: ${result.stderr}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let regex = /^(?<timestamp>\d+)$/;
|
|
||||||
if (includeAuthor) {
|
// We only parse the output line starting with our "RESULT:" prefix
|
||||||
regex = /^(?<timestamp>\d+),(?<author>.+)$/;
|
// See why https://github.com/facebook/docusaurus/pull/10022
|
||||||
}
|
const regex = includeAuthor
|
||||||
|
? /(?:^|\n)RESULT:(?<timestamp>\d+),(?<author>.+)(?:$|\n)/
|
||||||
|
: /(?:^|\n)RESULT:(?<timestamp>\d+)(?:$|\n)/;
|
||||||
|
|
||||||
const output = result.stdout.trim();
|
const output = result.stdout.trim();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue