在 GitLab 升级至 17.0 版本后,遇到了部分仓库无法推送代码的问题。
具体报错如下:
Enumerating objects: 85550, done.
Counting objects: 100% (85550/85550), done.
Delta compression using up to 11 threads
Compressing objects: 100% (18362/18362), done.
Writing objects: 100% (85550/85550), 59.45 MiB | 197.00 KiB/s, done.
Total 85550 (delta 53836), reused 85548 (delta 53834), pack-reused 0
remote: error: object 5bea0fbd6b56c8c63223a056f7c7e84215f555f9: gitmodulesUrl: disallowed submodule url: https://xxxx.com:txxxxxu/resetprop.git
remote: fatal: fsck error in packed object
error: remote unpack failed: index-pack abnormal exit
症状
使用 git 命令进行仓库检查:
# git fsck --full 1 ↵ master
Checking object directories: 100% (256/256), done.
Checking objects: 100% (85869/85869), done.
error in blob 5bea0fbd6b56c8c63223a056f7c7e84215f555f9: gitmodulesUrl: disallowed submodule url: https://xxxx.com:txxxxxu/resetprop.git
dangling tree 7a58a48c0b40bacf61e57f5bfc44a05cbee841dc
dangling commit 50803c338ae5205ee5f096d38e1fa32901cd2e2a
dangling commit 0905adcd6442d891c93d268dfd4f9c59306d34f0
dangling commit a721b2ad8414bb588bce0fa53814b7f4ac4f0c47
dangling commit ae78b2e8b0d3656bae4ec0ae2a62ea47e47534ec
dangling commit 73544bf3ed48fd3c8f4f91c845e1dbf85e1be19a
dangling commit c46307ebcf6018af7ec78515665131d2412753e4
可见其报错一致,参考其 GitLab 发布的官方通告 Encountering gitmodulesUrl: disallowed submodule url error when running repository check,其产生原因为 GitLab 17.0 版本开始使用了新版本的 Gitaly 组件,对所有历史存在的子模块地址会进行严格扫描,因此如果项目中存在不规范的地址引用即会报错。
解决方法
解决办法有两种,一种是从服务端入手,修改其安全策略,让其不扫描此项,但是会产生些许安全风险。另外就是重新整理仓库,将其异常的提交进行修复。
修改服务端仓库一致性检查配置
参照其官方文档,从 GitLab 15.10 之后的版本开始,修改 /etc/gitlab/gitlab.rb
:
gitaly['configuration'] = {
# ...
git: {
# ...
config: [
{ key: "fetch.fsck.gitmodulesUrl", value: "ignore" },
{ key: "fsck.gitmodulesUrl", value: "ignore" },
{ key: "receive.fsck.gitmodulesUrl", value: "ignore" },
],
},
}
小贴士:需要注意的是fetch
,fsck
,receive
三个参数必须都加入,分别对应的是获取、检查、接收三种操作,才能完成代码推送的整个流程。
其中的 key 为 Git 本身的一致性检查参数,所有可用项可以参考其官方文档 FSCK MESSAGES。
修改完成后重新生成配置并重启服务即可。
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
重新整理仓库移除异常子模块
在此以仓库 Magisk 为例,因仓库的提交历史中存在异常,在 fsck 时会报错:
Checking object directories: 100% (256/256), done.
Checking objects: 100% (85869/85869), done.
error in blob 5bea0fbd6b56c8c63223a056f7c7e84215f555f9: gitmodulesUrl: disallowed submodule url: https://github.com:topjohnwu/resetprop.git
dangling tree 7a58a48c0b40bacf61e57f5bfc44a05cbee841dc
dangling commit 50803c338ae5205ee5f096d38e1fa32901cd2e2a
dangling commit 0905adcd6442d891c93d268dfd4f9c59306d34f0
dangling commit a721b2ad8414bb588bce0fa53814b7f4ac4f0c47
dangling commit ae78b2e8b0d3656bae4ec0ae2a62ea47e47534ec
dangling commit 73544bf3ed48fd3c8f4f91c845e1dbf85e1be19a
dangling commit c46307ebcf6018af7ec78515665131d2412753e4
使用命令查询问题所在的 commit
git log --grep="Add resetprop to Magisk"
git show 1d0c36a0abe8ca5a35276cf6434439985fd69a16
可以看到在这次提交了,提交了一个异常的子模块地址,查看具体改动
git show 1d0c36a0abe8ca5a35276cf6434439985fd69a16 .gitmodules
可见
diff --git a/.gitmodules b/.gitmodules
index 2ed75deed..5bea0fbd6 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,3 +4,6 @@
[submodule "jni/sepolicy-inject"]
path = jni/sepolicy-inject
url = https://github.com/topjohnwu/sepolicy-inject
+[submodule "jni/resetprop"]
+ path = jni/resetprop
+ url = https://github.com:topjohnwu/resetprop.git
确定问题后,可以使用 git-filter-repo 工具对仓库进行修正,然后重新提交即可。
cd Magisk/
vim ../1.txt
## 写入以下内容
https://github.com:topjohnwu/resetprop.git==>https://github.com/topjohnwu/resetprop.git
## 然后批量进行替换
git filter-repo --replace-text ../1.txt
## 修改后会移除 origin ,需要手动添加远程地址并推送,如果已经存在则需要强制推送
git remote add origin git-repo-address
git push --set-upstream origin --all
git push --set-upstream origin --tags
参数 --replace-text
具体使用方式可参考其文档
附录
参考链接
本文由 柒 创作,采用 知识共享署名4.0
国际许可协议进行许可。
转载本站文章前请注明出处,文章作者保留所有权限。
最后编辑时间: 2025-05-12 13:59 PM