Skip to content
Open
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
12 changes: 12 additions & 0 deletions src/utils/__tests__/processes-git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ describe('detectGitRemoteRepo', () => {
expect(await detectGitRemoteRepo('/repo')).toBe('org/repo');
});

it.each([
['SSH with .git', 'git@github.com:test-owner/my.repo.git', 'test-owner/my.repo'],
['SSH without .git', 'git@github.com:test-owner/my.repo', 'test-owner/my.repo'],
['HTTPS with .git', 'https://github.com/test-owner/my.repo.git', 'test-owner/my.repo'],
['HTTPS without .git', 'https://github.com/vercel/next.js', 'vercel/next.js'],
['GitHub Pages repo', 'git@github.com:user/user.github.io.git', 'user/user.github.io'],
['multiple dots', 'https://github.com/org/a.b.c.git', 'org/a.b.c'],
])('keeps dots in repository name (%s)', async (_label, url, expected) => {
mockExecAsync.mockResolvedValue({ stdout: `${url}\n`, stderr: '' });
expect(await detectGitRemoteRepo('/repo')).toBe(expected);
});

it('returns undefined when git command fails (no remote)', async () => {
mockExecAsync.mockRejectedValue(new Error('fatal: No such remote origin'));
expect(await detectGitRemoteRepo('/repo')).toBeUndefined();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/processes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export async function detectGitRemoteRepo(cwd: string): Promise<string | undefin
try {
const { stdout } = await execAsync('git remote get-url origin', { cwd, timeout: 5000, windowsHide: true });
const remoteUrl = stdout.trim();
const match = remoteUrl.match(/[:/]([^/]+)\/([^/.]+?)(?:\.git)?$/);
const match = remoteUrl.match(/[:/]([^/]+)\/([^/]+?)(?:\.git)?$/);
if (match) return `${match[1]}/${match[2]}`;
return undefined;
} catch {
Expand Down