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
7 changes: 6 additions & 1 deletion extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,12 @@ export class Git {
options.cwd = sanitizePath(cwd);
}

return cp.spawn(this.path, args, options);
// Depending on the user's Git settings (i18n.commitEncoding, i18n.logOutputEncoding),
// commit messages may appear garbled,
// so the output encoding for commit messages is forced to UTF-8.
const spawnArgs = ['-c', 'i18n.logOutputEncoding=UTF-8', ...args];

return cp.spawn(this.path, spawnArgs, options);
}

private getCwd(options: SpawnOptions): string | undefined {
Expand Down
27 changes: 27 additions & 0 deletions extensions/git/src/test/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,33 @@ suite('git smoke test', function () {
assert.strictEqual(repository.state.indexChanges.length, 0);
});

test('reads non-UTF-8 encoded commit messages as UTF-8', async function () {
const expectCommitMessage = 'テスト';
const commitMessage = Buffer.from('a5c6a5b9a5c8', 'hex'); // Encoded in EUC-JP
const commitMessageFile = file('commit-message.txt');

try {
fs.writeFileSync(commitMessageFile, commitMessage);
cp.execSync('git config i18n.commitEncoding EUC-JP', { cwd });
cp.execSync(`git commit --allow-empty --file "${commitMessageFile}"`, { cwd });

const [commitLog] = await repository.log({ maxEntries: 1 });

assert.strictEqual(commitLog.message, expectCommitMessage);
} finally {
// Clean up without masking the original failure
if (fs.existsSync(commitMessageFile)) {
fs.unlinkSync(commitMessageFile);
}

try {
cp.execSync('git config --unset i18n.commitEncoding', { cwd });
} catch {
// Ignore cleanup errors if the config was never set or already unset.
}
}
});

// diabled because of https://github.com/microsoft/vscode/issues/327142
test.skip('opens notebook diff and file from active notebook editor', async function () {
const committed = JSON.stringify({ cells: [{ cell_type: 'code', source: ['x = 1'], metadata: {}, outputs: [], execution_count: null }], metadata: {}, nbformat: 4, nbformat_minor: 5 });
Expand Down