如何从客户端获取未关联分支的Git refs/results引用?
获取Git服务器上的测试结果引用(refs/results/)
核心操作步骤
1. 临时拉取结果引用
如果仅需获取某一次源码提交对应的测试结果,执行以下命令(替换<源码提交哈希>为目标提交的哈希值,比如deadbeef):
git fetch origin refs/results/<源码提交哈希>:refs/remotes/origin/results/<源码提交哈希>
若要一次性拉取服务器上所有测试结果引用,执行:
git fetch origin 'refs/results/*:refs/remotes/origin/results/*'
2. 永久配置自动拉取
如果希望每次执行git fetch时自动同步refs/results命名空间下的所有引用,修改本地仓库的.git/config文件:
找到[remote "origin"]段落,添加一行配置:
fetch = +refs/results/*:refs/remotes/origin/results/*
之后执行git fetch就会自动拉取所有测试结果引用。
3. 查看或访问结果
拉取完成后,可通过以下方式操作:
- 查看结果提交的内容:
git show origin/results/<源码提交哈希> - 切换到结果提交的工作区(进入 detached HEAD 模式):
git checkout origin/results/<源码提交哈希> - 查看最新测试结果(钩子会自动更新
results标签):git fetch origin results git show results
现有实现背景
Git日志结构
仓库的日志结构如下(测试结果提交与源码提交平行独立存在):
* bot: add results from `make run` / * Change experimental setup | | * bot: add results from `make run` | * Add feature | | * bot: add results from `make run` | * Initial commit
设计动机
为每个测试结果创建独立提交节点的原因:
- 测试输出通常体积较大,无需为其保留完整分支历史
- 结果与源码提交一一绑定,可通过源码哈希快速定位对应测试结果,保证实验复现性
完整post-receive钩子代码
#!/bin/sh -e # post-receive hook receives its arguments on stdin # in case multiple branches are pushed at once, we use a while loop while read oldrev newrev refname do branch=$(git rev-parse --symbolic --abbrev-ref "${refname}") if [ "${branch}" = "run" ]; then cd .. unset GIT_DIR git checkout run # Enter detached-HEAD mode. # Commits made are not added to any particular branch. git checkout HEAD # In the event of error, we must checkout dummy so users can push to the run # branch (pushing is not allowed if the branch is checked out). make run || git checkout -B dummy git add --all git commit --message 'results from `make run`' \ --author 'results bot <@>' # Add a reference so we can find the results commit using the hash of # the commit containing the code used to generate the results. git update-ref "refs/results/$(git rev-parse HEAD~)" HEAD # Also tag the latest results "results" git tag --delete results git tag results HEAD # Now, if we have some code in commit deadbeef..., its results can be # found in refs/results/deadbeef... This ref will be transferred to # the user next time they run `git fetch` or `git pull`. # Finally, un-checkout run. Having it checked out will interfere with # users pushing code to it. git checkout -B dummy cd - fi done
内容的提问来源于stack exchange,提问作者Zaz
相关产品推荐
相关产品推荐

