Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/docusaurus-utils/src/vcs/__tests__/gitUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,24 @@ describe('commit info APIs', () => {
}
`);
});

it('preserves author names containing commas', async () => {
const {repoDir, git} = await createGitRepoEmpty();

await git.commitFile('comma-author.txt', {
fileContent: 'content',
commitMessage: 'Commit by author with comma in name',
commitDate: '2024-01-15',
commitAuthor: 'Doe, Jane <jane@example.com>',
});

const filesInfo = await getGitRepositoryFilesInfo(repoDir);
const fileInfo = filesInfo.get('comma-author.txt');

expect(fileInfo).toBeDefined();
expect(fileInfo!.creation.author).toBe('Doe, Jane');
expect(fileInfo!.lastUpdate.author).toBe('Doe, Jane');
});
});
});

Expand Down
10 changes: 6 additions & 4 deletions packages/docusaurus-utils/src/vcs/gitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,13 @@ The command exited with code ${result.exitCode}: ${result.stderr}`,
for (const logLine of logLines) {
if (logLine.startsWith('t:')) {
// t:<timestamp>,a:<author name>
const [timestampStr, authorStr] = logLine.split(',') as [string, string];
const timestamp = Number.parseInt(timestampStr.slice(2), 10) * 1000;
const author = authorStr.slice(2);
// We can't use split(',') because author names may contain commas
// (e.g., "Last, First" or "John Doe, Jr.")
const separatorIndex = logLine.indexOf(',a:');
const timestampStr = logLine.slice(2, separatorIndex);
const author = logLine.slice(separatorIndex + 3);

runningDate = timestamp;
runningDate = Number.parseInt(timestampStr, 10) * 1000;
runningAuthor = author;
}

Expand Down