Thursday, November 1, 2007

Frustrating: Subversion / Interesting: Bash

So in the process of messing around with IDEs, I used NetBeans (most likely) to check out my project from Subversion. No problem - I edit my code, actually get my JSP page to work. Let me check it in and deploy! We're sorry - you can't check that in - Permission Denied. We're using svn+ssh protocol and the remote user is wrong - it is my local userid which is not the remote userid. Ok, how could that happen? And what to do?

Turns out the URL is stored in .svn/entries - just have to edit it. Sed to the rescue.
> find . -name entries -exec sed /host/s//user@host/ {} > {} \;
Ran fine - no change. All 'entries' files are read-only.
> find . -name entries -exec chmod u+w {} \;
Re-run sed. No change. Redirect is going somewhere else. Seem the second brace pair is not replaced with the file name. So put the sed command into a script. ~/bin/runsed.sh:
sed /host/s//user@host/ $1 > $1
Ok, let me try this on one file...
> ~/bin/runsed.sh src/main/java/.svn/entries
> ls -l src/main/java/.svn/entries
rw-r--r-- 0 entries
Zero!?? Oops. Change runsed.sh:
sed /host/s//user@host/ $1 > $1.fix
Re-run fine:
> find . -name entries -exec ~/bin/runsed.sh {} \;
Now I just have all these entries.fix files. Let's get rid of the old ones:
> find . -name entries -exec rm -f {} \;
Hmm... now if the curly braces only expand once, we're going to need a new bash script... And I recall there's a bunch of clever stuff bash will do with variables and file names... oh - here it is: "${1%\.fix}" will get rid of that...
~/bin/mvname.sh:
mv $1 ${1%\.fix}
> find . -name entries.fix -exec ~/bin/mvname.sh {} \;
Put them back to r/o:
> find . -name entries -exec chmod u-w {} \;

Done! Subversion now works again! Phew.

No comments: