@@ -4,7 +4,8 @@ import { AskpassHandler } from '../ipc/askpassHandler'
44import { SSHHostKeyHandler } from '../ipc/sshHostKeyHandler'
55import { writeTemporarySSHKey , buildSSHCommand , buildSSHCommandWithKnownHosts , cleanupSSHKey , parseSSHHost } from '../utils/ssh-key-manager'
66import { decryptSecret } from '../utils/crypto'
7- import { isSSHUrl , extractHostFromSSHUrl , getSSHCredentialsForHost , type GitCredential } from '../utils/git-auth'
7+ import { isSSHUrl , normalizeSSHUrl , extractHostFromSSHUrl , getSSHCredentialsForHost } from '../utils/git-auth'
8+ import type { GitCredential } from '@opencode-manager/shared'
89import { logger } from '../utils/logger'
910import { SettingsService } from './settings'
1011
@@ -81,18 +82,19 @@ export class GitAuthService {
8182 }
8283 }
8384
84- async setupSSHForRepoUrl ( repoUrl : string | undefined , database : Database ) : Promise < boolean > {
85+ async setupSSHForRepoUrl ( repoUrl : string | undefined , database : Database , skipSSHVerification : boolean = false ) : Promise < boolean > {
8586 if ( ! repoUrl || ! isSSHUrl ( repoUrl ) ) {
8687 return false
8788 }
8889
89- const sshHost = extractHostFromSSHUrl ( repoUrl )
90+ const normalizedUrl = normalizeSSHUrl ( repoUrl )
91+ const sshHost = extractHostFromSSHUrl ( normalizedUrl )
9092 if ( ! sshHost ) {
9193 logger . warn ( `Could not extract SSH host from URL: ${ repoUrl } ` )
9294 return false
9395 }
9496
95- const { port } = parseSSHHost ( repoUrl )
97+ const { port } = parseSSHHost ( normalizedUrl )
9698 this . setSSHPort ( port && port !== '22' ? port : null )
9799
98100 const settingsService = new SettingsService ( database )
@@ -109,10 +111,20 @@ export class GitAuthService {
109111 }
110112 }
111113
112- const verified = await this . verifyHostKeyBeforeOperation ( repoUrl )
113- if ( ! verified ) {
114- await this . cleanupSSHKey ( )
115- throw new Error ( 'SSH host key verification failed or was rejected by user' )
114+ if ( skipSSHVerification ) {
115+ logger . info ( `Skipping SSH host key verification for ${ sshHost } (user requested)` )
116+ try {
117+ await this . autoAcceptHostKey ( normalizedUrl )
118+ } catch ( error ) {
119+ await this . cleanupSSHKey ( )
120+ throw new Error ( `Failed to auto-accept SSH host key for ${ sshHost } : ${ ( error as Error ) . message } ` )
121+ }
122+ } else {
123+ const verified = await this . verifyHostKeyBeforeOperation ( normalizedUrl )
124+ if ( ! verified ) {
125+ await this . cleanupSSHKey ( )
126+ throw new Error ( 'SSH host key verification failed or was rejected by user' )
127+ }
116128 }
117129
118130 return sshCredentials . length > 0
@@ -125,6 +137,14 @@ export class GitAuthService {
125137 return this . sshHostKeyHandler . verifyHostKeyBeforeOperation ( repoUrl )
126138 }
127139
140+ async autoAcceptHostKey ( repoUrl : string ) : Promise < void > {
141+ if ( ! this . sshHostKeyHandler ) {
142+ logger . warn ( 'SSH host key handler not initialized, skipping auto-accept' )
143+ return
144+ }
145+ await this . sshHostKeyHandler . autoAcceptHostKey ( repoUrl )
146+ }
147+
128148 async cleanupSSHKey ( ) : Promise < void > {
129149 if ( this . sshKeyPath ) {
130150 await cleanupSSHKey ( this . sshKeyPath )
0 commit comments