建立repo服务器四(多个项目repo批量下载)

下载git-repo
官网是https://code.google.com/archive/p/git-repo/

``` git clone https://android.googlesource.com/tools/repo

git clone https://gerrit.googlesource.com/git-repo ```

无法访问可以使用清华的mirror,https://mirror.tuna.tsinghua.edu.cn/help/git-repo/


  • 下载repo
客户端运行
$git clone https://mirror.tuna.tsinghua.edu.cn/help/git-repo/

$ vim  git-repo.git/repo
REPO_URL = 'ssh://192.168.199.119:29418/git-repo'
REPO_REV = 'master'

$ cp -f ./git-repo.git/repo  /bin    //注意:repo的REPO_VER为git-repo仓库的分支

//git-repo建仓
ssh -p 29418 [email protected] gerrit create-project  git-repo
rm -rf .git
git init 
git add ./
git commit -m "git-repo"
git push ssh://[email protected]:29418/git-repo  HEAD:refs/heads/master

git clone ssh://[email protected]:29418/git-repo 
git tag -a -m "master" master
git push origin –tags

每次使用repo命令时都会自动下载git-repo,故修改REPO_URL = 'ssh://192.168.199.119:29418/git-repo'


  • 将repo拷贝到客户端 ~/bin

在客户端空仓库原始代码里,运行脚本

#!/bin/bash

SERVER_IP="192.168.199.119"
SERVER_PORT="29418"
REMOTE_FETCH="ssh://${SERVER_IP}:${SERVER_PORT}/"
REMOTE_REVIEW="http://${SERVER_IP}"
PROJECT_NAME="testGit"
BRANCH="dev"
SRC_SOURCE=`pwd`

#根据目录下的.git创建project.list
#删除目录下的.git&.gitignore
#在空目录下创建.gitkeep,避免建仓时空目录不能提交
function createProjectList(){
    find ./ -name ".git" > project.list
    sed -ri "s/^..(.*)..git$/\1/" project.list    
    find ./ -name ".git" | xargs rm -rf {}
    find ./ -name ".gitignore" | xargs rm -rf {}
    touch .gitkeep
    find ./ -type d -empty | xargs -i cp ./.gitkeep {}
    rm -f ./.gitkeep

}

#创建manifests.xml清单文件
function createManifestsXml(){

    echo "" > manifest.xml
    echo "" >> manifest.xml
    echo "  " >> manifest.xml
    echo "  " >> manifest.xml
    echo "" >> manifest.xml
  
    GIT_PROJECTS=`cat project.list | xargs`

    for git_path in ${GIT_PROJECTS}  
    do
        if [ ${git_path} == "build" ]
        then
            echo "  " >> manifest.xml
                echo "      " >> manifest.xml
                echo "  " >> manifest.xml
        elif [ ${git_path} == "vendor/intel/support" ]
        then
            echo "  " >> manifest.xml
                echo "      " >> manifest.xml
            echo "      " >> manifest.xml
            echo "  " >> manifest.xml
        else
            echo "  " >> manifest.xml
        fi
    done
    echo "" >> manifest.xml
    echo "" >> manifest.xml
}

#远程建仓并提交SRC
function createRepo() {
    GIT_PROJECTS=`cat project.list | xargs`
    for repoName in ${GIT_PROJECTS}
    do
        #批量建仓
        echo "Init Empty Repo:${PROJECT_NAME}/${repoName}"
        ssh -p $SERVER_PORT git@$SERVER_IP gerrit create-project -n ${PROJECT_NAME}/${repoName}
    done

    while read git_name
    do
        if [ -d ${SRC_SOURCE}/${git_name} ]
        then
            echo "${SRC_SOURCE}/${git_name}"
            cd ${SRC_SOURCE}/${git_name}
            git init
            git add ./
            git commit -m "Init Repo"
            git push ssh://git@${SERVER_IP}:${SERVER_PORT}/${PROJECT_NAME}/${git_name}  HEAD:refs/heads/master
        fi
    done < project.list
}

createProjectList
createManifestsXml
createRepo

以上脚本为仅供参考脚本,有些。实际使用时需做适当修改

实践中的2种方法:

