diff --git a/src/cli/tasks.ts b/src/cli/tasks.ts index 7b7c114..11860b8 100644 --- a/src/cli/tasks.ts +++ b/src/cli/tasks.ts @@ -33,15 +33,21 @@ export const cloneRepo = ( ) => { const projectDir = join(workingDirectory, dir); const gitHistoryDir = join(projectDir, '.git'); + const args = + repoInfo.branch === '.' + ? ['clone', '--depth=1', repoInfo.repo, dir] + : [ + 'clone', + '--depth=1', + `--branch=${repoInfo.branch}`, + repoInfo.repo, + dir + ]; try { - await spawner( - 'git', - ['clone', '--depth=1', `--branch=${repoInfo.branch}`, repoInfo.repo, dir], - { - cwd: workingDirectory, - stdio: suppressOutput ? 'pipe' : 'inherit' - } - ); + await spawner('git', args, { + cwd: workingDirectory, + stdio: suppressOutput ? 'pipe' : 'inherit' + }); } catch (err) { if (err.code === 'ENOENT') { throw new Error(` diff --git a/src/cli/tests/cli.integration.spec.ts b/src/cli/tests/cli.integration.spec.ts index 676b9f4..6ea3ae4 100644 --- a/src/cli/tests/cli.integration.spec.ts +++ b/src/cli/tests/cli.integration.spec.ts @@ -40,7 +40,8 @@ const branch = execa.sync('git', [ 'HEAD' ]).stdout; const repoInfo = { - branch: branch === 'HEAD' ? 'master' : branch, + // if local repo is in a detached HEAD state, providing --branch to `git clone` will fail. + branch: branch === 'HEAD' ? '.' : branch, repo: process.cwd() }; const buildDir = join(process.cwd(), 'build'); diff --git a/src/cli/tests/cli.unit.spec.ts b/src/cli/tests/cli.unit.spec.ts index 70a0542..5786018 100644 --- a/src/cli/tests/cli.unit.spec.ts +++ b/src/cli/tests/cli.unit.spec.ts @@ -138,7 +138,7 @@ const mockErr = (code?: string | number) => test('cloneRepo: errors when Git is not installed on PATH', async t => { const error = await t.throws( - cloneRepo(mockErr('ENOENT'))({ repo: 'r', branch: 'b' }, 'd', 'p') + cloneRepo(mockErr('ENOENT'))({ repo: 'r', branch: '.' }, 'd', 'p') ); t.regex(error.message, /Git is not installed on your PATH/); });