Updating an svn working copy from a non-versioned source tree — quick & dirty bash surgery
When you find out, for whatever unpleasant reason, that you need numerous files in your working copy overwritten from a non-versioned source, it’s a bit of a problem. You can’t go overwriting your whole working copy tree, because you’ll lose all those .svn files, and that wouldn’t be much of a working copy anymore, would it?
What you somehow need to do is individually overwrite files that have changed, which I do here:
diff -rq unversioned workingcopy | grep -v '\.svn\|_notes' | grep 'differ' | while read a uvfile b svnfile c; do cp $uvfile ${svnfile%/*}/; done
Explanation: a recursive diff of the unversioned directory against the working directory, with brief output, ignoring .svn and Dreamweaver _notes files (not from me, I promise), filtered by only ‘differ’ as opposed to ‘Only in’ differences (cheating here, since I was confident none of my filenames contained the string ‘differ’), And doing a really cheap ‘while’ to parse out the filenames to copy over. Notice I’m cheating with the while loop as well, because this won’t work with filenames containing spaces. Do yourself a favor, and don’t use filenames with spaces if you want to be able to do stuff like this in a hurry. ${svnfile%/*}/ takes the filename off the end of the svnfile variable (actually, it takes off the final slash as well, which I re-added). That step may not have been necessary… but it stays ’cause that’s what I actually did.
Thankfully I had few enough ‘Only in’ differences to handle it manually, but I think the above command could be tweaked easily enough to perform those ‘merges’ well.





August 22nd, 2008 at 5:35 pm
This probably would have been better done with rsync, using –exclude=”.svn/’ or similar.