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

23,627

Solution 1

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 2

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 3

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

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 5

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.

Share:
23,627
Dandikas
Author by

Dandikas

C#, Agile

Updated on July 09, 2022

Comments

  • Dandikas
    Dandikas almost 2 years

    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 ;)

    • Dandikas
      Dandikas about 14 years
      I am amazed that the question yet has no answer! It sure was a hard thing to do before mergeinfo was introduced, but now I was expecting an answer like "stupid, you should learn how to google, here is the link". Strange and yet disappointing.
  • Dandikas
    Dandikas about 14 years
    @Ether that's a good short explanation on merge ;) I do know how to merge(i.e. that was not the question). I am interested in source maintaining, and want to get an automated answer on question "what was not merged". The answer would than be mailed to people who forgot to merge.
  • Dandikas
    Dandikas about 14 years
    @dma_k 3 step requires human interaction. I really need something exactly like svn mergeinfo that returns a simple list of revisions merged (or not merged). In your scenario after getting merge results further manual investigation is needed to find out what revisions were not merged and who is the author.
  • Dandikas
    Dandikas about 14 years
    @tmont from question: "It seams 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)." --show-revs eligible only changes list from "what was merged" to "yet to merge" but mentioned sub folder commit failure is still there.
  • Dandikas
    Dandikas about 14 years
    nope :( dry run will tell if running merge is going to produce conflicts. Again, you can than try to find out revisions that were not merged, but it's more a game not a "one click" action that could be scheduled for automated run on branch closure.
  • Ether
    Ether about 14 years
    @Dandikas: I've amended my answer to be more clear what I meant.
  • Dandikas
    Dandikas about 14 years
    @Nathan Kidd this is exactly what I am looking for! Only difference is that I expect it to work without special comment, as now we have svn:mergeinfo property in place.
  • Dandikas
    Dandikas about 14 years
    True as long as there are < 10 developers working on the same project. With a big teem you either change coding work-flow or do the check manually(sux).
  • Dandikas
    Dandikas about 14 years
    This sounds like what is needed, except that I do not want to make a convention on comments since we have mergeinfo property starting from SVN v1.5
  • Nathan Kidd
    Nathan Kidd about 14 years
    @Dandikas If I were to write it again I'm not sure I'd use svn:mergeinfo anyway. The reason is our concern is not really that a particular diff gets merged, but that the logical fix for the issue is applied. Sometimes if a branch diverges enough we'll fix the issue and mark it 'merged' but in fact we didn't apply any of the original diff; a separate approach was used to fix the same issue. The manual log message approach lets you do this, svn:mergeinfo doesn't so much.
  • Mat Schaffer
    Mat Schaffer about 14 years
    I hear you. I wish that worked too, but I have yet to have the 1.5 merge handling do anything other than complicate the situation.
  • Dandikas
    Dandikas about 14 years
    got your point. Our work-flow is slightly different in the way that merges are performed as soon as possible. I.e. if developer commits fix to a branch (be it one commit or several, that accomplishes the fix) he than immediately merges them to trunk. This approach has many strengths and one serious weakness - human factor. Any fix in a branch is potentially performed under more pressure with less available time. Yet we still must assure, that people (devs are people right) know when they might have forgotten to merge something.
  • Pavel Radzivilovsky
    Pavel Radzivilovsky over 13 years
    Nooo! Due to the lack of silver bullet, one must develop it. Best procedure is Working Code.
  • amit kumar
    amit kumar over 13 years
    @Pavel If there are many other interesting things one wants to develop, for this issue one may like to switch to git instead.
  • Ari Maniatis
    Ari Maniatis over 12 years
    There is a solution to the merginfo problem. That is "svn merge --record-only" to record those merges which were done at a different part of the tree, or where there was no actual merge but rather an application of the logical fix. Then you can use "--show-revs eligible" to get a list of things still waiting to be merged.
  • Nathan Kidd
    Nathan Kidd about 11 years
    If you find yourself using a grep and sed like in your 2nd and 3rd lines, try this simple optimization: sed -n 's/--- Merging//p'
  • bebbo
    bebbo about 11 years
    "and it is a common scenario" -> it's a common error to merge / branch at different levels! ALWAYS merge at that level where your branch started. ALWAYS.
  • Adam
    Adam over 9 years
    There is a -R (recursive) option to the svn mergeinfo command (at least in the current version) which should make it include merges performed lower down. We try to always merge at the top level (commits can be performed at lower levels, or including only files in a certain directory, but merges always at the top) so I haven't really tested it.
  • Ed Randall
    Ed Randall over 8 years
    I was confused by terminology for a moment, "level" here means "directory level", right?