Skip to content

Instantly share code, notes, and snippets.

@siddhadev
Last active November 9, 2021 17:20
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save siddhadev/5814802 to your computer and use it in GitHub Desktop.
Save siddhadev/5814802 to your computer and use it in GitHub Desktop.
Bash script for fixing subversion's "Working copy text base is corrupt" error
#!/bin/bash
set -e
usage(){
echo "Error $errcode $errorcode at line ${BASH_LINENO[0]} while executing: $BASH_COMMAND"
exit $errorcode
}
trap usage ERR
file="$1"
[ -f "$file" ] # must be a file
url=$(svn info "$file" | grep '^URL' | awk '{print $2}')
root=$(svn info "$file" | grep '^Working Copy Root' | awk -F':' '{print $2}')
rev=$(svn info "$file" | grep '^Revision' | awk -F':' '{print $2}')
name="$(basename $url)"
dir="$(dirname $url)"
tmp="$(mktemp -d .tmp.XXX)"
echo "Doing fresh checkout for: $name"
echo " URL: $dir"
echo " dest: $tmp"
echo " rev: $rev"
svn co -N -r $rev "$dir" "$tmp" >> /dev/null
hash=$(cd "$tmp" && sha1sum "$name" | awk '{print $1}')
corrupt=$(find ${root}/.svn/pristine -name $hash.svn-base)
svnbase=$(find ${tmp}/.svn/pristine -name $hash.svn-base)
corrupt_sum=$(md5sum "$corrupt" | awk '{print $1}')
svnbase_sum=$(md5sum "$svnbase" | awk '{print $1}')
if [[ "$corrupt_sum" != "$svnbase_sum" ]]
then
echo "Fixing .svn-base for $name"
echo " from: $corrupt_sum (corrupted)"
echo " to: $svnbase_sum (expected)"
echo " src: $svnbase"
echo " dest: $corrupt"
cp -f $svnbase $corrupt
else
echo "No corruption detected"
fi
rm -rf "$tmp"
@str
Copy link

str commented Feb 6, 2014

I get the following error:
Error at line 13 while executing: [ -f "$file" ]

@neilvince
Copy link

You get this if you don't provide a file name.

I get the following error:
Error at line 13 while executing: [ -f "$file" ]

@cschaba
Copy link

cschaba commented Jul 27, 2015

thank you, this helped me a lot!

@pramoddevendra
Copy link

Thanks a lot !!! you saved my day.. cheers !!!

@ZenGuLhe
Copy link

That's a hack ... But that's not a dirty hack !
Very nice indeed ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment