From 71ed8bae267974b2433efc5ae89a8fb6542696d7 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 4 Feb 2021 16:29:51 +0100 Subject: [PATCH 1/8] wp-env.json: Pin tt1-blocks dependency to v0.4.3 --- .wp-env.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.wp-env.json b/.wp-env.json index ccd1231aa28b25..2d5ce3d259ccb1 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -3,7 +3,7 @@ "plugins": [ "." ], - "themes": [ "WordPress/theme-experiments/tt1-blocks" ], + "themes": [ "WordPress/theme-experiments/tt1-blocks#f3d2c0d" ], "env": { "tests": { "mappings": { From a42f596c04b097e7fa61b07794fbd06e0fcd9712 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 4 Feb 2021 16:36:21 +0100 Subject: [PATCH 2/8] wp-env: Add config parser tests for subdirectory and ref --- packages/env/lib/config/test/config.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/env/lib/config/test/config.js b/packages/env/lib/config/test/config.js index c9d620b12d2185..a20bf54569bbd8 100644 --- a/packages/env/lib/config/test/config.js +++ b/packages/env/lib/config/test/config.js @@ -366,6 +366,7 @@ describe( 'readConfig', () => { 'WordPress/gutenberg', 'WordPress/gutenberg#master', 'WordPress/gutenberg#5.0', + 'WordPress/theme-experiments/tt1-blocks#f3d2c0d', ], } ) ) @@ -394,6 +395,16 @@ describe( 'readConfig', () => { path: expect.stringMatching( /^\/.*gutenberg$/ ), basename: 'gutenberg', }, + { + type: 'git', + url: + 'https://github.com/WordPress/theme-experiments.git', + ref: 'f3d2c0d', + path: expect.stringMatching( + /^\/.*theme-experiments\/tt1-blocks$/ + ), + basename: 'tt1-blocks', + }, ], }; expect( config.env.tests ).toMatchObject( matchObj ); From fb236adeff5ab7cb163fc74cacdc227b27d3faf9 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 4 Feb 2021 17:25:10 +0100 Subject: [PATCH 3/8] Try expanding short SHAs --- packages/env/lib/download-sources.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/env/lib/download-sources.js b/packages/env/lib/download-sources.js index d74f33d826484d..308642cb9c12dc 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 ); From 4246cc2bd9781338e78649807df77d707a52d9b9 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 4 Feb 2021 20:00:53 +0100 Subject: [PATCH 4/8] Await, and use commit.sha() --- packages/env/lib/download-sources.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/env/lib/download-sources.js b/packages/env/lib/download-sources.js index 308642cb9c12dc..2c0f4846fa2ec2 100644 --- a/packages/env/lib/download-sources.js +++ b/packages/env/lib/download-sources.js @@ -142,8 +142,9 @@ async function downloadGitSource( source, { onProgress, spinner, debug } ) { log( 'Fetching the specified ref.' ); const remote = await repository.getRemote( 'origin' ); - const oid = NodeGit.Oid.fromString( source.ref ); - const ref = NodeGit.Commit.lookupPrefix( repository, oid, 6 ); + const oid = await NodeGit.Oid.fromString( source.ref ); + const commit = await NodeGit.Commit.lookupPrefix( repository, oid, 6 ); + const ref = commit.sha(); await remote.fetch( ref, gitFetchOptions.fetchOpts ); await remote.disconnect(); try { From df157be848ee344f5ef8ca107d8171144a79fb3f Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 5 Feb 2021 18:17:08 +0100 Subject: [PATCH 5/8] Revert "Await, and use commit.sha()" This reverts commit a9348620a23cfa27baaf73a7a164d6a49fa7cc5c. --- packages/env/lib/download-sources.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/env/lib/download-sources.js b/packages/env/lib/download-sources.js index 2c0f4846fa2ec2..308642cb9c12dc 100644 --- a/packages/env/lib/download-sources.js +++ b/packages/env/lib/download-sources.js @@ -142,9 +142,8 @@ async function downloadGitSource( source, { onProgress, spinner, debug } ) { log( 'Fetching the specified ref.' ); const remote = await repository.getRemote( 'origin' ); - const oid = await NodeGit.Oid.fromString( source.ref ); - const commit = await NodeGit.Commit.lookupPrefix( repository, oid, 6 ); - const ref = commit.sha(); + 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 { From 7c105fc97acb8182a50b1d4f7e64b4c9d9bc59b4 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Fri, 5 Feb 2021 18:17:16 +0100 Subject: [PATCH 6/8] Revert "Try expanding short SHAs" This reverts commit 16070b0b773ab1f62fd6377bba8ef4d5a1cdb27c. --- packages/env/lib/download-sources.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/env/lib/download-sources.js b/packages/env/lib/download-sources.js index 308642cb9c12dc..d74f33d826484d 100644 --- a/packages/env/lib/download-sources.js +++ b/packages/env/lib/download-sources.js @@ -142,9 +142,7 @@ async function downloadGitSource( source, { onProgress, spinner, debug } ) { log( 'Fetching the specified ref.' ); const remote = await repository.getRemote( 'origin' ); - const oid = NodeGit.Oid.fromString( source.ref ); - const ref = NodeGit.Commit.lookupPrefix( repository, oid, 6 ); - await remote.fetch( ref, gitFetchOptions.fetchOpts ); + await remote.fetch( source.ref, gitFetchOptions.fetchOpts ); await remote.disconnect(); try { log( 'Checking out the specified ref.' ); @@ -153,14 +151,16 @@ 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, ref ) ), + .catch( + repository.getReference.bind( repository, source.ref ) + ), { checkoutStrategy: NodeGit.Checkout.STRATEGY.FORCE, } ); } catch ( error ) { log( 'Ref needs to be set as detached.' ); - await repository.setHeadDetached( ref ); + await repository.setHeadDetached( source.ref ); } onProgress( 1 ); From e1b20a03c1f1fa1a8033b5a648c572723450b004 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 8 Feb 2021 18:42:27 +0100 Subject: [PATCH 7/8] Use tag name instead of commit SHA --- .wp-env.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.wp-env.json b/.wp-env.json index 2d5ce3d259ccb1..4d67d71c82fb55 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -3,7 +3,7 @@ "plugins": [ "." ], - "themes": [ "WordPress/theme-experiments/tt1-blocks#f3d2c0d" ], + "themes": [ "WordPress/theme-experiments/tt1-blocks#tt1-blocks@0.4.3" ], "env": { "tests": { "mappings": { From 703c24af567975cb49f02ec3cb24188cf5a007c6 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 9 Feb 2021 13:35:19 +0100 Subject: [PATCH 8/8] Update unit test to reflect real-world example --- packages/env/lib/config/test/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/env/lib/config/test/config.js b/packages/env/lib/config/test/config.js index a20bf54569bbd8..fef400492b68c6 100644 --- a/packages/env/lib/config/test/config.js +++ b/packages/env/lib/config/test/config.js @@ -366,7 +366,7 @@ describe( 'readConfig', () => { 'WordPress/gutenberg', 'WordPress/gutenberg#master', 'WordPress/gutenberg#5.0', - 'WordPress/theme-experiments/tt1-blocks#f3d2c0d', + 'WordPress/theme-experiments/tt1-blocks#tt1-blocks@0.4.3', ], } ) ) @@ -399,7 +399,7 @@ describe( 'readConfig', () => { type: 'git', url: 'https://github.com/WordPress/theme-experiments.git', - ref: 'f3d2c0d', + ref: 'tt1-blocks@0.4.3', path: expect.stringMatching( /^\/.*theme-experiments\/tt1-blocks$/ ),