Repository navigation
[Blueprints] Support creating a local .git directory via git:directory resource - #2787
Merged
Merged
Conversation
Co-authored-by: adamziel <205419+adamziel@users.noreply.github.com>
adamziel
marked this pull request as ready for review
October 16, 2025 20:28
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:directoryBlueprint resource: the ability to create a functional, local.gitdirectory alongside the checked-out files.Rationale
Currently, the
git:directoryresource 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:directoryresource definition.When you set
".git": true, the resource will create a.gitdirectory containing:HEADreference, pointing to the correct branch or commit..git/configfile configured with the remote origin and settings for a partial clone (promisor remote)..git/objects..git/indexfile, ensuring the repository starts with a clean working tree..git/refs/for the checked-out branch and remote..git/shallowfile indicating the shallow clone depth.Usage Examples
Before (Standard Behavior):
This blueprint downloads only the specified directory's files.
{ "steps": [ { "step": "writeFiles", "writeToPath": "/wordpress/wp-content/plugins/gutenberg", "filesTree": { "resource": "git:directory", "url": "https://github.com/WordPress/gutenberg.git", "ref": "trunk", "path": "packages/block-library/src/archives" } } ] }Resulting Files:
After (With
.git: true):By adding the
".git": trueflag, the blueprint now also creates the hidden.gitdirectory, turning the destination into a working Git repository.{ "steps": [ { "step": "writeFiles", "writeToPath": "/wordpress/wp-content/plugins/gutenberg", "filesTree": { "resource": "git:directory", "url": "https://github.com/WordPress/gutenberg.git", "ref": "trunk", "path": "packages/block-library/src/archives", ".git": true } } ] }Resulting Files:
With this new structure, you can now run
git statusinside thegutenbergdirectory and get a correct reading of the repository state.Implementation Details
sparseCheckoutfunction in@wp-playground/storagenow 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-gitlibrary is used to programmatically build the.git/indexfile from the list of checked-out files and their corresponding object hashes.Testing instructions
Create the following:
blueprint.jsonfile in your local Playground repository.{ "steps": [ { "step": "installPlugin", "options": { "activate": true, "targetFolderName": "blocky-formats" }, "pluginData": { "resource": "git:directory", "url": "https://github.com/dmsnell/blocky-formats.git", "ref": "trunk", "path": "", ".git": true } } ] }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.