我们可以使用svn钩子更改默认的svn提交模板吗 [英] Can we change the default svn commit template using svn hooks

查看:248
本文介绍了我们可以使用svn钩子更改默认的svn提交模板吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要想在执行svn commit时即时更改默认的提交模板(svn-commit.tmp). 我从论坛上得知,设置SVN_EDITOR会有所帮助

I primarily wanted to change my default commit template(svn-commit.tmp) on the fly when I do a svn commit. I got the knew from forums that setting the SVN_EDITOR would help

setenv SVN_EDITOR "rm svn-commit.tmp && cp $REPO/hooks/log.tmpl svn-commit.tmp && emacs"

但是,只有在用户如上所述在其用户环境中设置SVN_EDITOR时,才会发生这种情况. 还有其他任何明确的方法可以让我在执行svn commit时从其他位置而不是默认位置打开模板文件.提交模板将更特定于存储库和提交日期.因此,有一种方法可以在svn存储库上设置一些属性来调用不同的提交模板. 我应该将其强制应用于所有(特定于存储库的),并且不应像设置SVN_EDITOR那样是特定于用户的.即使我们设置了SVN_EDITOR,当我们通过调用某些钩子进行svn commit时也可以调用此设置.我了解前&提交提交之后,才会提交提交钩子.

But this would happen only if the user sets the SVN_EDITOR in his user environment as above. So is there any other explicit way that when I do a svn commit, I will open a template file from a different location rather than the default one. The commit template would be more specific to repositories and the date of commit. So is there a way where I can set some property on the svn repository to invoke a different commit template. I should enforce it to all(repository specific) and it should not be user-specific like setting the SVN_EDITOR. Even if we are setting the SVN_EDITOR can this setting be called when we do a svn commit by calling some hooks. I understand that pre & post commit hooks will be called only after the commit is submitted.

我们仅使用svn命令客户端.

We only use the svn command client.

推荐答案

有两种可行的方法,具体取决于您必须使用的subversion客户端:

There are 2 possible ways to go, depending on the subversion client you have to use:

  • TortoiseSVN:为此使用客户端挂钩
  • SVN命令客户端:使用Shell脚本和一些svn属性

当您查看客户端挂钩脚本"一章时,在TortoiseSVN帮助中,您将找到以下部分:

When you look at the chapter "Client Side Hook Scripts" of the TortoiseSVN Help, you will find the following section:

开始提交

在显示提交对话框之前调用.如果挂钩修改了版本化文件并影响了需要提交和/或提交消息的文件列表,则可能要使用此功能.但是,您应该注意,由于挂钩是在早期阶段调用的,因此无法选择要提交的对象的完整列表.

Called before the commit dialog is shown. You might want to use this if the hook modifies a versioned file and affects the list of files that need to be committed and/or commit message. However you should note that because the hook is called at an early stage, the full list of objects selected for commit is not available.

该挂钩具有以下参数:

  • PATH:到临时文件的路径,该文件包含已开始操作的所有路径.每个路径都在临时文件的单独一行上.
  • MESSAGEFILE:包含提交日志消息的文件的路径.该文件包含UTF-8编码的文本.成功执行启动提交挂钩之后,将回读日志消息,使挂钩有机会对其进行修改.
  • CWD:运行脚本的当前工作目录.设置为所有受影响路径的公共根目录.

因此,您有足够的能力来实现一个小的脚本,以根据目录更改svn commit模板.但是,您必须注意如何部署客户端挂钩,因为每个用户都必须自己安装它们.

So you have ingredients to implement a small script to change the svn commit template depending on the directory. However, you have to care how you can deploy the client hook, because each user has to install them on its own.

  1. 定义一个shell脚本,该脚本将在其中调用真正的subversion命令.
  2. 在具有有用名称(例如template-file)的目录上定义svn属性,并从起始目录向上搜索已设置该svn属性的目录.
  3. 使用found属性作为文件名来查找内容(可能应该是URL,因此无需在本地安装这些模板).
  4. 如果未找到,请使用默认模板.
  1. Define a shell script that will call the real subversion command inside.
  2. Define a svn property on directories with a useful name (like template-file) and search from the starting directory upwards a directory that has that svn property set.
  3. Use the found property as the file name to look up the contents (possibly should be an URL, so no local installation of these templates necessary).
  4. If none is found, use the default template.

但是,您也必须在客户端上安装该脚本. Subversion中没有机制可以允许使用不同的模板,而无需在客户端上进行额外的安装.

However, you have to install that script on the client as well. There is no mechanism in Subversion that allows the usage of different templates without an additional installation on the client.

这篇关于我们可以使用svn钩子更改默认的svn提交模板吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