Pentium10
Pentium10

Reputation: 208042

List all SVN repository URLs from a folder in recursive mode

We are looking for a script that will traverse in recursive mode all subfolders and list all SVN repository URLs and the path where it was found.

It will be used on /home folder of a user.

Upvotes: 6

Views: 3829

Answers (3)

Didier Trosset
Didier Trosset

Reputation: 37477

Recursively find directories, and for each of them try to get the SVN info. If it is successfull, then don't descend into the directory and print the directory name.

find -type d -exec bash -c "svn info {} > /dev/null 2> /dev/null" \; -prune -print

This will list the directories.

If you want the repository info, you can add it in the middle of the find exec command.

find -type d -exec bash -c "svn info {} 2> /dev/null | grep URL" \; -prune -print

Edit:

I found much better results by only testing for the presence of an .svn subdirectory. Then, svn info is called once at the end and grepped for Path and URL. (Plus using -0 to prevent from spaces in filenames.)

find -type d -exec test -d "{}/.svn" \; -prune -print0 | xargs -0 svn info | grep -e '\(Path\|URL\)'

Upvotes: 4

choroba
choroba

Reputation: 242343

user_home=... # fill in the user's home dir
old_dir=/../
find $user_home -name .svn | rev | cut -f2- -d/ | rev | while read line ; do
    echo -n "$line"$'\t'
    wc -c <<<"$line"
done | sort -t$'\t' -k1,1 -k2,2n | while read dir size ; do
    if [[ $dir != $old_dir* ]] ; then
        old_dir=$dir
        svn info $dir | grep URL
        echo PATH: $dir
        echo
    fi
done

Just hope users do not store SVN under directories with spaces in names.

Upvotes: 0

Vala
Vala

Reputation: 5674

Depending on what kind of limitations you have there could be different ways. The easiest way would be to do svn ls -R | grep -v "\." to grab all the sub-folders from the repository location you're at and feed that in to a for loop that adds the URI to the root of the ls to the front of each line. This will however not be adequate if you have files that do not contain a "." as they will be detected as folders. Unfortunately svn ls doesn't allow you to filter by file/folder, so if you need to deal with filenames without extensions then you'd have to do something different such as checking out the source and using find to get the folder names.

Upvotes: 0

Related Questions