build(integration): clone properly from the local repo when in a detached HEAD state
This commit is contained in:
@@ -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(`
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user