方法一、先建立本地git仓库:

1、创建git_create.sh,初始化空仓库,以下脚本测试过OK,可以优化为简单的for循环脚本,执行此脚本后源码将会建立很多个git仓库,可以自己定义,再细分,下载链接 ://download.csdn.net/download/xiangzi10/12053871

2、执行以下2条命令后将生成project.list文件,后面将会以此文件创建gerrit的仓库

$find ./ -name ".git" > project.list
$sed -ri "s/^..(.*)..git$/\1/" project.list

脚本执行完,会在gerrit服务器新建多个仓库

#cat project.list 
ndk
device
hardware
build
bootable
platform_testing
developers
tools
bionic
libnativehelper
libcore
abi
development
vendor/mstar/mif
vendor/mstar/pm
vendor/mstar/fpp
vendor/mstar/mboot/MBoot
vendor/mstar/kernel/linaro
vendor/mstar/rt-pm
vendor/mstar/supernova
system
external
docs
frameworks
pdk
art
cts
sdk
prebuilts
packages
dalvik

3、创建create_manifest.sh 脚本,下载链接如下://download.csdn.net/download/xiangzi10/12053682

执行此脚本后会自动创建manifest.xml文件,此文件以后将添加到manifest仓库作为repo下载的依据

4、创建create_GerritProject.sh,下载链接如下://download.csdn.net/download/xiangzi10/12053696

执行此脚本可以使用ssh -p $SERVER_PORT $gerrit_admin@$SERVER_IP gerrit create-project --empty-commit批量创建仓库

然后批量推送本地代码到gerrit仓库

至此gerrit仓库已完成。

方法二、先建立目录最后建立git仓库并上传:

使用一体化脚本


  • 创建gerrit manifest仓库

新建名为manifest仓库,下载到客户端,创建新分支,以后以分支名来区别不同的repo,添加刚才生成的manifest.xml

#git checkout -b MSD6A358

#git branch -a
* MSD6A358
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

#git status
#git add -A

#git commit -a -m "xxx"

#git push --set-upstream origin MSD6A358                建立远程分支

#git branch -a
* MSD6A358
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/MSD6A358
  remotes/origin/master


  • repo pull 远程代码:注意:参数--no-repo-verify为不验证签名
#repo init -u ssh://[email protected]:29418/manifests -b MSD6A358 -m manifest.xml
Get ssh://192.168.0.198:29418/git-repo
remote: Counting objects: 4496, done
remote: Finding sources: 100% (4496/4496)
remote: Total 4496 (delta 2972), reused 4496 (delta 2972)
Receiving objects: 100% (4496/4496), 1.52 MiB | 10.87 MiB/s, done.
Resolving deltas: 100% (2972/2972), done.
From ssh://192.168.0.198:29418/git-repo
 * [new branch]      master     -> origin/master

fatal: branch 'master' has not been signed
fatal: cloning the git-repo repository failed, will remove '.repo/repo' 

添加参数--no-repo-verify为不验证签名

#repo init -u ssh://[email protected]:29418/manifests -b MSD6A358 -m manifest.xml --no-repo-verify
Get ssh://192.168.0.198:29418/git-repo
remote: Counting objects: 4496, done
remote: Finding sources: 100% (4496/4496)
remote: Total 4496 (delta 2972), reused 4496 (delta 2972)
Receiving objects: 100% (4496/4496), 1.52 MiB | 11.10 MiB/s, done.
Resolving deltas: 100% (2972/2972), done.
From ssh://192.168.0.198:29418/git-repo
 * [new branch]      master     -> origin/master
Get ssh://[email protected]:29418/manifests
fatal: No names found, cannot describe anything.
remote: Counting objects: 6, done        
remote: Finding sources: 100% (6/6)           
remote: Total 6 (delta 0), reused 4 (delta 0)        
From ssh://192.168.0.198:29418/manifests
 * [new branch]      MSD6A358 -> origin/MSD6A358
 * [new branch]      master        -> origin/master

Your identity is: xxx 
If you want to change this, please re-run 'repo init' with --config-name

