WordPress / WordPress/php-toolkit
git:directory resolves only ref: "HEAD"; branches, tags, and commit SHAs all fail
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 61
- Forks
- 21
- Avg merge
- 19h 34m
- Merged PRs (30d)
- 7
Description
Summary
A git:directory data reference resolves only when ref is "HEAD". Branches, tags, and commit SHAs all fail, and the v1 schema documents ref as "The ref (branch, tag, or commit)".
There are two distinct failures behind this. Branches that exist on the remote fetch successfully and then fail on a local ref lookup. Tags and commit SHAs never get that far, because fetch() looks every ref up under refs/heads/.
This blocks gallery Blueprints such as blueprints/personal-crm, which uses ref: "dist/main". The JS Blueprints runtime accepts the same input, so the two runtimes diverge.
Follow-on to #292 and #294, which fixed the HEAD path through GitRemote. This is the same area, for every other ref form.
Reproduction
Save as blueprint.json, substituting each ref from the table below:
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"steps": [
{
"step": "installPlugin",
"options": { "activate": false, "targetFolderName": "under-test" },
"pluginData": {
"resource": "git:directory",
"url": "https://github.com/akirk/personal-crm",
"ref": "REF_UNDER_TEST",
"path": "/"
}
}
]
}
Run against any empty directory:
SITE=$(mktemp -d)
php blueprints.phar exec ./blueprint.json \
--mode=create-new-site \
--site-path="$SITE" \
--site-url=http://localhost:8888 \
--db-engine=sqlite
All three ref forms exist on the remote, ruling out a network/repo issue:
$ git ls-remote https://github.com/akirk/personal-crm refs/heads/main refs/heads/dist/main refs/tags/v1.1.1
48f7dc07f09945e4243a7a75cff284e519c1c652 refs/heads/dist/main
a4ec612f7fab6869859e4c60866b0641cf7bbf09 refs/heads/main
db0d844106b9703ed3731a689b9576745dd90267 refs/tags/v1.1.1
Results
ref |
Result | Error |
|---|---|---|
HEAD |
passes | |
main |
fails | GitException: Branch file not found: main |
dist/main |
fails | GitException: Failed to resolve branch file path: dist/main |
refs/heads/main |
fails | GitException: Branch file not found: refs/heads/main |
refs/heads/dist/main |
fails | GitException: Branch file not found: refs/heads/dist/main |
refs/remotes/origin/main |
fails | GitRemoteException: Branch "refs/heads/refs/remotes/origin/main" not found on remote origin |
v1.1.1 |
fails | GitRemoteException: Branch "refs/heads/v1.1.1" not found on remote origin |
refs/tags/v1.1.1 |
fails | GitRemoteException: Branch "refs/heads/refs/tags/v1.1.1" not found on remote origin |
a4ec612f7fab6869859e4c60866b0641cf7bbf09 |
fails | GitRemoteException: Branch "refs/heads/a4ec612f..." not found on remote origin |
Error
For an existing branch, the fetch succeeds and the failure comes afterward:
WordPress\Git\GitException: Failed to resolve branch file path: dist/main
at components/Git/class-gitrepository.php:337
#0 components/Git/class-gitremote.php(297): GitRepository->get_branch_tip('dist/main')
#1 components/Blueprints/DataReference/class-datareferenceresolver.php(177): GitRemote->pull('dist/main', Array)
Code path
Existing branches fail on a local lookup. In components/Git/class-gitremote.php, fetch() writes the fetched tip to refs/remotes/<remote>/<name>. pull() then calls $this->repository->get_branch_tip( $full_branch_name ) with the caller's raw ref, against the local repository, where nothing was written at that path. HEAD is the only ref that resolves, because a local HEAD already exists.
In components/Git/class-gitrepository.php, resolve_branch_file_path() also treats the ref as a path relative to the repository root, and rejects any name containing / that does not begin with refs/heads/ or refs/remotes/. That accounts for the different message on dist/main.
Tags and commit SHAs fail earlier, at the remote lookup. fetch() builds the remote ref as 'HEAD' === $full_branch_name ? 'HEAD' : 'refs/heads/' . $branch_name, and localize_ref_name() strips only a leading refs/heads/. Any tag, commit SHA, or refs/remotes/... name is therefore requested under refs/heads/ and is not found.
Environment
blueprints.pharv0.9.0, and the build bundled with WordPress Studio (from v0.8.1). Same behavior on both, so this is not a regression between them.- PHP 8.5.5.
Possibly separate
With ref: "HEAD", options.targetFolderName appears to be ignored: the plugin installs to wp-content/plugins/git-repo regardless. Observed on every passing run across both versions, with two different targetFolderName values. Happy to split this out if it is unrelated.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with components/Git/class-gitremote.php fetch() and pull(), then trace get_branch_tip() and resolve_branch_file_path() in components/Git/class-gitrepository.php. Use the provided blueprint reproduction with the listed branches, tags, remote refs, and commit SHA. Done means supported ref forms resolve through git:directory consistently with the JS runtime; keep the separate targetFolderName observation out of scope unless confirmed related.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100