During a recent project I needed to modify user interface (UI) files in a Subversion repository and then deploy them to a Tomcat server. At first I recursively copied all of the files using a batch script, but because of the size of the repository this could take anywhere from 10 to 15 seconds. That is long enough to interrupt cognitive flow and consequently decrease programmer productivity. Because of this I decided to try copying only the locally-modified files to the Tomcat deployment folder. I did this using a PowerShell script that uses the ‘svn status’ command to obtain a list of all repository files with local changes. Due to the fact that I am only modifying a small number of UI files at a time, this script copies all changed files to the deployment folder in less than one second, a significant improvement over the “brute force” approach.
The PowerShell script that I created is provided below. In order to use it you will need to change the values assigned to $REPOSITORY_LOCATION and $DEPLOYMENT_LOCATION. You will also need to enable PowerShell script execution on your machine. You can enable this by opening PowerShell and typing “set-executionpolicy remotesigned”.
I hope that you find this script useful. Please feel free to contact me if you have any questions.
# Selective Deployment PowerShell Script # # This script copies locally-modified files in a Subversion repository to a # specified deployment folder. Note that this script assumes that the # deployment folder and all subdirectories exist.
# Set the repository location and the location to which to deploy the modified repository files.
$REPOSITORY_LOCATION=”C:pathtorepositorydirectory”
$DEPLOYMENT_LOCATION=”C:pathtodeploymentdirectory”
# Use ‘svn status’ to list all locally modified files in the specified repository.
# Copy each file to the correct folder in the deployment directory.
(svn status $REPOSITORY_LOCATION -q) | ForEach {
# Extract the filename from the line.
$FILENAME=[regex]::split($_, “Ms”)[1].Trim()
Write-Host $FILENAME
# Extract the location within the repository from the string.
$REPOSITORY_LOCATION_SUBSTRING=$FILENAME.substring($REPOSITORY_LOCATION.get_Length())
# Append this location to the end of the deployment location path. Remove
# the filename to get the directory to which we will copy the original file.
$COPY_TO_FILE=(Join-Path $DEPLOYMENT_LOCATION $REPOSITORY_LOCATION_SUBSTRING)
$COPY_TO_DIRECTORY=$COPY_TO_FILE.substring(0,$COPY_TO_FILE.LastIndexOf(“”))
# Copy the original file to the correct subdirectory in the deployment folder.
Copy-Item $FILENAME $COPY_TO_DIRECTORY
}