TortoiseSVNキーワード置換

症状

TortoiseSVNで、キーワード置換ができない。

原因と対処

「設定を失念したまま、プロジェクトをリポジトリに登録してしまった」ということで、(1)キーワード置換の設定、(2)プロジェクトの登録し直し、の2点について対処が必要です。

キーワード置換の設定

「C:\Users\etc\AppData\Roaming\Subversion\config」の該当箇所を次のように設定する。

[miscellany]
enable-auto-props = yes

[auto-props]
*.as = svn:keywords=Author Date Id Rev URL;svn:eol-style=native
*.xml = svn:keywords=Author Date Id Rev URL;svn:eol-style=native
*.mxml = svn:keywords=Author Date Id Rev URL;svn:eol-style=native
*.js = svn:keywords=Author Date Id Rev URL;svn:eol-style=native
*.java = svn:keywords=Author Date Id Rev URL;svn:eol-style=native
*.php = svn:keywords=Author Date Id Rev URL;svn:eol-style=native
      ・・・・(以下略)


キーワード置換は拡張子の種別ごとに登録する必要があります。予期せぬ置換を防ぐためなのでしょうね。

プロジェクトの登録し直し

さらに、プロジェクトが(既に)リポジトリに格納されいる場合は、キーワードが置換が有効にならないということが起きます。その場合はプロジェクトの登録し直しが必要です。

  1. プロジェクトをどこか適当なフォルダにexportし、
  2. リポジトリからプロジェクトを削除し、
  3. さっきexportしたプロジェクトをリポジトリにimportして、
  4. ふさわしいフォルダにプロジェクトをチェックアウトする。

という手順で登録をし直すことで、キーワード置換が有効になるようです。

補足説明

設定用ファイルは、「C:\Users\etc\AppData\Roaming\Subversion\config」というもの。これまで(XP)は「%ALLUSERSPROFILE%\Application Data\Subversion\config」だったけど、Win7では変更になっていました。あるいは、右クリ、コンテキストメニューの「TortoiseSVN」=>「settings」=>「General」=>「Subversion Configuration File:Edit」でアクセスします。
欲しいのはキーワード置換で、config内の「auto-props」と「miscellany」が該当箇所。そこのコメントを拙訳します。

[miscellany]
### Set enable-auto-props to 'yes' to enable automatic properties
### for 'svn add' and 'svn import', it defaults to 'no'.
### Automatic properties are defined in the section 'auto-props'.
# enable-auto-props = yes
'svn add''svn import'に対して自動属性を有効にするためには、
enable-auto-propsを'yes'に設定します。既定では'no'です。
自動属性は'auto-props'セクションで定義します。

[auto-props]
### The format of the entries is:
###   file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?').  All entries which match (case-insensitively) will be
### applied to the file.  Note that auto-props functionality
### must be enabled, which is typically done by setting the
### 'enable-auto-props' option.
登録項目の形式は、
  ファイル名パタン = 属性名[=][;属性名[=]]
です。ファイル名パタンは'*''?'といったワイルドカードを含めることができます。
一致するすべての登録項目がファイルに適用されることになります。
大文字小文字の違いは無視されます。auto-props機能は有効にされなければなりませんが、
それには、'enable-auto-props'オプションを設定します。


ということで、上記「対処」のように設定しました。
参照: