Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a SVN Commit Message Template and Hook to Verify

I'm using Visual SVN Server and Tortoise SVN (client) for source control. I would like all developers to standardize on a consistent format for checkin notes.

For Example I want their Commit Message to default to...

Synopsis:

Developer Name: (pre-populated)

Reviewed By:

[Bug Id]:

[Change Bug State]:

Known Issues:

Affected Files: (pre-populated)

In the future I'd like [Bug Id] and [Bug State] to supply the information to trigger an automated update to the Bug Tracking system. Also Developer Name and Affected Files should be prepopulated with the svn user and files that the user is commiting.

Please send any links or samples you may have.

like image 492
Justin Avatar asked Jun 11 '09 19:06

Justin


People also ask

What is post commit hook in svn?

The post-commit hook is run after the transaction is committed and a new revision is created. Most people use this hook to send out descriptive emails about the commit or to notify some other tool (such as an issue tracker) that a commit has happened. Some configurations also use this hook to trigger backup processes.

Can we change the commit message in svn?

By default, the log message property (svn:log) cannot be edited once it is committed. That is because changes to revision properties (of which svn:log is one) cause the property's previous value to be permanently discarded, and Subversion tries to prevent you from doing this accidentally.

What does svn commit mean?

svn commit will send any lock tokens that it finds and will release locks on all PATH s committed (recursively) unless --no-unlock is passed. Tip. If you begin a commit and Subversion launches your editor to compose the commit message, you can still abort without committing your changes.


4 Answers

Taken from How to create a Tortoise SVN Checkin Template (modified to fit to more current versions):

The log template can be customized as per the project requirements and can be used to implement strict log format.

Adding this to your svn repository is easy :

  1. Select a SVN folder to which you want to apply this go to Subversion properties( right click TortoiseSVN -> Properties)

  2. Select New -> Advanced, then tsvn:logtemplate from the drop down list named Property name.

  3. Add the above templates(or your own) to text area below combo box.

  4. If you want to apply the property to every file and folder in the hierarchy below the current folder, check the Recursive checkbox.

  5. Click on OK to add that property to the list.

  6. Check-in all the folders and files so that everyone else in your team can use the same template.

like image 139
Justin Avatar answered Nov 09 '22 19:11

Justin


A way to do this with the command line is to change the SVN_EDITOR environment variable, described here:

http://svn.haxx.se/dev/archive-2006-02/0487.shtml

SVN_EDITOR="rm svn-commit.tmp && cp $REPOS/hooks/log.tmpl svn-commit.tmp && vi svn-commit.tmp"
like image 38
purecharger Avatar answered Nov 09 '22 19:11

purecharger


Or, for further SVN_EDITOR comfort (e.g. properly linking to the TFS work item in the case of having to use SvnBridge), one could store the following script as ~/bin/svn_editor :

#!/bin/sh

template_file="${@}"
template_file_new="${template_file}.new"

current_work_item_number_file="${HOME}/tfs_work_item_number_current.txt"
[ -f "${current_work_item_number_file}" ] && work_item=$(cat "${current_work_item_number_file}") || work_item="please fill in!"

# Yes folks, this is the TFS convention (hard, NOT-TO-BE-ALTERED text)
# to properly link to work items via SvnBridge commits!
work_item_prefix_hard_tfs_convention_text="work item: "

work_item_text="${work_item_prefix_hard_tfs_convention_text}${work_item}"

custom_text="${work_item_text}\n\n[this addition above initially placed to ignored content part here,\nto ensure properly abortable empty message by default - please move it to active content as needed]"

sed -e 's/\(will be ignored--\)/\1\n'"${custom_text}"'/' "${template_file}" > "${template_file_new}"

mv -f "${template_file_new}" "${template_file}"

$EDITOR "${@}"

and then simply do

export SVN_EDITOR=~/bin/svn_editor

in ~/.bashrc or some such. Bonus points for keeping the work item number file updated even from the current work item page as viewed in Firefox TFS web interface (I think there possibly is a way to communicate with Firefox to get page titles etc.). Or simply have this script start a first initial editor run on the persistent work item file and then let it do the second editor run on the customized commit template.

like image 42
JoeRandomUser Avatar answered Nov 09 '22 19:11

JoeRandomUser


I found it using: Folder right-click -> Properties -> New... -> Advanced -> Property name: tsvn:logtemplate -> enter a Property value -> OK -> OK.

like image 36
Safa Avatar answered Nov 09 '22 19:11

Safa