feat: add SSH commit signing to git identities
Configure commit signing per Git identity Apply SSH signing settings automatically Support signing in web and VS Code
This commit is contained in:
@@ -531,12 +531,14 @@ export async function handleStandardGitBridgeMessage(message: BridgeMessageInput
|
||||
}
|
||||
|
||||
case 'api:git/identity': {
|
||||
const { directory, method, userName, userEmail, sshKey } = (payload || {}) as {
|
||||
const { directory, method, userName, userEmail, sshKey, signCommits, signingKey } = (payload || {}) as {
|
||||
directory?: string;
|
||||
method?: string;
|
||||
userName?: string;
|
||||
userEmail?: string;
|
||||
sshKey?: string | null;
|
||||
signCommits?: boolean;
|
||||
signingKey?: string | null;
|
||||
};
|
||||
const dirError = requireDirectory(id, type, directory);
|
||||
if (dirError) return dirError;
|
||||
@@ -552,7 +554,14 @@ export async function handleStandardGitBridgeMessage(message: BridgeMessageInput
|
||||
if (!userName || !userEmail) {
|
||||
return { id, type, success: false, error: 'userName and userEmail are required' };
|
||||
}
|
||||
const result = await gitService.setGitIdentity(directory!, userName, userEmail, sshKey);
|
||||
const result = await gitService.setGitIdentity(
|
||||
directory!,
|
||||
userName,
|
||||
userEmail,
|
||||
sshKey,
|
||||
signCommits === true,
|
||||
signingKey ?? null
|
||||
);
|
||||
return { id, type, success: true, data: result };
|
||||
}
|
||||
|
||||
|
||||
@@ -3284,12 +3284,15 @@ export async function setGitIdentity(
|
||||
directory: string,
|
||||
userName: string,
|
||||
userEmail: string,
|
||||
sshKey?: string | null
|
||||
sshKey?: string | null,
|
||||
signCommits?: boolean | null,
|
||||
signingKey?: string | null
|
||||
): Promise<{ success: boolean }> {
|
||||
const repo = await getRepository(directory);
|
||||
|
||||
// Build SSH command once if needed
|
||||
const sshCommand = sshKey ? buildSshCommand(sshKey) : null;
|
||||
const shouldSignCommits = signCommits === true && typeof signingKey === 'string' && signingKey.trim().length > 0;
|
||||
|
||||
if (repo) {
|
||||
try {
|
||||
@@ -3298,6 +3301,11 @@ export async function setGitIdentity(
|
||||
if (sshCommand) {
|
||||
await repo.setConfig('core.sshCommand', sshCommand);
|
||||
}
|
||||
if (shouldSignCommits) {
|
||||
await repo.setConfig('gpg.format', 'ssh');
|
||||
await repo.setConfig('user.signingkey', signingKey.trim());
|
||||
await repo.setConfig('commit.gpgsign', 'true');
|
||||
}
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('[GitService] Failed to set identity:', error);
|
||||
@@ -3310,6 +3318,11 @@ export async function setGitIdentity(
|
||||
if (sshCommand) {
|
||||
await execGit(['config', 'core.sshCommand', sshCommand], directory);
|
||||
}
|
||||
if (shouldSignCommits) {
|
||||
await execGit(['config', 'gpg.format', 'ssh'], directory);
|
||||
await execGit(['config', 'user.signingkey', signingKey.trim()], directory);
|
||||
await execGit(['config', 'commit.gpgsign', 'true'], directory);
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user