As I’ve started to develop a few bigger browser-based projects recently, I thought about setting up a version control system for keeping track of changes to source files, images and so on.
Since CVS ain’t fun when it comes down to web-based projects and GIT feels a bit too overdosed for my purposes, I made the decision to use SubVersion, which affords me to move files around without loosing their history and is still syntactically quite similiar to CVS.
Because of my job, I’m also used to a bug tracking system, namely Mantis, which can be feeded by a CVS post-commit hook with some extra data to each single bug-ID, and of course I wanted the same for my bug tracker. Like in CVS, there’s also a (per-repository) post-commit hook in SubVersion and so I followed the pervasive tutorials on the net, for getting this nifty feature running.
Sadly none of those tutorials worked for me in the way that I expected or that has been promised. Actually the hook was kinda self-explaining; stating the following commit should push a comment with the commit details to a certain id.
1
| $ svn commit -m"working on issue [#mantisid]" file |
The corresponding post-commit script looked like that:
1
2
3
4
5
6
7
8
9
10
11
12
13
| #!/bin/bash
REPOS="$1"
REV="$2"
SVNAUTH=$(svnlook author -r $REV $REPOS)
SVNDATE=$(svnlook date -r $REV $REPOS)
SVNLOG=$(svnlook log -r $REV $REPOS)
SVNCHANGE=$(svnlook changed -r $REV $REPOS)
n=$'\n'
LOGMSG="Changeset [${REV}] for repo [${REPOS}] by ${SVNAUTH}${n}${SVNDATE}${n}${n}${SVNLOG}${n}${n}Changed Files:${n}${SVNCHANGE}"
# echo $LOGMSG >> /tmp/svnchange.log
/usr/bin/php5 -q /path/to/mantis/scripts/checkin.php <<< "$LOGMSG" |
For some odd reason svnlook hasn’t been executed and the shell variables has been empty (and no, it wasn’t the fact that you’ve got a minimal environment in the post-commit script, neither setting up the PATH nor absolute paths changed the behaviour). As this is not strange enough, the following worked:
1
2
3
4
5
6
| #!/bin/bash
REPOS="$1"
REV="$2"
SVNVERSION=$(svnlook --version);
echo $SVNVERSION >> /tmp/svnversion.test |
After some confusing and frustrating days, I found the following solution (sorry I know that is more than just mean, actually it’s a bastard):
1
2
3
4
5
6
7
8
9
10
11
12
13
| #!/bin/bash
REPOS="$1"
REV="$2"
SVNAUTH=`exec svnlook author -r $REV $REPOS`
SVNDATE=`exec svnlook date -r $REV $REPOS`
SVNLOG=`exec svnlook log -r $REV $REPOS`
SVNCHANGE=`exec svnlook changed -r $REV $REPOS`
n=$'\n'
LOGMSG="Changeset [${REV}] for repo [${REPOS}] by ${SVNAUTH}${n}${SVNDATE}${n}${n}${SVNLOG}${n}${n}Changed Files:${n}${SVNCHANGE}"
# echo $LOGMSG >> /tmp/svnchange.log
/usr/bin/php5 -q /path/to/mantis/scripts/checkin.php <<< "$LOGMSG" |
As mentioned this worked for me, but out of pure curiousity: why the fuck I needed to use a back-ticked-exec for svnlook, instead of a $()?