BoffinBrain
BoffinBrain

Reputation: 6535

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:

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

Upvotes: 7

Views: 1959

Answers (2)

Steven Green
Steven Green

Reputation: 983

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

Upvotes: 1

Peska
Peska

Reputation: 4140

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.

Upvotes: 4

Related Questions