diff --git a/src/hooks/usePlugins.ts b/src/hooks/usePlugins.ts index ff6a16f0..00f09b7e 100644 --- a/src/hooks/usePlugins.ts +++ b/src/hooks/usePlugins.ts @@ -91,10 +91,6 @@ export function usePlugins() { dir: pluginDir, singleBranch: true, fastForward: true, - author: { - name: 'shakespeare.diy', - email: 'assistant@shakespeare.diy', - }, }); return pluginName; diff --git a/src/lib/git.test.ts b/src/lib/git.test.ts index ec55c28f..86db8a21 100644 --- a/src/lib/git.test.ts +++ b/src/lib/git.test.ts @@ -306,7 +306,7 @@ describe('Git', () => { const { readGitSettings } = await import('./configUtils'); vi.mocked(readGitSettings).mockResolvedValue({ credentials: [], - coAuthorEnabled: true, + coAuthorEnabled: false, }); await gitInstance.commit({ @@ -322,10 +322,6 @@ describe('Git', () => { name: 'shakespeare.diy', email: 'assistant@shakespeare.diy', }, - committer: { - name: 'shakespeare.diy', - email: 'assistant@shakespeare.diy', - }, }); }); @@ -351,10 +347,6 @@ describe('Git', () => { name: 'John Doe', email: 'john@example.com', }, - committer: { - name: 'John Doe', - email: 'john@example.com', - }, }); }); @@ -380,47 +372,6 @@ describe('Git', () => { name: 'John Doe', email: 'john@example.com', }, - committer: { - name: 'John Doe', - email: 'john@example.com', - }, - }); - }); - - it('respects provided author when explicitly passed', async () => { - const { readGitSettings } = await import('./configUtils'); - vi.mocked(readGitSettings).mockResolvedValue({ - credentials: [], - name: 'John Doe', - email: 'john@example.com', - coAuthorEnabled: true, - }); - - await gitInstance.commit({ - dir: '/test', - message: 'Test commit', - author: { - name: 'Custom Author', - email: 'custom@example.com', - }, - committer: { - name: 'Custom Committer', - email: 'committer@example.com', - }, - }); - - expect(mockGit.commit).toHaveBeenCalledWith({ - fs, - dir: '/test', - message: 'Test commit', - author: { - name: 'Custom Author', - email: 'custom@example.com', - }, - committer: { - name: 'Custom Committer', - email: 'committer@example.com', - }, }); }); }); diff --git a/src/lib/git.ts b/src/lib/git.ts index 385f409e..ea9e3a37 100644 --- a/src/lib/git.ts +++ b/src/lib/git.ts @@ -12,6 +12,7 @@ export interface GitOptions { nostr: NPool; corsProxy?: string; ngitServers?: string[]; + systemAuthor?: { name: string; email: string }; } interface NostrCloneURI { @@ -31,12 +32,17 @@ export class Git { private http: HttpClient; private nostr: NPool; private ngitServers: string[]; + private systemAuthor: { name: string; email: string }; constructor(options: GitOptions) { this.fs = options.fs; this.http = new GitHttp(options.corsProxy); this.nostr = options.nostr; this.ngitServers = options.ngitServers ?? ['git.shakespeare.diy', 'relay.ngit.dev']; + this.systemAuthor = options.systemAuthor ?? { + name: 'shakespeare.diy', + email: 'assistant@shakespeare.diy', + }; } // Repository initialization and configuration @@ -96,50 +102,19 @@ export class Git { } // Commits and history - async commit(options: Omit[0], 'fs'>) { - // If author is not provided, use Git identity settings - let author = options.author; - let committer = options.committer; + async commit(options: Omit[0], 'fs' | 'author'>) { + const { author, coAuthorEnabled } = await this.getGitSettings(); + + // Add system co-author if enabled let message = options.message; - - if (!author || !committer) { - // Read Git identity settings from config - const gitSettings = await readGitSettings(this.fs); - - // Determine author based on Git identity settings - const defaultAuthor = { - name: 'shakespeare.diy', - email: 'assistant@shakespeare.diy', - }; - - const hasCustomIdentity = gitSettings.name && gitSettings.email; - - if (hasCustomIdentity) { - const customAuthor = { - name: gitSettings.name!, - email: gitSettings.email!, - }; - - // Use custom identity - if (!author) author = customAuthor; - if (!committer) committer = customAuthor; - - // Add Shakespeare as co-author if enabled - if (gitSettings.coAuthorEnabled ?? true) { - message = `${message}\n\nCo-authored-by: shakespeare.diy `; - } - } else { - // Use Shakespeare as default author - if (!author) author = defaultAuthor; - if (!committer) committer = defaultAuthor; - } + if (coAuthorEnabled) { + message = `${message}\n\nCo-authored-by: ${this.systemAuthor.name} <${this.systemAuthor.email}>`; } return git.commit({ fs: this.fs, ...options, author, - committer, message, }); } @@ -246,14 +221,15 @@ export class Git { }); } - async pull(options: Omit[0], 'fs' | 'http' | 'corsProxy'>) { + async pull(options: Omit[0], 'fs' | 'http' | 'author' | 'corsProxy'>) { // Check if this is a Nostr repository by looking at the remote URL const remote = options.remote || 'origin'; const dir = options.dir || '.'; const remoteUrl = await this.getRemoteURL(dir, remote); + const { author } = await this.getGitSettings(); if (remoteUrl && remoteUrl.startsWith('nostr://')) { - return this.nostrPull(remoteUrl, { ...options, remote, dir }); + return this.nostrPull(remoteUrl, { ...options, author, remote, dir }); } // Regular Git pull @@ -261,6 +237,7 @@ export class Git { fs: this.fs, http: this.http, ...options, + author, }); } @@ -598,6 +575,26 @@ export class Git { return git.version(); } + private async getGitSettings(): Promise<{ author: { name: string; email: string }; coAuthorEnabled: boolean }> { + const { + name, + email, + coAuthorEnabled = true, + } = await readGitSettings(this.fs); + + if (name && email) { + return { + author: { name, email }, + coAuthorEnabled, + }; + } else { + return { + author: this.systemAuthor, + coAuthorEnabled, + } + } + } + // Nostr-specific helper methods /**