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
6 changes: 3 additions & 3 deletions src/core/git/gitCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const execLsRemote = async (
validateGitUrl(url);

try {
const result = await deps.execFileAsync('git', ['ls-remote', '--heads', '--tags', url]);
const result = await deps.execFileAsync('git', ['ls-remote', '--heads', '--tags', '--', url]);
return result.stdout || '';
} catch (error) {
logger.trace('Failed to execute git ls-remote:', (error as Error).message);
Expand All @@ -113,7 +113,7 @@ export const execGitShallowClone = async (

if (remoteBranch) {
await deps.execFileAsync('git', ['-C', directory, 'init']);
await deps.execFileAsync('git', ['-C', directory, 'remote', 'add', 'origin', url]);
await deps.execFileAsync('git', ['-C', directory, 'remote', 'add', '--', 'origin', url]);
try {
await deps.execFileAsync('git', ['-C', directory, 'fetch', '--depth', '1', 'origin', remoteBranch]);
await deps.execFileAsync('git', ['-C', directory, 'checkout', 'FETCH_HEAD']);
Expand Down Expand Up @@ -143,7 +143,7 @@ export const execGitShallowClone = async (
await deps.execFileAsync('git', ['-C', directory, 'checkout', remoteBranch]);
}
} else {
await deps.execFileAsync('git', ['clone', '--depth', '1', url, directory]);
await deps.execFileAsync('git', ['clone', '--depth', '1', '--', url, directory]);
}

// Clean up .git directory
Expand Down
45 changes: 39 additions & 6 deletions tests/core/git/gitCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ file2.ts

await execGitShallowClone(url, directory, remoteBranch, { execFileAsync: mockFileExecAsync });

expect(mockFileExecAsync).toHaveBeenCalledWith('git', ['clone', '--depth', '1', url, directory]);
expect(mockFileExecAsync).toHaveBeenCalledWith('git', ['clone', '--depth', '1', '--', url, directory]);
});

test('should throw error when git clone fails', async () => {
Expand All @@ -134,7 +134,7 @@ file2.ts
execGitShallowClone(url, directory, remoteBranch, { execFileAsync: mockFileExecAsync }),
).rejects.toThrow('Authentication failed');

expect(mockFileExecAsync).toHaveBeenCalledWith('git', ['clone', '--depth', '1', url, directory]);
expect(mockFileExecAsync).toHaveBeenCalledWith('git', ['clone', '--depth', '1', '--', url, directory]);
});

test('should execute commands correctly when branch is specified', async () => {
Expand All @@ -148,7 +148,15 @@ file2.ts

expect(mockFileExecAsync).toHaveBeenCalledTimes(4);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(1, 'git', ['-C', directory, 'init']);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(2, 'git', ['-C', directory, 'remote', 'add', 'origin', url]);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(2, 'git', [
'-C',
directory,
'remote',
'add',
'--',
'origin',
url,
]);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(3, 'git', [
'-C',
directory,
Expand Down Expand Up @@ -177,7 +185,15 @@ file2.ts
).rejects.toThrow('Authentication failed');
expect(mockFileExecAsync).toHaveBeenCalledTimes(3);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(1, 'git', ['-C', directory, 'init']);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(2, 'git', ['-C', directory, 'remote', 'add', 'origin', url]);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(2, 'git', [
'-C',
directory,
'remote',
'add',
'--',
'origin',
url,
]);
expect(mockFileExecAsync).toHaveBeenLastCalledWith('git', [
'-C',
directory,
Expand Down Expand Up @@ -207,7 +223,15 @@ file2.ts

expect(mockFileExecAsync).toHaveBeenCalledTimes(5);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(1, 'git', ['-C', directory, 'init']);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(2, 'git', ['-C', directory, 'remote', 'add', 'origin', url]);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(2, 'git', [
'-C',
directory,
'remote',
'add',
'--',
'origin',
url,
]);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(3, 'git', [
'-C',
directory,
Expand Down Expand Up @@ -238,7 +262,15 @@ file2.ts
).rejects.toThrow(errMessage);
expect(mockFileExecAsync).toHaveBeenCalledTimes(3);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(1, 'git', ['-C', directory, 'init']);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(2, 'git', ['-C', directory, 'remote', 'add', 'origin', url]);
expect(mockFileExecAsync).toHaveBeenNthCalledWith(2, 'git', [
'-C',
directory,
'remote',
'add',
'--',
'origin',
url,
]);
expect(mockFileExecAsync).toHaveBeenLastCalledWith('git', [
'-C',
directory,
Expand Down Expand Up @@ -281,6 +313,7 @@ c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8\trefs/tags/v1.0.0
'ls-remote',
'--heads',
'--tags',
'--',
'https://github.com/user/repo.git',
]);
});
Expand Down
Loading