gitolite 搭建Android仓库(二)

gitolite – 导入 Android 代码镜像仓库

平时在github上创建仓库、推拉代码、创建 Pull/Merge Request、发起 Issue 。
如果是本地代码 git 只能跟踪的代码信息,无法完成如上操作。本文介绍利用 gitolite 搭建本地git存档信息平台,可以实现类似功能。
本文以搭建鸿蒙代码仓库为例,讲解 gitolite 导入鸿蒙源码镜像仓,以管理代码授权密钥管理授权源码同步。


提示:此文章仅为搭建repo镜像仓,下一篇为 repo代码反向生成 repo镜像仓。


Gitolite 实现目标

a) 搭建本地Androi SDK repo 仓库,创建 Pull/Merge Request
b) 增加私有代码仓,不影响代码迭代更新
c) 管控授权密钥,分配用户仓库


1. 同步 repo 仓库代码

如果当前用也有Andoid 代码镜像仓可跳过此步骤;本文以搭建鸿蒙本地代码镜像仓为例。

1.1 配置git和安装repo

git 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-repo

1.2 安装 git-lfs

sudo apt-get install git-lfs

1.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

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
- <remote fetch="ssh://git@www.rockchip.com.cn/linux/" name="rk"/>
+ <remote fetch="ssh://git@192.168.1.88/rk3288_linux/" name="rk"/>
  • 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,发现躺坑很多,各种查资料,问题解决特此记述。
希望我的前车之鉴能为你省点时间。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值