正点原子repo放到自己的git服务器
atk-rk3568_android11
导出project-objects
对应仓库
.repo/repo/repo list -n > project-object.txt
将project-object.txt
格式化,并通过gitolite.conf
创建对应仓库
@atk-rk3568_android11_repo = atk-rk3568_android11/RKTools
@atk-rk3568_android11_repo = atk-rk3568_android11/device/common
@atk-rk3568_android11_repo = atk-rk3568_android11/device/generic/arm64
...
...
@atk-rk3568_android11_repo = atk-rk3568_android11/toolchain/benchmark
@atk-rk3568_android11_repo = atk-rk3568_android11/toolchain/pgo-profiles
@atk-rk3568_android11_repo = atk-rk3568_android11/tools/platform-compat
repo @atk-rk3568_android11_repo
RW+CD = evan
获取路径和项目
.repo/repo/repo forall -c 'echo $REPO_PATH' > path.txt
.repo/repo/repo forall -c 'echo $REPO_PROJECT' > project.txt
脚本
#!/bin/bash
# 常量定义
REP_URL="git@127.0.0.1:atk-rk3568_android11"
# 获取脚本的真实路径
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOG_FILE="$SCRIPT_DIR/script.log"
# 日志函数
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
}
# 显示帮助信息
usage() {
cat << EOF
Usage: $0 [OPTIONS] <DIR> <SRC_DIR>
This script initializes and pushes Git repositories based on paths and projects specified in files.
Options:
-h, --help Display this help message and exit.
Arguments:
DIR Directory containing path.txt and project.txt files.
SRC_DIR Source directory where the repositories are located.
Example:
$0 /path/to/dir /source/directory
The script reads paths from 'path.txt' and corresponding projects from 'project.txt',
initializes a Git repository for each path, commits changes, and pushes to the remote repository.
EOF
}
# 检查文件是否存在
check_files() {
if [ ! -f "$1" ] || [ ! -f "$2" ]; then
log "错误:找不到文件 $1 或 $2"
usage
exit 1
fi
}
# 初始化并推送 Git 仓库
init_and_push() {
local path="$1"
local project="$2"
local src_dir="$3"
# 进入目录
cd "$src_dir/$path" || { log "无法进入目录 $src_dir/$path"; return; }
# 删除 .git 目录(如果存在)
if [ -d ".git" ]; then
rm -rf .git
fi
# 初始化 Git 仓库
git init || { log "初始化 Git 仓库失败: $path"; return; }
# 添加所有文件
git add . || { log "添加文件失败: $path"; return; }
# 提交更改
git commit -m "first commit && create master branch" || { log "提交失败: $path"; return; }
# 添加远程仓库
git remote add origin "$REP_URL/$project" || { log "添加远程仓库失败: $path"; return; }
# 推送至远程仓库
git push -u origin master || { log "推送失败: $path"; return; }
log "成功处理: $path : $project"
}
# 主逻辑
main() {
# 参数检查
if [ $# -eq 1 ] && ([ "$1" == "-h" ] || [ "$1" == "--help" ]); then
usage
exit 0
fi
if [ $# -ne 2 ]; then
log "错误:参数数量不正确"
usage
exit 1
fi
# 获取参数
DIR="$1"
SRC_DIR="$2"
# 文件路径
path_file="$DIR/path.txt"
project_file="$DIR/project.txt"
# 检查文件是否存在
check_files "$path_file" "$project_file"
# 打开文件并逐行读取
{
while IFS= read -r path_line && IFS= read -r project_line <&3; do
# 处理每一行
init_and_push "$path_line" "$project_line" "$SRC_DIR"
echo "==================================="
done < "$path_file" 3< "$project_file"
} 3<&- # 关闭文件描述符3
# 检查文件行数是否一致
if [ "$(wc -l < "$path_file")" -ne "$(wc -l < "$project_file")" ]; then
log "警告:$path_file 和 $project_file 的行数不一致。"
fi
}
# 调用主逻辑
main "$@"