Design logic
- The command line allows you to dynamically merge code from different repositories by passing values .
- determine if the code has been moved out to the local, if no need to move out first;
- get the version number of the trunk and the branch to facilitate future merging;
- if the trunk version number is greater than or equal to the branch version number, no merging is required;
- after merging, the skeleton version number is submitted to the trunk;
- Pull the trunk update log to see if the merge was successful;
Code logic
#!/bin/shif [-N $];then repos_name=$1 repos_url= ' svn://domain.com/' $repos _name repos_dir= '/root/svn _co_code/' $repos _name if [!-D $repos _dir];then cd/root/svn_co_code SVN co $repos _url fi trunk= $repos _url '/trunk ' dev= $repos _url '/branches/dev ' trunk_ver=$ (svn info ${trunk}-rhead | grep "Last modified version:" | Cut-d '-f2) dev_ver=$ (svn info ${dev}-rhead | grep "Last modified version:" | Cut-d '-f2) Echo ' Trunk Branch version number (trunk): ' $trunk _ver Echo ' Development Branch version number (Branches/dev): ' $dev _ver if [$trunk _ver- GE $dev _ver];then echo ' No need to merge ' exit fi cd $repos _dir pwd svn up cd $repos _dir '/ Trunk ' svn merge-r $trunk _ver: $dev _ver $dev svn ci-m "merge br [email protected]${dev_ver} to trunk" pwd< C24/>SVN log |more-2 qelse echo ' Please enter repository name ' Exitfi
Sample Example
Trunk: is the trunk branch. The production environment runs the code under this branch.
Branches/dev: Is the development branch. The developer code is mainly here.
The tester will occasionally merge the Code of the Development Branch into the trunk branch for testing.
Assume:
Repository address is: SVN://CODE.DOMAIN.COM/API
The local eviction code directory is stored in the following path:/root/svn_co_code/api
Can be executed directly under the command line
Sh./merge.sh API
To complete the automated merge
#!/bin/shif [-N $];then repos_name=$1 repos_url= ' svn://domain.com/' $repos _name repos_dir= '/root/svn _co_code/' $repos _name if [!-D $repos _dir];then cd/root/svn_co_code SVN co $repos _url fi trunk= $repos _url '/trunk ' dev= $repos _url '/branches/dev ' trunk_ver=$ (svn info ${trunk}-rhead | grep "Last modified version:" | Cut-d '-f2) dev_ver=$ (svn info ${dev}-rhead | grep "Last modified version:" | Cut-d '-f2) Echo ' Trunk Branch version number (trunk): ' $trunk _ver Echo ' Development Branch version number (Branches/dev): ' $dev _ver if [$trunk _ver- GE $dev _ver];then echo ' No need to merge ' exit fi cd $repos _dir pwd svn up cd $repos _dir '/ Trunk ' svn merge-r $trunk _ver: $dev _ver $dev svn ci-m "merge br [email protected]${dev_ver} to trunk" pwd< C24/>SVN log |more-2 qelse echo ' Please enter repository name ' Exitfi
Code Share--SVN Branch Merge (Development Branch merged into trunk)