One of the applications of my customer in being maintained by an external vendor. The vendor delivers code to a separated SVN repository, by importing it every time as a new tag. This causes a few difficulties:
- SVN is not able to report code differences between two versions
- all available at the company tooling has to be configured to scan additional SVN repository
To resolve this problem I wrote a script, which extracts newly delivered code from “external” SVN repository and commits it as a single change to a trunk in another repository.
The script uses SVN CLI and has been tested with both 1.6 and 1.7 versions. The following limitations are known… and any improvement suggestions are very welcome:
- it behaves like CVS, renaming of a file or directory is seen as deletion of the old file and adding a new one. The fact of renaming is lost to importing of the code by vendor
The script is also available in Bitbucket
9 | test $error_code == 0 && exit 1; |
13 | usage=$"This script extracts code from source SVN URL and merges it with an existing code in target URL.\n\ |
18 | $0 source_svn_url target_svn_url\n\ |
21 | [ "$#" - ge 1 ] || die "Wrong parameters. $usage" |
26 | svnRun=` which svn 2> /dev/null` |
29 | die "svn CLI is not found on PATH" |
32 | SCRDIR= "$( cd " $( dirname "${BASH_SOURCE[0]}" ) " && pwd )" |
35 | echo "Exporting source code from $source_uri" |
36 | svn export $source_uri source |
39 | echo "Checking out target code from $target_uri" |
40 | svn checkout $target_uri target |
43 | echo "Deleting targer files, keeping SVN metadata" |
44 | find target - type f -mindepth 1 \! -iwholename "*/.svn/*" \! -iwholename "*/.svn" - exec rm -f {} \; |
45 | find target -empty -mindepth 1 \! -iwholename "*/.svn/*" \! -iwholename "*/.svn" - exec rm -rf {} \; |
48 | echo "Copying source over target SVN metadata" |
52 | find target -depth -mindepth 1 - type d \! -iwholename "*/.svn/*" \! -iwholename "*/.svn" - exec perl $SCRDIR/rm_empty_dir.pl {} \; |
57 | added=`svn status | grep "? " | wc -l`; |
58 | echo "$added files are added" |
61 | svn status | grep "? " | awk '{print $2}' | xargs svn add |
65 | deleted=`svn status | grep "! " | wc -l`; |
66 | echo "$deleted files are deleted" |
69 | svn status | grep "! " | awk '{print $2}' | xargs svn delete |
73 | echo "Commiting changes back to target SVN" |
74 | svn -m "merging with code from $source_uri" commit |