Subversion: howto find all revisions that are not merged to trunk?

SvnMergeBranch

Svn Problem Overview


Branching sources for release cycle is one of common source management scenarios. Merging as soon as possible is a good practice. Thus we have a human factor: branch is closed, but someone forgot to merge something back to trunk.

Q: Is there a "one click" way to get all revision numbers that were not merged from branch X to trunk?

(Note: I do not need these revision numbers to find what to merge, I need them to create automated validation, that would remind people to make sure they did not forget to merge something to trunk. Merging itself is not an issue.)

It seems like svn mergeinfo command fails to help here. Passing branch and trunk roots will fail if merge was performed not on root level (and it is a common scenario).

Scripts, tools any kind of svn hooks as a solution are welcome.

P.S.

Latest version of SVN. No need to argue how common or good this scenario is ;)

Svn Solutions


Solution 1 - Svn

You can do this super easily if you're using a relatively newish version of Subversion (1.5 or higher, I think) with the mergeinfo sub-command.

svn mergeinfo --show-revs eligible svn://repo/branches/your-branch-name svn://repo/trunk

This will show you all the revisions that are eligible to be merged to the trunk from the branch "your-branch-name".

Source: http://svnbook.red-bean.com/en/1.5/svn.ref.svn.c.mergeinfo.html

Solution 2 - Svn

Short answer: I don't think so.

Long answer: I ended up writing a python script to answer this question. Whenever developers merge a changeset they're required to put "merged rXXX" in the log message. (This from before svn:mergeinfo existed) The script parses all live svn branches + trunk and recursively scans all "merged" links, outputting a per-developer list of changes they haven't merged.

[update] The answer from @tmont is better now that everyone has a svn version that supports svn mergeinfo --show-revs eligible and svn merge --record-only for those times when you want to record the logical fix only.

Solution 3 - Svn

I realize your case is probably too late for this, but what I do for this sort of thing is to establish a convention for the merge commits so they're identifiable later. For example "Merging [1234]: ...(full commit log of 1234)...". Then I can parse it out of svn log with a script later.

To make sure your whole team does it, make the merge convention into a script and put it in your project. (e.g., ./scripts/merge 1234). People will generally even appreciate this, doubly so if the script makes merges easier than the raw svn command would be by doing things like figuring out the source url automatically

Good luck.

Solution 4 - Svn

I wouldn't worry about the specific change numbers that need to get merged, but rather just look at the diffs:

First, bring the side branch up to date with trunk (or see what would be merged):

cd branch-dir
svn merge --reintegrate http://svnrepo/path-to-trunk .
svn ci -m'making this branch current'

cd ../trunk-dir
svn merge --dry-run http://svnrepo/path-to-trunk http://svnrepo/path-to-branch .
svn ci -m'merging in all unmerged changes from <branch>'

Remember, svn merge commands look just like svn diff commands - you create a diff/patch, then apply that to a particular location. That merge command above is simply saying "take all the differences between trunk and the branch, and apply them to a working copy of trunk". So you could just as easily change that second merge command into a diff for your mail notification.

Don't forget to check the diffs before committing in each case, to be sure that nothing bad has happened. You may also have to resolve some conflicts.

Solution 5 - Svn

I'm sorry I don't have my SVN server up at home to test this right now, but could the command:

svn log --verbose

Which you could parse? I'm not sure the output after you merge back to main, but you might be able to parse through (using a script, which I don't have as I'm the only one using my SVN server) the log and read all the files that have been checked in, and then look for a keyword indicating that the file has been merged to main?

I'll try to check it out sometime tonight when I get home if I have some time.

Solution 6 - Svn

For that reason CVS created a tag to mark a root of branch :) For SVN that should look like:

+ trunk / project1
+ tags / project1-b1-root
+ branches / project1-b1

Notes:

  1. Tag project1-b1-root and branch project1-b1 are created at the same time from trunk.
  2. Nobody should commit to project1-b1-root (you can restrict this operation for tags/ path).
  3. When everybody claimed, that he has put everything to the trunk, you make a diff between project1-b1-root and project1-b1 and try to apply it to trunk: the changes, which are already applied, will be silently skipped, for the rest you will see the difference or collisions.

Solution 7 - Svn

Will svn merge --dry-run give you the details you need?

Solution 8 - Svn

Due to the lack of a silver bullet, the disciplined way is to keep a note of what has been merged and from where.

Solution 9 - Svn

Based on Ether's reply above, from the branch you want to check for unmerged revisions

svn merge --dry-run http://svnrepo/path-to-merge-source .  \
| grep Merging                                             \
| sed 's/--- Merging//'                                    \
| sed 's/into.*//'                                         \
| sort -u                                                  \
| sed 's/ through r/:/'                                    \
| sed -e :a -e N -e 's/\n//' -e ta                         \
| sed 's/ r/ -r/g'                                         \
| sed 's|^|svn log http://svnrepo/path-to-merge-source |'

Solution 10 - Svn

I'm enjoying your thread after 3 years of it being created. And I believe there is still no solution for your task in the form you put it :)

What I found though in the $ svn help merge is the advice not to do sub tree merges:

> If you want to merge only a subtree, then the subtree path must be > included in both SOURCE and TARGET_WCPATH; this is discouraged, to > avoid subtree mergeinfo

So I guess the solution is to break your "common scenario" of doing subtree merges.

It would be mandatory to establish some control for merge operation, as otherwise anybody having Read access to one branch and Write access to another can do the merge from first to second. So the actual question is - how to control subtree merges ))

Solution 11 - Svn

I have written Java Web Application using Wicket and SVNKit for finding not merged revisions between branches, it could be customized to do whatever you want... link

screeno

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDandikasView Question on Stackoverflow
Solution 1 - SvntmontView Answer on Stackoverflow
Solution 2 - SvnNathan KiddView Answer on Stackoverflow
Solution 3 - SvnMat SchafferView Answer on Stackoverflow
Solution 4 - SvnEtherView Answer on Stackoverflow
Solution 5 - Svnonaclov2000View Answer on Stackoverflow
Solution 6 - Svndma_kView Answer on Stackoverflow
Solution 7 - SvnAdam LissView Answer on Stackoverflow
Solution 8 - Svnamit kumarView Answer on Stackoverflow
Solution 9 - SvnMalcolmView Answer on Stackoverflow
Solution 10 - SvnIvanView Answer on Stackoverflow
Solution 11 - SvnMeoView Answer on Stackoverflow