Pass onAuth into the git constructor instead of to push method

This commit is contained in:
Alex Gleason committed 2025-12-22 21:16:18 -06:00
1 parent a915b9121f
commit 3eb156e983
6 files changed
+19 -37

No files matched your search

-5
View File
@@ -4,8 +4,6 @@ import type { NostrSigner } from "@nostrify/nostrify";
import { createSuccessResult, createErrorResult } from "../ShellCommand";
import type { GitSubcommand, GitSubcommandOptions } from "../git";
import type { Git } from "../../git";
import { findCredentialsForRepo } from "@/lib/gitCredentials";
import { readGitSettings } from "@/lib/configUtils";
export class GitPushCommand implements GitSubcommand {
name = 'push';
@@ -64,8 +62,6 @@ export class GitPushCommand implements GitSubcommand {
return createErrorResult(`fatal: '${remote}' does not appear to be a git repository`);
}
const settings = await readGitSettings(this.fs);
try {
await this.git.push({
dir: cwd,
@@ -73,7 +69,6 @@ export class GitPushCommand implements GitSubcommand {
ref: targetBranch,
remoteRef: targetBranch,
force: options.force,
onAuth: (url) => findCredentialsForRepo(url, settings.credentials),
signer: this.signer,
});
+6 -2
View File
@@ -1,4 +1,4 @@
import git, { FetchResult, GitHttpRequest, GitHttpResponse, HttpClient } from 'isomorphic-git';
import git, { AuthCallback, FetchResult, GitHttpRequest, GitHttpResponse, HttpClient } from 'isomorphic-git';
import { NIP05 } from '@nostrify/nostrify';
import { nip19 } from 'nostr-tools';
import { proxyUrl } from './proxyUrl';
@@ -13,6 +13,7 @@ export interface GitOptions {
corsProxy?: string;
ngitServers?: string[];
systemAuthor?: { name: string; email: string };
onAuth?: AuthCallback;
}
interface NostrCloneURI {
@@ -33,6 +34,7 @@ export class Git {
private nostr: NPool;
private ngitServers: string[];
private systemAuthor: { name: string; email: string };
private onAuth?: AuthCallback;
constructor(options: GitOptions) {
this.fs = options.fs;
@@ -43,6 +45,7 @@ export class Git {
name: 'shakespeare.diy',
email: '[email protected]',
};
this.onAuth = options.onAuth;
}
// Repository initialization and configuration
@@ -241,7 +244,7 @@ export class Git {
});
}
async push(options: Omit<Parameters<typeof git.push>[0], 'fs' | 'http' | 'corsProxy'> & { signer?: NostrSigner }) {
async push(options: Omit<Parameters<typeof git.push>[0], 'fs' | 'http' | 'onAuth' | 'corsProxy'> & { signer?: NostrSigner }) {
// Check if this is a Nostr repository by looking at the remote URL
const remote = options.remote || 'origin';
const dir = options.dir || '.';
@@ -257,6 +260,7 @@ export class Git {
return git.push({
fs: this.fs,
http: this.http,
onAuth: this.onAuth,
...options,
});
}