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 trunkrepo/branches/b2
has been mergedrepo/branches/b3
was deleted in a previous revision and wasn't mergedrepo/branches/b4
was deleted after being mergedYour solution should return either b1 or b2, but must never return b3 or b4.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With