Reputation: 9579
I use JIRA as bug-tracking system. If there is a newly revealed bug then it is commited to the trunk first. Commits are done under a specific ticket. For example, ticket #37 is fixed by commits: 65, 68 and 74.
Sometimes I would need to backport a ticket to a branch. So I have to download a repository for a branch, i.e. #3 and apply following command
svn merge -c65,68,74 http://.../svn/trunk
then to commit and so on for every ticket.
What I would like to do is specify a list of tickets from JIRA and branch id. So they would be merged automatically from trunk to a specific branch.
What are the options to accomplish that?
Upvotes: 1
Views: 907
Reputation: 4502
If you're referencing your Jira tickets in a consistent way from the commit messages, using the Jira ABC-123 ticket number format you can get a list of revisions by searching the SVN log.
svn log --search=FOO-57 http://.../svn/trunk
This will give you the log messages and revision numbers for each relevant commit. Assuming a unix-like environment, you can use some pipes and shell manipulation to convert the svn log output to a list of revision numbers like so:
svn log --search=FOO-57 http://.../svn/trunk | grep ^r | cut '-d|' -f1 | sed s,r,,
A little bit more shell manipulation can give you that same revision list in a comma-separated format:
REVISIONS=($(svn log --search=FOO-57 http://.../svn/trunk | grep ^r | cut '-d|' -f1 | sed s,r,,))
echo "${REVISIONS[*]}" | sed 's/ /,/g'
So now you can merge just by using the output of that second command as your -c
argument to svn merge
REVISIONS=($(svn log --search=FOO-57 http://.../svn/trunk | grep ^r | cut '-d|' -f1 | sed s,r,,))
svn merge -c$(echo "${REVISIONS[*]}" | sed 's/ /,/g') http://.../svn/trunk
You can convert the above into a re-usable shell script by replacing the search term and the URL with "$1"
and "$2"
. Or, if you want to apply this to multiple Jira tickets at once, you can wrap the entire thing in a loop like so:
#!/bin/bash
TRUNK_URL="http://.../svn/trunk"
REVISIONS=($((for search_term in "$@"; do
svn log --search="$search_term" "$TRUNK_URL" | grep ^r | cut '-d|' -f1 | sed s,r,,;
done) | sort -u))
svn merge -c$(echo "${REVISIONS[*]}" | sed 's/ /,/g') "$TRUNK_URL"
If you'd prefer to avoid shell scripting to get the revision list, you can achieve a similar results using any language with libsvn
bindings. Here's an example using Python and pysvn:
#!/usr/bin/env python
import pysvn
logs = pysvn.Client().log('http://.../svn/trunk')
to_merge = { x['revision'].number for x in logs if 'FOO-57' in x['message'] }
Upvotes: 3