diff --git a/src/components/GitDialog.tsx b/src/components/GitDialog.tsx index 9397e1a3..d1be2ddb 100644 --- a/src/components/GitDialog.tsx +++ b/src/components/GitDialog.tsx @@ -63,15 +63,6 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog const projectPath = `/projects/${projectId}`; - // Get credentials for the current repository - const getCredentialsForCurrentRepo = () => { - if (!gitStatus?.remotes.length) return null; - const remoteUrl = gitStatus.remotes[0].url; // Use first remote (usually 'origin') - return findCredentialsForRepo(remoteUrl, settings.credentials); - }; - - const currentCredentials = getCredentialsForCurrentRepo(); - const handlePush = async () => { if (!gitStatus?.isGitRepo || !gitStatus.currentBranch) { toast({ @@ -106,19 +97,11 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog try { const remote = gitStatus.remotes[0]; // Use first remote (usually 'origin') - // Prepare authentication if credentials are available - const authOptions = currentCredentials ? { - onAuth: () => ({ - username: currentCredentials.username, - password: currentCredentials.password - }), - } : {}; - await git.push({ dir: projectPath, remote: remote.name, ref: gitStatus.currentBranch, - ...authOptions, + onAuth: (url) => findCredentialsForRepo(url, settings.credentials), }); setPushResult(`✅ Successfully pushed ${gitStatus.ahead} commit${gitStatus.ahead !== 1 ? 's' : ''} to ${remote.name}/${gitStatus.currentBranch}`); @@ -167,14 +150,6 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog try { const remote = gitStatus.remotes[0]; // Use first remote (usually 'origin') - // Prepare authentication if credentials are available - const authOptions = currentCredentials ? { - onAuth: () => ({ - username: currentCredentials.username, - password: currentCredentials.password - }), - } : {}; - await git.pull({ dir: projectPath, ref: gitStatus.currentBranch, @@ -183,7 +158,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog name: 'shakespeare.diy', email: 'assistant@shakespeare.diy', }, - ...authOptions, + onAuth: (url) => findCredentialsForRepo(url, settings.credentials), }); setPullResult(`✅ Successfully pulled from ${remote.name}/${gitStatus.currentBranch}`); diff --git a/src/lib/commands/git/push.ts b/src/lib/commands/git/push.ts index 95351115..e21502a5 100644 --- a/src/lib/commands/git/push.ts +++ b/src/lib/commands/git/push.ts @@ -65,15 +65,6 @@ export class GitPushCommand implements GitSubcommand { } const settings = await readGitSettings(this.fs); - const currentCredentials = findCredentialsForRepo(remoteUrl, settings.credentials); - - // Prepare authentication if credentials are available - const authOptions = currentCredentials ? { - onAuth: () => ({ - username: currentCredentials.username, - password: currentCredentials.password, - }), - } : {}; try { await this.git.push({ @@ -81,7 +72,7 @@ export class GitPushCommand implements GitSubcommand { remote: remote, ref: targetBranch, remoteRef: targetBranch, - ...authOptions, + onAuth: (url) => findCredentialsForRepo(url, settings.credentials), }); return createSuccessResult(`To ${remoteUrl}\n ${targetBranch} -> ${targetBranch}\n`); diff --git a/src/lib/gitCredentials.test.ts b/src/lib/gitCredentials.test.ts index fe2838dd..790edcb3 100644 --- a/src/lib/gitCredentials.test.ts +++ b/src/lib/gitCredentials.test.ts @@ -64,17 +64,17 @@ describe('gitCredentials', () => { .toEqual({ username: 'git', password: 'github-token' }); }); - it('should return null when no credentials found', () => { + it('should return undefined when no credentials found', () => { expect(findCredentialsForRepo('https://unknown.com/user/repo.git', mockCredentials)) - .toBe(null); - + .toBe(undefined); + expect(findCredentialsForRepo('invalid-url', mockCredentials)) - .toBe(null); + .toBe(undefined); }); - it('should return null for empty credentials', () => { + it('should return undefined for empty credentials', () => { expect(findCredentialsForRepo('https://github.com/user/repo.git', {})) - .toBe(null); + .toBe(undefined); }); }); diff --git a/src/lib/gitCredentials.ts b/src/lib/gitCredentials.ts index ed90ed80..45942d8d 100644 --- a/src/lib/gitCredentials.ts +++ b/src/lib/gitCredentials.ts @@ -31,9 +31,9 @@ export function extractGitOrigin(gitUrl: string): string | null { export function findCredentialsForRepo( repoUrl: string, credentials: Record -): GitCredential | null { +): GitCredential | undefined { const repoOrigin = extractGitOrigin(repoUrl); - if (!repoOrigin) return null; + if (!repoOrigin) return; // Direct match if (credentials[repoOrigin]) { @@ -57,8 +57,6 @@ export function findCredentialsForRepo( return credential; } } - - return null; } /**