Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 2 deletions src/cli/actions/remoteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const runRemoteAction = async (
spinner.start();

// Clone the repository
await cloneRepository(formatGitUrl(repoUrl), tempDirPath, {
await cloneRepository(formatGitUrl(repoUrl), tempDirPath, options.branch, {
Comment thread
yamadashy marked this conversation as resolved.
Outdated
Comment thread
yamadashy marked this conversation as resolved.
Outdated
execGitShallowClone: deps.execGitShallowClone,
});

Expand Down Expand Up @@ -73,6 +73,7 @@ export const createTempDirectory = async (): Promise<string> => {
export const cloneRepository = async (
url: string,
directory: string,
branch?:string,
deps = {
execGitShallowClone: execGitShallowClone,
},
Expand All @@ -81,7 +82,7 @@ export const cloneRepository = async (
logger.log('');

try {
await deps.execGitShallowClone(url, directory);
await deps.execGitShallowClone(url, directory, branch);
} catch (error) {
throw new RepomixError(`Failed to clone repository: ${(error as Error).message}`);
}
Expand Down
2 changes: 2 additions & 0 deletions src/cli/cliRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface CliOptions extends OptionValues {
init?: boolean;
global?: boolean;
remote?: string;
branch?:string;
}

export const run = async () => {
Expand All @@ -44,6 +45,7 @@ export const run = async () => {
.option('--init', 'initialize a new repomix.config.json file')
.option('--global', 'use global configuration (only applicable with --init)')
.option('--remote <url>', 'process a remote Git repository')
.option('--branch <name>', 'select a specific branch or commit id')
.action((directory = '.', options: CliOptions = {}) => executeAction(directory, process.cwd(), options));

await program.parseAsync(process.argv);
Expand Down
3 changes: 2 additions & 1 deletion src/core/file/gitCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ export const isGitInstalled = async (
export const execGitShallowClone = async (
url: string,
directory: string,
branch?:string,
deps = {
execAsync,
},
) => {
await deps.execAsync(`git clone --depth 1 ${url} ${directory}`);
await deps.execAsync(`git clone --depth 1 ${branch ? `-b ${branch} `:""}${url} ${directory}`);
Comment thread
yamadashy marked this conversation as resolved.
Outdated
};
19 changes: 16 additions & 3 deletions tests/core/file/gitCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,34 @@ describe('gitCommand', () => {
const mockExecAsync = vi.fn().mockResolvedValue({ stdout: '', stderr: '' });
const url = 'https://github.com/user/repo.git';
const directory = '/tmp/repo';
const branch = 'master';

await execGitShallowClone(url, directory, { execAsync: mockExecAsync });
await execGitShallowClone(url, directory, branch, { execAsync: mockExecAsync });

expect(mockExecAsync).toHaveBeenCalledWith(`git clone --depth 1 ${url} ${directory}`);
expect(mockExecAsync).toHaveBeenCalledWith(`git clone --depth 1 -b ${branch} ${url} ${directory}`);
Comment thread
yamadashy marked this conversation as resolved.
});

test('should throw error when git clone fails', async () => {
const mockExecAsync = vi.fn().mockRejectedValue(new Error('Authentication failed'));
const url = 'https://github.com/user/repo.git';
const directory = '/tmp/repo';
const branch = 'master';

await expect(execGitShallowClone(url, directory, { execAsync: mockExecAsync })).rejects.toThrow(
await expect(execGitShallowClone(url, directory, branch, { execAsync: mockExecAsync })).rejects.toThrow(
'Authentication failed',
);

expect(mockExecAsync).toHaveBeenCalledWith(`git clone --depth 1 -b ${branch} ${url} ${directory}`);
});

test('should execute without branch option if not specified by user', async () => {
const mockExecAsync = vi.fn().mockResolvedValue({ stdout: '', stderr: '' });
const url = 'https://github.com/user/repo.git';
const directory = '/tmp/repo';
const branch = undefined;

await execGitShallowClone(url, directory, branch, { execAsync: mockExecAsync });

expect(mockExecAsync).toHaveBeenCalledWith(`git clone --depth 1 ${url} ${directory}`);
});
});
Expand Down