Make git identity configurable in settings

This commit is contained in:
Alex Gleason committed 2025-10-14 20:36:29 -05:00
1 parent 51f7a42d3e
commit e4c3fc8b05
13 files changed
+270 -108

No files matched your search

+131
View File
@@ -19,6 +19,9 @@ vi.mock('@nostrify/nostrify', () => ({
lookup: vi.fn(),
},
}));
vi.mock('./configUtils', () => ({
readGitSettings: vi.fn(),
}));
const mockGit = vi.mocked(git);
@@ -293,4 +296,132 @@ describe('Git', () => {
});
});
});
describe('commit with Git identity settings', () => {
beforeEach(() => {
mockGit.commit = vi.fn().mockResolvedValue('abc123');
});
it('uses shakespeare.diy as default author when no Git identity is configured', async () => {
const { readGitSettings } = await import('./configUtils');
vi.mocked(readGitSettings).mockResolvedValue({
credentials: {},
coAuthorEnabled: true,
});
await gitInstance.commit({
dir: '/test',
message: 'Test commit',
});
expect(mockGit.commit).toHaveBeenCalledWith({
fs,
dir: '/test',
message: 'Test commit',
author: {
name: 'shakespeare.diy',
email: '[email protected]',
},
committer: {
name: 'shakespeare.diy',
email: '[email protected]',
},
});
});
it('uses custom identity when both name and email are configured', async () => {
const { readGitSettings } = await import('./configUtils');
vi.mocked(readGitSettings).mockResolvedValue({
credentials: {},
name: 'John Doe',
email: '[email protected]',
coAuthorEnabled: true,
});
await gitInstance.commit({
dir: '/test',
message: 'Test commit',
});
expect(mockGit.commit).toHaveBeenCalledWith({
fs,
dir: '/test',
message: 'Test commit\n\nCo-authored-by: shakespeare.diy <[email protected]>',
author: {
name: 'John Doe',
email: '[email protected]',
},
committer: {
name: 'John Doe',
email: '[email protected]',
},
});
});
it('does not add co-author when coAuthorEnabled is false', async () => {
const { readGitSettings } = await import('./configUtils');
vi.mocked(readGitSettings).mockResolvedValue({
credentials: {},
name: 'John Doe',
email: '[email protected]',
coAuthorEnabled: false,
});
await gitInstance.commit({
dir: '/test',
message: 'Test commit',
});
expect(mockGit.commit).toHaveBeenCalledWith({
fs,
dir: '/test',
message: 'Test commit',
author: {
name: 'John Doe',
email: '[email protected]',
},
committer: {
name: 'John Doe',
email: '[email protected]',
},
});
});
it('respects provided author when explicitly passed', async () => {
const { readGitSettings } = await import('./configUtils');
vi.mocked(readGitSettings).mockResolvedValue({
credentials: {},
name: 'John Doe',
email: '[email protected]',
coAuthorEnabled: true,
});
await gitInstance.commit({
dir: '/test',
message: 'Test commit',
author: {
name: 'Custom Author',
email: '[email protected]',
},
committer: {
name: 'Custom Committer',
email: '[email protected]',
},
});
expect(mockGit.commit).toHaveBeenCalledWith({
fs,
dir: '/test',
message: 'Test commit',
author: {
name: 'Custom Author',
email: '[email protected]',
},
committer: {
name: 'Custom Committer',
email: '[email protected]',
},
});
});
});
});