Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

git:directory resolves only ref: "HEAD"; branches, tags, and commit SHAs all fail

未关闭
#306 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
git, php
领域
tooling

调研方向

从 components/Git/class-gitremote.php 中的 fetch() 和 pull() 开始,然后跟踪 components/Git/class-gitrepository.php 中的 get_branch_tip() 和 resolve_branch_file_path()。使用提供的 blueprint reproduction,以及其中列出的 branches、tags、remote refs 和 commit SHA。完成的标准是:受支持的 ref 形式能够通过 git:directory 以与 JS runtime 一致的方式解析;除非确认与之相关,否则将单独的 targetFolderName 观察结果排除在范围之外。

由索引模型根据 Issue 内容生成。

描述

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.phar v0.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.

主要语言
PHP
星标
62
派生
23
平均合并
4 小时 12 分钟
30 天内合并 PR
1

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

WordPress/php-toolkit 的其他 Issue

查看 WordPress/php-toolkit 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。