1
0
mirror of synced 2025-11-08 12:57:47 +00:00

build(integration): clone properly from the local repo when in a detached HEAD state

This commit is contained in:
Jason Dreyzehner
2018-03-20 20:51:55 -04:00
parent 1e14d03596
commit 369a3b46b6
3 changed files with 17 additions and 10 deletions

View File

@@ -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(`

View File

@@ -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');

View File

@@ -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/);
});