Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,10 @@ function initGit(cwd: string) {
);

// Reuse the current repository instead of creating a nested one.
if (repositoryCheck.exitCode === 0) {
if (
repositoryCheck.exitCode === 0 &&
repositoryCheck.stdout.trim() === 'true'
) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion test/custom-tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const mocks = rs.hoisted(() => {
// rslint-disable-next-line @typescript-eslint/no-explicit-any
}) as any,
// rslint-disable-next-line @typescript-eslint/no-explicit-any
xSync: rs.fn(() => ({ stdout: '', stderr: '', exitCode: 0 })) as any,
xSync: rs.fn(() => ({ stdout: 'true\n', stderr: '', exitCode: 0 })) as any,
};
});

Expand Down
19 changes: 15 additions & 4 deletions test/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ rs.mock('tinyexec', () => ({
xSync: mocks.xSync,
}));

const createResult = (exitCode: number, stderr = '') => ({
stdout: '',
const createResult = (exitCode: number, stdout = '', stderr = '') => ({
stdout,
stderr,
exitCode,
});
Expand Down Expand Up @@ -71,7 +71,7 @@ test('should initialize a Git repository by default', async () => {

test('should reuse an existing Git repository', async () => {
const projectDir = path.join(testDir, 'existing');
rs.mocked(mocks.xSync).mockReturnValue(createResult(0));
rs.mocked(mocks.xSync).mockReturnValue(createResult(0, 'true\n'));

await createProject(projectDir);

Expand All @@ -83,6 +83,17 @@ test('should reuse an existing Git repository', async () => {
);
});

test('should initialize Git when the current repository is bare', async () => {
const projectDir = path.join(testDir, 'bare');
rs.mocked(mocks.xSync).mockReturnValueOnce(createResult(0, 'false\n'));

await createProject(projectDir);

expect(mocks.xSync).toHaveBeenNthCalledWith(2, 'git', ['init'], {
nodeOptions: { cwd: projectDir },
});
});

test('should skip Git initialization when disabled', async () => {
const projectDir = path.join(testDir, 'disabled');

Expand All @@ -96,7 +107,7 @@ test('should continue when Git initialization fails', async () => {
rs.mocked(mocks.xSync).mockImplementation((_command, args) =>
args[0] === 'rev-parse'
? createResult(128)
: createResult(1, 'Git is unavailable'),
: createResult(1, '', 'Git is unavailable'),
);

await expect(createProject(projectDir)).resolves.toBeUndefined();
Expand Down
2 changes: 1 addition & 1 deletion test/skills.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const mocks = rs.hoisted(() => {

const xSync = rs.fn((command: string, args: string[], options: unknown) => {
return {
stdout: '',
stdout: 'true\n',
stderr: '',
exitCode: 0,
};
Expand Down