背景
repo是Google開發的用于基于git管理Android版本庫的一個工具,管理多個Git倉庫的工具,它可以幫助您在一個代碼庫中管理多個Git倉庫的代碼。其在鴻蒙操作系統中大量使用。下面我們就介紹repo在wsl中的安裝部署。
安裝方法
- 使用中國科技大學資源
腳本install_repo.sh:
mkdir -p ~/.bin/repo
git clone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo ~/.bin/repo
chmod +x ~/.bin/repo/repo
echo 'export PATH=~/.bin/repo:$PATH' >> /root/.bashrc
source ~/.bashrc
腳本執行后重開終端。驗證:
root@DESKTOP-UKR8O1E:~# repo --version
<repo not installed>
repo launcher version 2.54(from /root/.bin/repo/repo)
git 2.34.1
Python 3.10.12 (main, Feb 4 2025, 14:57:36) [GCC 11.4.0]
OS Linux 5.10.16.3-microsoft-standard-WSL2 (#1 SMP Fri Apr 2 22:23:49 UTC 2021)
CPU x86_64 (x86_64)
Bug reports: https://issues.gerritcodereview.com/issues/new?component=1370071
- 使用清華大學資源
腳本install_repo.sh:
mkdir -p ~/.bin/repo
git clone https://mirrors.tuna.tsinghua.edu.cn/git/git-repo ~/.bin/repo
chmod +x ~/.bin/repo/repo
echo 'export PATH=~/.bin/repo:$PATH' >> /root/.bashrc
source ~/.bashrc
腳本執行后重開終端。驗證省略。
使用問題集錦
- repo init 提示“fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle“
root@DESKTOP-R500S71:/home/work# repo init -u https://gitee.com/ark-standalone-build/manifest.git -b master
Downloading Repo source from https://gerrit.googlesource.com/git-repo
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno 110] Connection timed out
fatal: cloning the git-repo repository failed, will remove '.repo/repo'
原因:國內網絡限制,無法訪問https://gerrit.googlesource.com/git-repo/clone.bundle
解決方法:
替換腳本replace_repo_url.sh,替換REPO_URL 內容為:https://mirrors.tuna.tsinghua.edu.cn/git/git-rep
#!/bin/bash# 查找repo路徑
REPO_PATH=$(which repo)if [ -z "$REPO_PATH" ]; thenecho "錯誤:未找到repo命令"exit 1
fi# 備份原始文件
BACKUP_PATH="${REPO_PATH}.bak"
echo "備份原始文件到 ${BACKUP_PATH}..."
sudo cp "$REPO_PATH" "$BACKUP_PATH"# 執行替換操作
echo "執行URL替換..."
sudo sed -i 's|https://gerrit.googlesource.com/git-repo|https://mirrors.tuna.tsinghua.edu.cn/git/git-repo|g' "$REPO_PATH"if [ $? -eq 0 ]; thenecho "替換成功完成!"
elseecho "替換過程中出現錯誤,已恢復備份"sudo mv "$BACKUP_PATH" "$REPO_PATH"exit 1
fi