find all subversion working copies on machine
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
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).
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
The following works for me just fine. It finds also all sparse checkouts (or nested working copies).
find $PWD -type d -wholename "*/.svn" |
while read path
do
path=${path%%/.svn}
wcr=$(svn info ${path} 2>/dev/null | perl -F"/:\s/" -le '{ print $F[1] if $F[0] =~ /^Working Copy Root/; }')
[ "$path" = "$wcr" ] && {
echo -e "\n WC Root $path"; svn stat -qu $path;
}
done
if you have GNU find/sort
find /path -type f -name ".svn*" -printf "%h\n" | sort -u
精彩评论