# Sync from multiple svn/mercurial/git/repo



## kdemidofff (Jul 3, 2010)

Initially wrote this for learning bash so feedback welcome

It will sync all intermediate sub-directories in current directory with appropriate
command based on presence of .svn .git .hg .repo directories



```
#!/usr/local/bin/bash
#include <TEHDrunkWare.h>
#Feel free to use, get profit and/or post beer or coca-cola or at least unused floppies to teh imba author. can take epix or crafted items from wow also (eu r
ealms plz)

#Copyright(c) <2010>, <kdemidofff>
#All teh me has rights reserved.

#Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or
 other materials provided with the distribution.
# * Neither the name of teh <me> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prio
r written permission.

# TEH HAS SOFTWARE IS PROVIDED BY THE anyone "AS has IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCH
ANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INC
IDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFI
TS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE
) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

me=`basename $0`;

fancystuff=0
logging=0

reposfound=0
badrepos=0

if [ $logging == 0 ] ; then
    tehhaslogfile="/dev/null"
    tehhasbrokenrepos="/dev/null"
else
    tehhaslogfile="$me.log"
    `rm -f $tehhaslogfile`

    tehhasbrokenrepos="skipped-repos.lst"
    `rm -f $tehhasbrokenrepos`
fi

(
for tehdir in `find . -maxdepth 1 -type d`
do
    echo -ne "has pending $tehdir ..! Getting teh info.. "
    (( reposfound++ ))

    if [ -d $tehdir/\.git ]; then
            echo ": is has a teh GIT REPO"
            (cd $tehdir && git pull)
    elif [ -d $tehdir/\.svn ]; then
            echo ": is has a teh SVN REPO"
            (cd $tehdir && svn up)

    elif [ -d $tehdir/\.hg ]; then
            echo ": is has a teh Mercurial REPO"
            (cd $tehdir && hg pull --update)

    elif [ -d $tehdir/\.repo ]; then
            echo ": has can teh REPO REPO prooly xD"
            (cd $tehdir && repo sync)

    elif [ "$tehdir" == "." ] ; then
            echo ": has own directory! skipped.."
            (( reposfound-- ))
            continue;
    else
        (( reposfound-- ))
        (( badrepos++ ))
        echo -e "\n"
        echo "giving up on teh $tehdir.."
        echo "$tehdir" >>$tehhasbrokenrepos
    fi
done

echo "All found (=$reposfound) repos teh has updated. Not recognized: ($badrepos)"
) | tee $tehhaslogfile

echo "Has teh nice day!"
sleep 2;
```

View attachment tehhasrepo.sh.gz


----------



## fairy (Jul 5, 2010)

A directory can be under multiple VCS. It's not always desired to update all of them, conflicts may arise. For example, I have firefox-devel port that keeps track of cvs-ports, gecko-svn and my own git history.


----------



## kdemidofff (Jul 5, 2010)

fairy said:
			
		

> A directory can be under multiple VCS. It's not always desired to update all of them, conflicts may arise. For example, I have firefox-devel port that keeps track of cvs-ports, gecko-svn and my own git history.




edit:
actually in ur case it depends.. is there unified scheme for sync from multiple sources?
source can checked out from one master repo? not like p2p 
but after what order of updates? its user desition ?

this is just skeleton.. for me it works.. XD its implies that all directories under one repo management system
i can change it if u provide more specific feedback

or feel free to change its bsd license


----------

