Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find all subversion working copies on machine

Tags:

find

bash

unix

svn

How could I use find unix utility to find all working copies on the machine? For example, I can use find / -name .svn -type d command, but it outputs all redundant results (a lot of subfolders), while I need only parent directory of working copy to be shown.

There is related question, but it does not really help in my case: How can I find the root folder of a given subversion working copy

like image 250
altern Avatar asked Dec 06 '22 03:12

altern


2 Answers

maybe something like this?

#!/bin/bash
if [ -d "$1/.svn" ]; then
        echo $1
else
        for d in $1/*
        do
                if [ -d "$d" ]; then
                        ( $0 $d )
                fi;
        done
fi;

name it, for example - find_svn.sh, make it executable, and call like ./find_svn.sh /var/www (may need some tweaking to normalize directory name(s), strip trailing slash.. but works for me in this form, when called on some dir without trailing slash).

like image 140
parserr Avatar answered Dec 30 '22 17:12

parserr


Update 3 - sorted output of find to ensure .svn comes before hidden files. still might fail for checked-in hidden directories.


Perl can remove the nested paths for you:

find -s . -ipath *.svn | perl -lne's!/\.svn$!!i;$a&&/^$a/||print$a=$_'

In human, this says: for each svn path, ignoring the /.svn part, if the current path is a child of the last path I printed, don't print it.

example: for the directory structure:

$ find .
.
./1
./1/.svn
./1/1
./1/1/.svn
./2
./2/.svn
./3

this yields

./1
./2
like image 27
11 revs Avatar answered Dec 30 '22 18:12

11 revs