Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v2): read last update from inner git repositories #5048

Merged
merged 1 commit into from Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -31,15 +31,16 @@ describe('lastUpdate', () => {
test('non-existing file', async () => {
const consoleMock = jest.spyOn(console, 'error');
consoleMock.mockImplementation();
const nonExistingFileName = '.nonExisting';
const nonExistingFilePath = path.join(
__dirname,
'__fixtures__',
'.nonExisting',
nonExistingFileName,
);
expect(await getFileLastUpdate(nonExistingFilePath)).toBeNull();
expect(consoleMock).toHaveBeenCalledTimes(1);
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(undefined)).toBeNull();
Expand Down
16 changes: 10 additions & 6 deletions packages/docusaurus-plugin-content-docs/src/lastUpdate.ts
Expand Up @@ -7,6 +7,7 @@

import shell from 'shelljs';
import execa from 'execa';
import path from 'path';

type FileLastUpdateData = {timestamp?: number; author?: string};

Expand Down Expand Up @@ -43,12 +44,15 @@ export async function getFileLastUpdate(
return null;
}

const {stdout} = await execa('git', [
'log',
'-1',
'--format=%ct, %an',
filePath,
]);
const fileBasename = path.basename(filePath);
const fileDirname = path.dirname(filePath);
const {stdout} = await execa(
'git',
['log', '-1', '--format=%ct, %an', fileBasename],
{
cwd: fileDirname,
},
);
return getTimestampAndAuthor(stdout);
} catch (error) {
console.error(error);
Expand Down