mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Make git identity configurable in settings
This commit is contained in:
13 files changed
+270
-108
No files matched your search
@@ -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]',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user