平时在github上创建仓库、推拉代码、创建 Pull/Merge Request、发起 Issue 。
如果是本地代码 git 只能跟踪的代码信息,无法完成如上操作。本文介绍利用 gitolite 搭建本地git存档信息平台,可以实现类似功能。
提示:此文章仅为搭建repo镜像仓,下一篇为 repo代码反向生成 repo镜像仓。
文章目录- gitolite -- 导入 Android 代码镜像仓库
- Gitolite 实现目标
- 1. 同步 repo 仓库代码
- 1.1 配置git和安装repo
- 1.2 安装 git-lfs
- 1.3 下载harmony代码
- 2. 部署repo镜像仓到 gitolite
- 2.1 整理harmony 仓库路径配置信息
- 2.2 验证用户下载代码
- 2.3 repo常见问题分析
- 总结
Gitolite 实现目标
a) 搭建本地Androi SDK repo 仓库,创建 Pull/Merge Request
b) 增加私有代码仓,不影响代码迭代更新
c) 管控授权密钥,分配用户仓库
1. 同步 repo 仓库代码
如果当前用也有Andoid 代码镜像仓可跳过此步骤;本文以搭建鸿蒙本地代码镜像仓为例。
1.1 配置git和安装repogit config --global user.name "yourname" git config --global user.email "your-email-address" git config --global credential.helper store curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/bin/repo chmod a+x /usr/bin/repo pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests
提示 安装repo时如提示无权限,可下载至其他目录,并将其配置到环境变量中。
或者使用系统默认安装提示。
$ repo Command 'repo' not found, but can be installed with: sudo snap install git-repo1.2 安装 git-lfs
sudo apt-get install git-lfs1.3 下载harmony代码
使用 repo 下载代码格式如下:
repo init -u ssh://user_name@IP:path/xxx_manifestsgit -b branch_name -m manifest_name.xml --mirror
注意 -b选择分支,比如master或OpenHarmony-3.1-Beta; --mirror 下载镜像模式
mkdir -p ~/repositories/harmony cd ~/repositories/harmony repo init -u https://gitee.com/openharmony/manifest.git -b refs/tags/OpenHarmony-v3.1-Beta --no-repo-verify --mirror repo sync -c repo forall -c 'git lfs pull' sudo bash build/prebuilts_download.sh
注意:执行“bash build/prebuilts_download.sh”会因网络异常终中断,支持断点下载,重新下载即可。须确保预编译的工具都下载完成。
2. 部署repo镜像仓到 gitolite 2.1 整理harmony 仓库路径配置信息生成harmony repo list
cd ~/repositories/harmony .repo/repo/repo list -n > harmony.conf sed -i 's/^/harmony//g' harmony.conf sed -i 's/n/ /g' harmony.conf sed ':a;N;s/n/ /;t a' harmony.conf > .harmony.conf; mv .harmony.conf harmony.conf sed -i 's/^/@harmony = /g' harmony.conf
添加 harmony.conf 到 gitolite
cp harmony.conf ~/gitolite-admin/conf
cd ~/gitolite-admin
vi conf/gitolite.conf #尾行添加 引用 include harmony.conf, @user 用户组成员,RW+ = @users 读写授权用户组
include "harmony.conf"
@users = git
repo @harmony
RW+ = @users
$ git diff
diff --git a/conf/gitolite.conf b/conf/gitolite.conf
index ae1dc08..96517a3 100644
--- a/conf/gitolite.conf
+++ b/conf/gitolite.conf
@@ -1,2 +1,8 @@
repo gitolite-admin
RW+ = git
+
+include "harmony.conf"
+
+@users = git
+repo @harmony
1. RW+ = @users
提示 harmony.conf 需一同提交;本地提交完成后,再推送到远程方可生效。
2.2 验证用户下载代码客户下下载代码
repo init -u ssh://user_name@IP:path/xxx_manifests.git -b master -m manifest.xml
path是相对 repositories中代码仓路径,xxx_manifests.git 为 manifest.git 相对harmony(代码镜像仓)路径
mkdir -p ~/harmony cd ~/harmony repo init -u git@127.0.0.1:harmony/openharmony/manifest.git -b refs/tags/OpenHarmony-v3.1-Beta --no-repo-verify repo sync -c repo forall -c 'git lfs pull' sudo bash build/prebuilts_download.sh
注意 如果gitolite管理用户名非“git”,请替换 git@ 中git为实际用户名;127.0.0.1是回环IP,实际使用中请替换为host IP。
2.3 repo常见问题分析ConfigParser.ParsingError: File contains parsing errors: /data/git/.gitosis.conf
- 配置文件不同步引起,解决方法
cp ~/gitolite-admin/gitosis.conf ~/.gitosis.conf
- repo init 建仓成功,但是同步是提示无原始仓权限
Please make sure you have the correct access rights and the repository exits. git@www.rockchip.com.cn: Persmission denied (publickey). fltal : Could not read from remote repository.
原因:本地使用 .repo/xxx_manifest.xml 的 ssh路径未修改为本地镜像仓库
vi .repo/manifest.xml- +
- repo代码同步提示无分支
fatal: Couldn't find remote ref refs/heads/harmony fatal: The remote end hung up unexpectedly
此情况请核对检出分支名是否正确
repo init -u grrit_URL -b branch(分支名不对) -m manifest.xml
- repo 初始化代码仓库未开通权限,但是其它代码有设定此用户密钥。
FATAL: R any rk288_linux/rockchip/platform/manifests user DENIED by fallthru (or you mis-spelled the reponame) fatal: Could not read from remote repository.
解决方法:开通要同步仓库权限即可
总结
万事皆有因果,刨根问底方知原委。尝试不用git用户搭建gitolite,发现躺坑很多,各种查资料,问题解决特此记述。
希望我的前车之鉴能为你省点时间。



