January 18, 2011

Using a Script to Handle Long File Check Ins

Surround SCM
Large binary files can result in long check ins that tie up the client and affect your productivity. A slow connection to the server can aggravate this. Using the Command Line Interface (CLI) for those check ins can free your client up of this operation and allow you to continue with your work. You can also create a custom menu in Surround SCM to launch a batch file that checks in the file in the background. First, the custom menu requires an XML file. Following is an example of what the contents of the XML file could be:
<Surround-Plugin version="1.0" author="[email protected]" >
   <menu-item name="Binary Check In"  icon="reqmnt_doc_review_24x24.png" >
       <location type="contextfile" />
       <action path="C:batchbincheckin.bat" wait-for-completion="false"></action>
The XML file is configured to have a file context menu item labeled "Binary Check In". It's also using the "reqmnt_doc_review_24x24.png" file as an icon, which is found in the "workflow icons" directory in the TestTrack Server installation directory. When the Binary Check In menu item is selected, it calls a batch file named "bincheckin.bat", which is stored on the local path "C:batch". Also, notice that the plug-in will not wait for the batch file to complete, as that would defeat the purpose of creating the plug-in. [caption id="attachment_6886" align="aligncenter" width="221" caption="Surround SCM custom menu"]Surround SCM custom menu[/caption] Refer to the Surround SCM Custom Menus blog post for more details on the available options. The content of the batch file is as follows:
set mypath=%SSCM_LOCALFILE% :Loop IF "%mypath:~-1,1%"=="" (  GOTO End ) SET mypath=%mypath:~0,-1% GOTO :Loop
ECHO %mypath%
cd %mypath%
sscm checkin "%SSCM_FILE%" -cc"batch check in" -f
The batch file does the following:
  • Gets the local path to the file being checked in.
  • Starting from the end of the path,  removes a character at a time until it finds a back slash (""). This returns the working directory.
  • Changes to the returned working directory.
  • Runs the check in command.
To ensure the correct repository and branch is always used, the script does the check in from the working directory. The working directory is not available as an environment variable, so the first part of the batch file parses the file name out of the local file path. A standard comment is passed with the check in ("batch check in"). The force option (-f) is also used to ensure the file is always checked in. Finally, the script does not pass any connection or login parameters. This is because it is assumed that the "always check in using this username and password" is selected in the client. If not, you have two options: - Pass the -y and -z options with the comment. - Use single sign-on. The Surround SCM Command Line Interface Guide includes more information about the CLI and the command syntax.