Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subversion: How to get a list of all active, unmerged branches

My question is similar to Mercurial: List all unmerged branches but for SVN, not Mercurial.

I need to find a way to list all currently open branches that haven't been merged into mine (usually trunk).

As far as I'm aware, the equivalent feature in Git is git branch --no-merged and git branch --merged

For clarification, I'm not asking for a list of unmerged revisions, like many other StackOverflow questions have asked in the past.

I'll accept any solution that is able to to list all active branches that are not yet merged. If this isn't possible, then I will accept an answer that lists all active, merged branches, allowing me to work backwards.

For example, if I'm on repo/trunk, and the repo has these branches:

  • repo/branches/b1 has not been merged into trunk
  • repo/branches/b2 has been merged
  • repo/branches/b3 was deleted in a previous revision and wasn't merged
  • repo/branches/b4 was deleted after being merged

Your solution should return either b1 or b2, but must never return b3 or b4.

like image 789
BoffinBrain Avatar asked Aug 03 '17 12:08

BoffinBrain


2 Answers

First, you have to take list all branches in the HEAD revision:

svn list repo/branches/ -r HEAD

And then, you have to loop through results, and check mergeinfo. Here is a script that you can save as *.bat file:

@echo off

for /f %%b in ('svn list repo/branches -r HEAD') do call :revisions %%b

exit /b

:revisions
for /f %%r in ('svn mergeinfo --show-revs eligible repo/branches/%1 repo/trunk') do (
    echo repo/branches/%1
    exit /b
)

I'm using a :revision subroutine here, because I want to exit it when I see the first revision available to merge. That's why this program won't print duplicate branches.

like image 107
Peska Avatar answered Nov 14 '22 13:11

Peska


For those people using MacOS or Linux, here is a simple bash script based on Peska's answer. You can pass paths to the branch and trunk folders on the command line, or it will default to the default remote paths ^/branches and ^/trunk

#!/bin/bash

BRANCHDIR=${1:-^/branches}
TRUNKDIR=${2:-^/trunk}

for branch in $(svn list "$BRANCHDIR" -r HEAD)
do
    for revision in $(svn mergeinfo --show-revs eligible "$BRANCHDIR/$branch" "$TRUNKDIR")
    do
        echo "$BRANCHDIR/$branch"
        break
    done
done
like image 40
Steven Green Avatar answered Nov 14 '22 12:11

Steven Green