Can we change the default svn commit template using svn hooks

﹥>﹥吖頭↗ 提交于 2019-12-06 13:03:35

问题


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"

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.

We only use the svn command client.


回答1:


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

  • TortoiseSVN: use the client hooks for that purpose
  • SVN command client: use a shell script and some svn properties

TortoiseSVN Client Hooks

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

Start-commit

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.

The hook has the following arguments:

  • PATH: A path to a temporary file which contains all the paths for which the operation was started. Each path is on a separate line in the temp file.
  • MESSAGEFILE: Path to a file containing the log message for the commit. The file contains the text in UTF-8 encoding. After successful execution of the start-commit hook, the log message is read back, giving the hook a chance to modify it.
  • CWD: The current working directory with which the script is run. This is set to the common root directory of all affected paths.

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.

SVN command client script and svn:template-file property

  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.

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.




回答2:


Here is one I created. It attempts to use the TortoiseSVN template if it exists, otherwise it looks for a template file in the global Git config, else it falls back to a built in template.

  • Code
  • Explanation

Note that using the standard TortoiseSVN template property does not mean you have to have TortoiseSVN installed.



来源:https://stackoverflow.com/questions/8212640/can-we-change-the-default-svn-commit-template-using-svn-hooks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!