When it rains it pours. This is the most action the blog has seen in a while. Today’s issue: migrating a sub-directory from one subversion repository to another without svnadmin access to either repo.
Problem
My client has a subversion repository used to store all the company applications. I have a sub-directory in this repo storing the code for my web applications. It includes CakePHP based web applications that have many folders with the svn:ignore property set to avoid tmp and other folders that have data that is not required in the repo. I do not have access to perform an svnadmin dump.
Solution
After a few minutes of searching Google and contemplating a solution, I decided to just write some Bash scripts to solve this problem. This is the procedure that I came up with:
- Copy the old working sub-directory into the new working sub-directory
- Remove all .svn from the old working sub-directory in the new working sub-directory
- Change to the old working sub-directory in order to retrieve relative paths
- Get a list of directories that have svn:ignore properties and put them into a file
- Iterate through the list of directories
- Establish a filename for storing the svn:ignore property information
- Run the svn propget svn:ignore on the old working directory and output to the filename generated in step 3
- Run the svn propset svn:ignore -F [filename] on the new working directory
- Perform basic clean-up of temp files
- Change back to directory the user was using when the script was called
- Exit
#!/bin/bash
HOME="/path/to/home"
SRC="/path/to/old/working/directory"
DST="/path/to/new/working/directory"
cp -r "${SRC}" "${DST}"
find "${DST}" -type d -name .svn -exec rm -rf {} \;
pushd "${SRC}"
for i in `find . -type d | grep -v .svn`; do svn proplist $i | grep ^Prop | sed "s/^[^']*'\([^']*\)':/\1/"; done > "${HOME}/tmp"
while read line; do
FILENAME=`echo $line | sed 's#/#_#g'`
svn propget svn:ignore "${SRC}/$line" > "${HOME}/${FILENAME}.svnignore"
svn propset svn:ignore -F "${HOME}/${FILENAME}.svnignore" "${DST}/$line"
rm "${HOME}/${FILENAME}.svnignore"
done < "${HOME}/tmp"
rm tmp
popd
exit 0
Warning
This script was run in a Cygwin environment and has not been tested in other Unix or Linux environments. It makes the the assumption that the properties that are found are ONLY svn:ignore properties. Any others could cause issues. I only had svn:ignore properties set. At first I ran the first half of the real work in this script manually to see the outcome one step at a time. I later compiled into this single script, but without fully testing it again as my repo was already set and I did not want to destroy it.