MCPcopy Index your code
hub / github.com/bitjson/typescript-starter / cloneRepo

Function cloneRepo

src/cli/tasks.ts:21–74  ·  view source on GitHub ↗
(
  spawner: typeof execa,
  suppressOutput = false
)

Source from the content-addressed store, hash-verified

19// We implement these as function factories to make unit testing easier.
20
21export const cloneRepo = (
22 spawner: typeof execa,
23 suppressOutput = false
24) => async (
25 repoInfo: {
26 readonly branch: string;
27 readonly repo: string;
28 },
29 workingDirectory: string,
30 dir: string
31) => {
32 const projectDir = join(workingDirectory, dir);
33 const gitHistoryDir = join(projectDir, '.git');
34 const args =
35 repoInfo.branch === '.'
36 ? ['clone', '--depth=1', repoInfo.repo, dir]
37 : [
38 'clone',
39 '--depth=1',
40 `--branch=${repoInfo.branch}`,
41 repoInfo.repo,
42 dir,
43 ];
44 try {
45 await spawner('git', args, {
46 cwd: workingDirectory,
47 stdio: suppressOutput ? 'pipe' : 'inherit',
48 });
49 } catch (err) {
50 if (err.exitCodeName === 'ENOENT') {
51 // eslint-disable-next-line functional/no-throw-statement
52 throw new Error(`
53 Git is not installed on your PATH. Please install Git and try again.
54
55 For more information, visit: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
56`);
57 } else {
58 // eslint-disable-next-line functional/no-throw-statement
59 throw new Error(`Git clone failed.`);
60 }
61 }
62 try {
63 const revParseResult = await spawner('git', ['rev-parse', 'HEAD'], {
64 cwd: projectDir,
65 encoding: 'utf8',
66 stdio: ['pipe', 'pipe', 'inherit'],
67 });
68 const commitHash = revParseResult.stdout;
69 return { commitHash, gitHistoryDir };
70 } catch (err) {
71 // eslint-disable-next-line functional/no-throw-statement
72 throw new Error(`Git rev-parse failed.`);
73 }
74};
75
76export const getGithubUsername = (
77 // eslint-disable-next-line @typescript-eslint/no-explicit-any

Callers 3

sandboxTasksFunction · 0.90
cli.unit.spec.tsFile · 0.90
tasks.tsFile · 0.85

Calls

no outgoing calls

Tested by 1

sandboxTasksFunction · 0.72