[Blueprints] Support creating a local .git directory via git:directory resource #2787
+652
−36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds a new feature to the
git:directory
Blueprint resource: the ability to create a functional, local.git
directory alongside the checked-out files.Rationale
Currently, the
git:directory
resource downloads the contents of a repository path, but it doesn't bring any of the Git metadata with it. This means that Git-aware tools (like the command linegit
, editor integrations, etc.) don't recognize the directory as a Git repository.What's New?
A new boolean flag,
".git"
, has been added to thegit:directory
resource definition.When you set
".git": true
, the resource will create a.git
directory containing:HEAD
reference, pointing to the correct branch or commit..git/config
file configured with the remote origin and settings for a partial clone (promisor remote)..git/objects
..git/index
file, ensuring the repository starts with a clean working tree..git/refs/
for the checked-out branch and remote..git/shallow
file indicating the shallow clone depth.Usage Examples
Before (Standard Behavior):
This blueprint downloads only the specified directory's files.
Resulting Files:
After (With
.git
: true):By adding the
".git": true
flag, the blueprint now also creates the hidden.git
directory, turning the destination into a working Git repository.Resulting Files:
With this new structure, you can now run
git status
inside thegutenberg
directory and get a correct reading of the repository state.Implementation Details
sparseCheckout
function in@wp-playground/storage
now returns not only the file contents (blobs) but also the raw Git objects (commits, trees) required to construct the repository history.git clone --depth=1 --filter=blob:none
). It only downloads the objects necessary for the initial checkout, with the configuration to fetch more from the remote origin as needed.isomorphic-git
library is used to programmatically build the.git/index
file from the list of checked-out files and their corresponding object hashes.Testing instructions
Create the following:
blueprint.json
file in your local Playground repository.Then, run the Blueprint from the usage examples in local CI:
Finally, confirm the repository was created as expected:
You should see status messages similar to those above.