Repository navigation
Fix wp-env can't checkout git repositories of a specific tag. - #31271
Conversation
|
Found relevant discussion on Slack https://wordpress.slack.com/archives/C02QB2JS7/p1618478772435400. cc @ockham :) |
|
Related to #31271 (comment): I was able to repro now. The key is to make
diff --git a/.wp-env.json b/.wp-env.json
index 260787b97f..2849ba4450 100644
--- a/.wp-env.json
+++ b/.wp-env.json
@@ -1,9 +1,7 @@
{
"core": "WordPress/WordPress",
- "plugins": [
- "."
- ],
- "themes": [ "WordPress/theme-experiments/tt1-blocks#tt1-blocks@0.4.5" ],
+ "plugins": [ "." ],
+ "themes": [ "WordPress/theme-experiments/tt1-blocks#tt1-blocks@0.4.3" ],
"env": {
"tests": {
"mappings": {
|
|
If (after #31271 (comment)) I then switch to this branch, So it still seems good for me. @noahtallen can you provide instructions how to repro the scenario you were worried about here? |
|
The truth is, I'm not really sure how Maybe @noahtallen can shed some light on this? |
Thanks for those steps, I'll try to troubleshoot based on that! The existing code is supposed to handle fetching and checking out a new ref if the source has already been cloned or not. The code proposed here (theoretically) only handles cloning and checking out a ref if the source does not exist yet. |
|
Perhaps restoring the lines that were removed would then make it work on both new repositories and existing repositories. |
And to clarify, this is exactly how it's supposed to work 😅 (e.g. you're right: it's confusing that it's not working) |
I think this makes sense to me. The current fix doesn't attempt to check out the new tag anymore, because it's gated behind |
|
Oh... And this situation also crashes on trunk because trunk tries to checkout the ref 4.5... But in the repro steps, we deleted the 4.5 tag locally, so it doesn't exist. (which is exactly what the git error is complaining about). It doesn't crash on this branch because of my previous comment (e.g. it never tries to check anything out) |
|
I was able to replicate locally in the git repo. The fetch command doesn't seem to always make the tag available for checkout locally: Does not work: # Make tag unavailable locally:
$ git checkout tt1-blocks@0.4.3 && git tag -d tt1-blocks@0.4.5
# Try to fetch it again from the origin:
$ git fetch origin tt1-blocks@0.4.5
From https://github.com/WordPress/theme-experiments
* tag tt1-blocks@0.4.5 -> FETCH_HEAD
$ git checkout tags/tt1-blocks@0.4.5
error: pathspec 'tags/tt1-blocks@0.4.5' did not match any file(s) known to gitDoes work: # Make tag unavailable locally:
$ git checkout tt1-blocks@0.4.3 && git tag -d tt1-blocks@0.4.5
# Try to fetch it again from the origin:
$ git fetch origin tt1-blocks@0.4.5:tt1-blocks@0.4.5
From https://github.com/WordPress/theme-experiments
* [new tag] tt1-blocks@0.4.5 -> tt1-blocks@0.4.5
*
$ git checkout tags/tt1-blocks@0.4.5
Previous HEAD position was 7aaf36d Merge pull request #188 from WordPress/tt1-blocks/version-bump-0.4.3
HEAD is now at d290b42 Merge pull request #243 from WordPress/tt1-blocks/version-bump-4-4-5 |
|
This patch seems to fix the problem for me: diff --git a/packages/env/lib/download-sources.js b/packages/env/lib/download-sources.js
index d87cd8e821..73e338ddf6 100644
--- a/packages/env/lib/download-sources.js
+++ b/packages/env/lib/download-sources.js
@@ -128,7 +128,9 @@ async function downloadGitSource( source, { onProgress, spinner, debug } ) {
}
log( 'Fetching the specified ref.' );
- await git.fetch( 'origin', source.ref );
+ await git.fetch( 'origin', `${ source.ref }:${ source.ref }`, {
+ '-u': true,
+ } );
log( 'Checking out the specified ref.' );
await git.checkout( source.ref );edit: I don't think this is perfect. You aren't supposed to use |
|
After tinkering a bit, maybe we should just be less clever about it. I think our problems are partially caused by trying to update the repo if it already exists. This gets challenging. For example, if we just want to pull the I'm not quite sure exactly what to do. My intuition right now is to try to clear the local git state somehow so that when we fetch and checkout from the remote, nothing conflicts locally 🤔 |
|
I've updated the test instructions on how to test on both new and existing repo. :) Thanks @ockham @noahtallen for testing it out and also.. the enthusiasm!!! |
noahtallen
left a comment
There was a problem hiding this comment.
This tests fantastically for me! It solves the crash which happens in the scenario @ockham described. Will merge this once tests pass 👍
As a follow up, I plan to fix the problem with pulling / fetching branches.
|
Follow-up PR: #31362 |


Description
Whenever I run
npm run wp-env start, I'm getting the errorGitError: error: pathspec 'tt1-blocks@0.4.5' did not match any file(s) known to git.Here's the full log.
Why it failed?
It appears that using the git clone option for
depth=1 --no-single-branchonly pulls the tip of all branches, not all tags.The
tt1-blocks@0.4.5is a tag ofWordPress/theme-experiments.How has this been tested?
Test wp-env with newly cloned repo
rm -fr ~/.wp-env/*.npm run wp-env start.cat ~/.wp-env/*/theme-experiments/tt1-blocks/style.css | grep Version.Version: 0.4.5.Test wp-env with previously cloned repo
cd ~/.wp-env/*/theme-experiments.git checkout tt1-blocks@0.4.3.git tag -d tt1-blocks@0.4.5.npm run wp-env start.cat ~/.wp-env/*/theme-experiments/tt1-blocks/style.css | grep Version.Version: 0.4.5as well.Screenshots
Types of changes
Bug fix
Checklist:
*.native.jsfiles for terms that need renaming or removal).