repo has been initialized in /home/htp828/sda1_2tb/clone/repo_358
#ls -ll .repo/
total 12
drwxrwxr-x  3 htp828 htp828 4096 Dec 25 10:59 manifests
drwxrwxr-x 10 htp828 htp828 4096 Dec 25 10:59 manifests.git
lrwxrwxrwx  1 htp828 htp828   22 Dec 25 10:59 manifest.xml -> manifests/manifest.xml
drwxrwxr-x  7 htp828 htp828 4096 Dec 25 10:59 repo

成功

#repo sync 成功下载代码

#repo start devo --all
给所有仓库弄一个本地分支

git add
git commit -m "xxx"
git pull --rebase
repo upload .----失败
git  push origin HEAD:refs/for/master

repo forall -c 就是对所有仓库递归,当然没有必要提交的要先清掉
repo forall -c git add . 这样是可以递归的
repo forall -c git commit -m "xxx"
repo forall -c git pull --rebase
repo forall -c git push origin HEAD:refs/for/master


问题点:

Q1:没有注册邮箱,group member不能识别

#git  push origin HEAD:refs/for/master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 319 bytes | 319.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2)
remote: Processing changes: refs: 1, done    
remote: ERROR: commit dba6a7c: email address [email protected] is not registered in your account, and you lack 'forge committer' permission.
remote: You have not registered any email addresses.
remote: To register an email address, visit:
remote: http://192.168.0.198:8081/settings#EmailAddresses
remote: 
remote: 
To ssh://192.168.0.198:29418/MSD6A358/build
 ! [remote rejected] HEAD -> refs/for/master (commit dba6a7c: invalid committer)
error: failed to push some refs to 'ssh://192.168.0.198:29418/MSD6A358/build'

原因:repo init时使用了git用户,但是push使用的不是这个用户,导致出错。

#git  push ssh://[email protected]:29418/MSD6A358/build HEAD:refs/for/master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 319 bytes | 319.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2)
remote: Processing changes: refs: 1, new: 1, done    
remote: 
remote: SUCCESS
remote: 
remote:   http://192.168.0.198:8081/c/MSD6A358/build/+/63 test [NEW]
remote: 
To ssh://192.168.0.198:29418/MSD6A358/build
 * [new branch]      HEAD -> refs/for/master

故repo init时要注意不用带用户@,repo init -u ssh://git@192.168.0.198:29418/manifests -b MSD6A358 -m manifest.xml --no-repo-verify

解决办法:gerrit添加权限

建立repo服务器四(多个项目repo批量下载)_第1张图片

Q2:#repo init -u ssh://[email protected]:29418/repo/MSD6A648/manifests.git --no-repo-verify
Get ssh://192.168.0.198:29418/git-repo
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: cloning the git-repo repository failed, will remove '.repo/repo' 

错误:

cat ~/.ssh/id_rsa.pub

将公钥加入到gerrit服务器上

建立repo服务器四(多个项目repo批量下载)_第2张图片

#touch ~/.ssh/config

#vi ~/.ssh/config

Host 192.168.0.198
HostName 192.168.0.198
User 201
IdentityFile ~/.ssh/id_rsa

#rm -rf ~/.repoconfig

#rm -rf .repo

#repo init -u ssh://192.168.0.198:29418/repo/MSD6A648/manifests.git --no-repo-verify
Get ssh://192.168.0.198:29418/git-repo
remote: Counting objects: 4496, done
remote: Finding sources: 100% (4496/4496)
remote: Total 4496 (delta 2972), reused 4496 (delta 2972)
Receiving objects: 100% (4496/4496), 1.52 MiB | 10.64 MiB/s, done.
Resolving deltas: 100% (2972/2972), done.
From ssh://192.168.0.198:29418/git-repo
 * [new branch]      master     -> origin/master
Get ssh://192.168.0.198:29418/repo/MSD6A648/manifests.git
fatal: No names found, cannot describe anything.
fatal: project repo/MSD6A648/manifests not found
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: project repo/MSD6A648/manifests not found
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: cannot obtain manifest ssh://192.168.0.198:29418/repo/MSD6A648/manifests.git

git clone "ssh://[email protected]:29418/repo/MSD6A648/manifest"

单独获取是可以的

你可能感兴趣的:(git版本控制)