Saturday, 12 November 2011

updateCVSRoot.bat

Ever been in a situation where you needed users to update the CVSROOT of their locally checked out source?
It's not always as straight forward as checking out the code again so here's a batch script to recursively update the CVS\Root file with the new CVSROOT.
Synopsis: updateCVSRoot.bat <WORKSPACEDIR> <CVSROOT>

  1. @echo off
  2. REM This script is used to update CVS Root in checked out directory
  3. REM SYNOPSIS: updateCVSRoot.bat <WORKSPACEDIR> <CVSROOT>
  4.  
  5. REM Check arguments
  6. if "%2" == "" goto MISSINGARGUMENT
  7.  
  8. REM Check if workspace directory exist
  9. IF NOT EXIST %1 GOTO NOWORKSPACEDIR
  10.  
  11.  
  12. REM Setup variables
  13. SET W_DRIVE=%~d1
  14. SET W_PATH=%~dp1
  15.  
  16. REM Enter drive and directory for the root of CVS checked out directory
  17. %W_DRIVE%
  18. cd %W_PATH%
  19.  
  20. REM Find all Root files and replace with CVSROOT
  21. for /f "tokens=*" %%a in ('dir Root /b /s') do (
  22.   echo %2> "%%a"
  23. )
  24.  
  25.  
  26. echo Done!
  27. exit /b 0
  28.  
  29. :MISSINGARGUMENT
  30. printf "Usage:  %~n0 <WORKSPACEDIR> <CVSROOT>\n"
  31. printf "  WORKSPACEDIR               Root directory to search for filenames called Root\n"
  32. printf "  CVSROOT                            Fully qualified CVSROOT\n"
  33. printf "\n"
  34. printf "Example: %~n0 c:\\\\cvsdir :sserver:username@cvs.localdomain:/my/cvsroot\n"
  35. printf "\n"
  36. exit /b 1
  37.  
  38. :NOWORKSPACEDIR
  39. echo ERROR: %1 doesn't exist
  40. echo.
  41. exit /b 1

No comments:

Post a Comment