3

Possible Duplicate:
Can I go back and edit comments on an SVN checkin?

Once in a rare while I inadvertently commit a file without commenting (we're supposed to comment on every commit no matter how trivial the change). Is there a way to add a comment after committing without reverting and recommitting?

Community
  • 1
  • 1
squidbe
  • 1,012
  • 1
  • 8
  • 13
  • 5
    Rather than being supposed to do this, you could see if the administrator can install a commit hook on the server to prevent commits without comments. – SteveMc May 17 '11 at 19:03
  • Thanks @RedFilter. @SteveMc, in a functional work environment, that'd be a great idea. ;-) – squidbe May 17 '11 at 19:12
  • 1
    manojlds (see below) makes a great suggestion. I had forgotten that you can make a local pre-commit hook. – Richard J Foster May 17 '11 at 19:17

3 Answers3

2

Apart from doing a propset on svn:log using something like below as suggested from Can I go back and edit comments on an SVN checkin?:

svn propset --revprop -r 1000 svn:log "Not blank"

you should consider creating a pre-commit hook that will prevent you from checking in without a commit message. This can be on the server or even on your local copy. Screenshot, since you are using TortoiseSVN:

enter image description here

After all, prevention is better than cure!

Sample pre-commit to prevent committing with no commit message:

for %%I in (%3) Do (
IF %%~zI==0 (
echo "No commit message given" 1>&2
exit 1
)
)

My bash knowledge is limited, but the above seems to work. You can of course have a script in Python, Ruby etc. if needed. Basically, the third parameter is a temporary file that contains the commit message. See if it is empty and exit if so.

Community
  • 1
  • 1
manojlds
  • 290,304
  • 63
  • 469
  • 417
  • Thanks @manojlds. I like this idea and am trying to find documentation on how to do it but am not finding much. I found a couple of samples: http://tortoisesvn.googlecode.com/svn/trunk/contrib/hook-scripts/client-side/PreCommit.js.tmpl http://stackoverflow.com/questions/692851/can-i-go-back-and-edit-comments-on-an-svn-checkin/692875#693032 but I'd like some kind of API or manual that shows me the possible options. Any idea how to check for empty comments or where I can look to find that info? – squidbe May 17 '11 at 20:35
  • @squidbe - have updated my answer with a sample hook – manojlds May 17 '11 at 21:34
  • Thanks @manojlds. I get an error when using that script: "The hook script returned an error." Informative, eh? ;-) Can you point me to whatever resource you used to get compose that script? I'll do the digging; I just need to know where to dig. – squidbe May 17 '11 at 23:11
1

From the FAQ, there is a mechanism available using the pre-revprop-change hook, or the svnadmin setlog command (if you have local access to the repository, which I suspect you don't), however in a team environment I would suggest that the revert & recommit is probably a better choice.

Richard J Foster
  • 4,278
  • 2
  • 32
  • 41
0

I would consider both of these as best practices:

  1. Require comments on commit (pre-commit hook needed)
  2. Allow editing of existing comments (pre-revprop-change hook needed)

I find the latter useful because it allows you to go back and revise poorly written, inaccurate, or just plain bad (e.g. "Fixed" :-) messages.

Regarding the former, it is best to install on the server--that way it applies to everyone automatically. If you require users to set it up on the client side, you run the chance of a new user forgetting to do so.

Installing a hook is as simple as placing a hook script in the hooks directory of the repository. In fact, when you create a repository it populates the hooks directory with sample hook scripts; they are in Unix/Linux shell script, though, so if your server is Windows-based you need to find (or write) other versions. As it happens, the SO question Common Types of Subversion Hooks provides Windows versions of a few hooks including both of those mentioned above.

For full details on Subversion hooks, see Implementing Repository Hooks in Chapter 5 of the Subversion Book for server side and Client Side Hook Scripts in Chapter 4 of the TortoiseSVN manual for client side.

Community
  • 1
  • 1
Michael Sorens
  • 35,361
  • 26
  • 116
  • 172