automate the svn merge process with shell script

Posted on 2009-12-25
Last Modified: 2013-12-26
I want to automate the process of merging tag to trunk in svn using shell script. I'm finding difficulty when getting the revision number of tags and put it in svn merge automatically.

these are the following steps to merge the tag to trunk

1. checkout tag
2. checkout trunk
3. cd to tag
4. run the command svn log --stop-on-copy (this will give the revisions. Please see the code snippet)
5. get the revision number from the above command (here the revision is 2780 from code snippet)
6. svn merge --dry-run -r2780:HEAD http://url/path  (testing the merge. if test merge fails ask the user whether the real merge can be done or not)
7. If user says yes, run svn merge  -r2780:HEAD http://url/path
8. print merge successful
svn log --stop-on-copy
r2811 | harry | 2009-12-24 11:47:57 -0800 (Thu, 24 Dec 2009) | 1 line

removed *.db
r2790 | sally | 2009-12-23 15:35:26 -0800 (Wed, 23 Dec 2009) | 1 line

updated index.jsp
r2787 | sally | 2009-12-23 15:33:09 -0800 (Wed, 23 Dec 2009) | 1 line

r2780 | sally | 2009-12-23 15:20:04 -0800 (Wed, 23 Dec 2009) | 1 line


Open in new window

Question by:CharanR
    1 Comment
    LVL 14

    Accepted Solution

    So you want the last (bottom) revision?

    REV=`svn log --stop-on-copy | grep "^r" | tail -1 | awk '{print $1;}'`

    > svn merge --dry-run -r2780:HEAD http://url/path  (testing the merge. if test merge fails ask the user

    Then use:
    svn merge --dry-run -r$REV:HEAD http://url/path

    If test merge fails does svn return non-zero exit code? if so:

    if [ $? != 0 ]; then
        echo "Merge failed..."
        # Handle merge fail here...


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
    Recently, an awarded photographer, Selina De Maeyer (, completed a photo shoot of a beautiful event ( in An…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now