diff --git a/packages/env/lib/download-sources.js b/packages/env/lib/download-sources.js index d74f33d826484..308642cb9c12d 100644 --- a/packages/env/lib/download-sources.js +++ b/packages/env/lib/download-sources.js @@ -142,7 +142,9 @@ async function downloadGitSource( source, { onProgress, spinner, debug } ) { log( 'Fetching the specified ref.' ); const remote = await repository.getRemote( 'origin' ); - await remote.fetch( source.ref, gitFetchOptions.fetchOpts ); + const oid = NodeGit.Oid.fromString( source.ref ); + const ref = NodeGit.Commit.lookupPrefix( repository, oid, 6 ); + await remote.fetch( ref, gitFetchOptions.fetchOpts ); await remote.disconnect(); try { log( 'Checking out the specified ref.' ); @@ -151,16 +153,14 @@ async function downloadGitSource( source, { onProgress, spinner, debug } ) { .getReference( 'FETCH_HEAD' ) // Sometimes git doesn't update FETCH_HEAD for things // like tags so we try another method here. - .catch( - repository.getReference.bind( repository, source.ref ) - ), + .catch( repository.getReference.bind( repository, ref ) ), { checkoutStrategy: NodeGit.Checkout.STRATEGY.FORCE, } ); } catch ( error ) { log( 'Ref needs to be set as detached.' ); - await repository.setHeadDetached( source.ref ); + await repository.setHeadDetached( ref ); } onProgress( 1 );