Monday, December 9, 2013

Pulling and updating of bunch of Mercurial projects in the same folder

A Useful bash script allows pulling and updating of bunch of Mercurial (Hg) projects placed in the same folder. These project repositories should desire the same credentials for authentication.

 #!/bin/bash  
 set -e  
 echo  
 echo "The Script allows to make bunch pulling and updating of all Hg projects found in the current folder"  
 echo "Author: Igor Maznitsa (http://www.igormaznitsa.com)"  
 echo  
 echo -n "Enter name, followed by [ENTER]: "  
 read hgUserName  
 echo -n "Enter password, followed by [ENTER]:"  
 read -s hgUserPassword  
 echo  
 folderCounter=0  
 for dir in $(ls -d */)  
      do  
           echo ----------------------------------  
           echo "Detected directory $dir"  
           if [ -d "./$dir/.hg" ]; then  
             echo "Making pull and update"  
             defaultPath=$(grep "default" "./$dir.hg/hgrc")  
             extractedPath=${defaultPath#*default*=}  
             extractedPath="${extractedPath#"${extractedPath%%[![:space:]]*}"}"  
             extractedPath="${extractedPath%"${extractedPath##*[![:space:]]}"}"  
             echo "Path $extractedPath"  
             hg --config auth.rc.prefix="$extractedPath" --config auth.rc.username="$hgUserName" --config auth.rc.password="$hgUserPassword" -R "./$dir" pull -u  
             echo  
             folderCounter=$[$folderCounter+1]  
           else  
             echo "WARNING: Directory $dir is not Hg repository"  
             echo  
           fi  
      done  
 echo "The Script work has been completed"  
 echo "Updated $folderCounter folder(s)"  
 exit 0  

No comments:

Post a Comment