Add existing source code into repo management
Applicable to the source code of non source code management (git/repo) in large projects
preface
When the company is developing some projects, the code given from the supplier's original factory does not contain any source code management files. Many people need to cooperate in the development, but due to the large project and the low efficiency of git management, this article is summarized for your reference and a record of my stepping on the pit.
It's the first time to post a technology blog. If you have any mistakes or questions, you're welcome to put forward them
1, repo introduction and installation
1. What is repo
Repo is used by Google Python A script written to call git can manage multiple git libraries
Repo implements many functions, such as repo init, repo sync, repo forall and so on. If you don't know the big pot, go to learn more.
2.repo installation
As for the installation of repo, I wrote a linux shell script, so I have to go to the terminal to knock. The details are as follows:
#!/bin/sh mkdir ~/bin curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo chmod a+x ~/bin/repo export PATH=~/bin:$PATH echo "export PATH=~/bin:$PATH" >> ~/.bashrc export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/' echo "export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'" >> ~/.bashrc
Copy and save the above, add executable permissions to it, and then run it.
If you're not sure if it's installed? Can run
which repo
See if it's in your home directory
Just the one above, done~
2, New project git warehouse
1. Get path file
Before building a new warehouse, you need to determine where you need to build a new warehouse in the project. If you don't know, you need to determine one by one, or find the project in the original warehouse List file. Later, you need to use the path of git to be created in this project.
If you cannot find project List file, you can only find default xml file, you need to use cat+awk and other commands to filter out the path path in xml. For the specific rules describing the syntax in the file of repo warehouse, please click ! Call you to take me!
ps: (in the actual xml file, the name is the git directory of the repo warehouse. Here, for the convenience of later script operations, use path, which does not affect)
Similar path files are as follows (the path files mentioned later refer to this file):
2. Create a new git warehouse for the server
Operate gitolite in the git management account, and use the path file to edit gitolite.com under gitolite admin / conf Conf file:
After adding and uploading, gitolite tool will automatically create all warehouses through the hook program
git add -A && git commit -m "Create project warehouse" git push origin master
3, Client upload code
1. Write one click upload shell script
Here is also the one click upload of the script, as follows:
#!/bin/sh pause(){ echo $1 echo "exec fail!!!" exit 1 } PRO_DIRS=$1 PROJECT_PATH=Your server code path (absolute address) PRO_REPO_DIR=This project server repo Home directory, similar( git@localhost:Project home directory) you only need to write the name of the project home directory, because access gitolte Will automatically~/repositories Look down echo "cd $PROJECT_PATH" cd $PROJECT_PATH || pause parent_path=`pwd` echo "dir:"$parent_path ##Label counting is convenient to locate which address is wrong, and subsequent manual maintenance NUM=0 ##Success count CNT=0 while read dir; do NUM=`expr $NUM + 1`; if test -d $dir then cd $parent_path/$dir || pause "cd $parent_path/$dir" ##New empty warehouse git init || pause "git init" ##Add all files in this directory git add -A || pause "git add -A ..." ##Submit git commit -m "init commit" || pause "git commit -m "init commit" ..." ##Add remote address git remote add origin $PRO_REPO_DIR/$dir.git || pause "git remote add origin $PRO_REPO_DIR/$dir" ##Upload in branch git push origin master || pause "git push origin master ..." echo "line:$NUM $dir init repositories ok!!!" CNT=`expr $CNT + 1`; cd $parent_path || pause "cd $parent_path" continue else echo "line:$NUM $dir is not exists!!!" fi done echo "successful init count: $CNT" echo "check done!!" exit 0
Save and grant execution permission
repo_update.sh
2. Run the script
-
You can delete some execution functions. First determine which folders exist in the path file and which need to be created as needed.
-
Before running this script, make sure that the path file is consistent with the actual warehouse address to be created, otherwise it will be difficult to operate in the future.
cat Path file | ./repo_update.sh
Wait for the progress, barabarabara.
~~
After all, the repo warehouse is successfully created, but:
We also lack the manifest file required by the repo repository
III Client editing manifest file
Old rules or scripts
1. Edit a script to generate the manifest file
This script is not much different from one click upload
#!/bin/sh pause(){ echo $1 echo "exec fail!!!" exit 1 } PRO_DIRS=$1 parent_path=`pwd` echo "dir:"$parent_path NUM=0 CNT=0 MANIFESTS_FILE=$parent_path/default.xml PROJECT_DIR=The absolute path of the project source code directory is used to verify the effectiveness ##write head echo "write head.." echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <manifest> <remote name=\"repo Warehouse name\" fetch=\".\" review=\"gitmngr@localhost git address\" /> <default revision=\"master branch\" remote=\"repo Warehouse name\" sync-j=\"8\" /> ">$MANIFESTS_FILE echo "write project path and neme..." while read dir; do NUM=`expr $NUM + 1`; if test -d $PROJECT_DIR/$dir then CNT=`expr $CNT + 1`; echo "<project path="\"$dir\"" name="\"$dir\"" />">>$MANIFESTS_FILE continue else echo "line:$NUM $dir is not exists!!!" fi done echo "write tail.." echo " </manifest> ">>$MANIFESTS_FILE echo "write count: $CNT" echo "write done!!" exit 0
2. Run the script
cat Path file | ./generate_manifest.sh
After successful execution, a default will be generated in the current directory XML file
Check this xml file to see what requires linkfile attributes and copyfile attributes. These attributes will perform copy and link actions when you repo sync. The files in the root directory of our project source code are linked / copied from other places, otherwise the subsequent repo sync files or compilation errors may occur (important, very important)
2. Clone the manifest file warehouse
git clone git@xxxxxxx:project/manifests.git
3. Upload files
The generated and modified default Put the XML file into the cloned directory and upload it:
git add -A && git commit -m "init commit manifests" git push
OK ~ almost, start testing our results.
IV Test our repo warehouse
We create a new folder on the client and run it in:
repo init -u git@xxxxxxx:project/manifests.git
Success ~ enter the long wait, and then harvest joy
TKS~
The code word is not easy, please indicate the reprint~