Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RND-102 Filter out blobs on git clone for time optimization purpose #160

Merged
merged 1 commit into from
Mar 29, 2023
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
3 changes: 2 additions & 1 deletion packages/backend/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import simpleGit from 'simple-git';

// NOTE: The idea behind the code below has been described in more details here: https://serverfault.com/questions/544156/git-clone-fail-instead-of-prompting-for-credentials
const disableGitAuthenticationPromptOption = '-c core.askPass=echo';
const filterOutBlobsOption = '--filter=blob:none';

const getUniqNotExistingTemporaryDirectory = (): string => {
const repositoryPath = path.join(os.tmpdir(), uniqueDirectoryName.generate());
Expand Down Expand Up @@ -35,7 +36,7 @@ export const cloneGitRepo = async <Result>(
const repositoryPath = getUniqNotExistingTemporaryDirectory();
try {
const gitUrl = getGitUrl(url, authHeader);
await simpleGit().clone(gitUrl, repositoryPath, [disableGitAuthenticationPromptOption]);
await simpleGit().clone(gitUrl, repositoryPath, [disableGitAuthenticationPromptOption, filterOutBlobsOption]);
return await callback(repositoryPath);
} catch (error: any) {
const isAuthenticationIssue = error.message.includes('Authentication failed');
Expand Down
5 changes: 4 additions & 1 deletion packages/backend/test/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ describe('git', () => {
await cloneGitRepo(url, callback, 'dXNlcjpwYXNz');

const repositoryPath = 'tmp/dir';
expect(clone).toHaveBeenCalledWith('//user:pass@url', repositoryPath, ['-c core.askPass=echo']);
expect(clone).toHaveBeenCalledWith('//user:pass@url', repositoryPath, [
'-c core.askPass=echo',
'--filter=blob:none'
]);
expect(callback).toHaveBeenCalledWith(repositoryPath);
expect(fs.rmdirSync).toHaveBeenCalledWith(repositoryPath, { recursive: true });
});
Expand Down