付録 D. TortoiseSVN の自動化

目次

TortoiseSVN コマンド
Tsvncmd URL ハンドラ
TortoiseIDiff コマンド

TortoiseSVN の全コマンドはコマンドラインパラメータから制御できるため、バッチスクリプトや、他のプログラム (例: お好みのテキストエディタ) から指定したコマンドやダイアログを起動するのを自動化できます。

重要項目

TortoiseSVN は GUI クライアントであることを忘れないでください。またこの自動化ガイドは、ユーザの入力を集めるのに TortoiseSVN ダイアログを表示させる方法を説明しています。入力を全くさせないようなスクリプトを書く場合は、公式 Subversion コマンドラインクライアントの方を使用してください。

TortoiseSVN コマンド

TortoiseSVN GUI プログラムは TortoiseProc.exe で呼び出されます。すべてのコマンドで /command:abcd パラメータを指定できます。abcd にはコマンド名が必要です。ほとんどのコマンドは /path:"some\path" という形で、少なくともひとつのパスを引数に渡す必要があります。以下の表で、/command:abcd パラメータに渡すコマンドと、/path:"some\path" パラメータに渡すパスを説明しています。

いくつかのコマンドは対象のパスを複数与えられる (例: コミット時に複数ファイルを指定) ので、/path パラメータには * で区切って複数のパスを与えます。

TortoiseSVN は、シェル拡張とメインプログラムの間で複数の引数を渡すのに、一時ファイルを使用します。TortoiseSVN 1.5.0 以降から、/notempfile パラメータはサポートされなくなり、追加する必要はなくなります。

You can also specify a file which contains a list of paths, separated by newlines. The file must be in UTF-16 format. If you pass such a file, use /pathfile instead of /path. To have TortoiseProc delete that file after the command is finished, you can pass the parameter /deletepathfile.

コミットや更新、その他たくさんのコマンドで使用する進行ダイアログは、通常 OK ボタンを押すまで、コマンドが終了した後も開いたままになります。設定ダイアログにある該当オプションをチェックして、動作を変更できます。しかしそれでは、バッチファイルからコマンドを起動しても、TortoiseSVN コンテキストメニューから起動しても、進行ダイアログは閉じてしまいます。

異なる場所にある設定ファイルを指定するには、/configdir:"path\to\config\directory" パラメータを使用してください。レジストリに設定されているデフォルトパスを上書きします。

永続的な設定を行わずに、コマンド終了時に進行ダイアログを自動で閉じるには、/closeonend パラメータを渡すことで行えます。

  • /closeonend:0 自動でダイアログを閉じません。

  • /closeonend:1 エラーがなければ自動で閉じます。

  • /closeonend:2 エラーや競合がなければ自動で閉じます。

  • /closeonend:3 エラー、競合、マージがなければ自動で閉じます。

エラーや競合がない場合、ローカル操作の進行ダイアログを閉じるには、/closeforlocal パラメータを渡してください。

以下の表には、TortoiseProc.exe のコマンドラインで使用してアクセスする、すべてのコマンドを一覧しています。上で述べたように、/command:abcd の形で使用してください。表では、紙面を節約するため、頭に付ける /command は省略しています。

表 D.1. 使用できるコマンドとオプションの一覧

コマンド説明
:aboutabout ダイアログを表示します。コマンドを与えなくても表示します。
:logOpens the log dialog. The /path specifies the file or folder for which the log should be shown. Six additional options can be set: /startrev:xxx, /endrev:xxx, /strict enables the 'stop-on-copy' checkbox, /findstring:"filterstring" fills in the filter text, /findtext forces the filter to use text, not regex, or /findregex forces the filter to use regex, not simple text search, and /findtype:X with X being a number between 1 and 7. The numbers correspond to:
  • /findtype:1 すべてに対してフィルタ

  • /findtype:2 メッセージでフィルタ

  • /findtype:3 パスに対してフィルタ

  • /findtype:4 作者に対してフィルタ

  • /findtype:5 リビジョンに対してフィルタ

  • /findtype:7 バグ ID に対してフィルタ

:checkoutOpens the checkout dialog. The /path specifies the target directory and the /url specifies the URL to checkout from. If you specify the key /blockpathadjustments, the automatic checkout path adjustments are blocked.
:importインポートダイアログを開きます。/path にインポートするデータのディレクトリを指定します。
:updateUpdates the working copy in /path to HEAD. If the option /rev is given then a dialog is shown to ask the user to which revision the update should go. To avoid the dialog specify a revision number /rev:1234. Other options are /nonrecursive, /ignoreexternals and /includeexternals.
:commitコミットダイアログを開きます。コミットする対象ディレクトリかファイルリストを、/path に指定します。/logmsg スイッチで、コミットダイアログに渡す定義済みのログメッセージを指定することもできます。または、コマンドラインからログメッセージを渡したくなければ、/logmsgfile:path を使用してください。path にはログメッセージのファイルを指定します。(バグ追跡システムの属性で統合の設定をしてある場合) バグ ID ボックスをあらかじめ入力しておくには、/bugid:"the bug id here" を使用できます。
:add/path のファイルをバージョン管理に追加します。
:revert作業コピーの手元の更新を取り消します。/path には取り消す項目を指定します。
:cleanupCleans up interrupted or aborted operations and unlocks the working copy in /path. Use /noui to prevent the result dialog from popping up (either telling about the cleanup being finished or showing an error message).
:resolve/path で指定した競合ファイルを解消としてマークします。/noquestion が与えられると、本当に行ってもよいか確認せずに解消を実行します。
:repocreate/path にリポジトリを作成します。
:switch切り替えダイアログを開きます。/path に対象ディレクトリを指定します。
:exportExports the working copy in /path to another directory. If the /path points to an unversioned directory, a dialog will ask for an URL to export to the directory in /path. If you specify the key /blockpathadjustments, the automatic export path adjustments are blocked.
:mergeマージダイアログを開きます。/path にはターゲットディレクトリを指定します。マージするリビジョン範囲は以下のオプションを利用できます。/fromurl:URL, /revrange:string 2 つのリポジトリツリーをマージするには、以下のオプション得降利用できます。/fromurl:URL, /tourl:URL, /fromrev:xxx, /torev:xxx 以上はマージダイアログにあらかじめ設定した状態になります。
:mergeallすべてマージダイアログを開きます。/path に対象ディレクトリを指定します。
:copyブランチ・タグダイアログを開きます。/path はブランチ・タグから作る作業コピーです。また、/url はターゲットの URL です。/logmsg スイッチで、ブランチ・タグダイアログに渡す定義済みのログメッセージを指定することもできます。または、コマンドラインからログメッセージを渡したくなければ、/logmsgfile:path を使用してください。path にはログメッセージのファイルを指定します。
:settings設定ダイアログを開きます。
:remove/path のファイルをバージョン管理下から削除します。
:rename/path のファイルの名前を変更します。このファイルの新しい名前を入力するダイアログを表示します。同様のファイルの名前の変更を行う際、1 ステップで質問が発生しないようにするには、/noquestion を渡してください。
:diffStarts the external diff program specified in the TortoiseSVN settings. The /path specifies the first file. If the option /path2 is set, then the diff program is started with those two files. If /path2 is omitted, then the diff is done between the file in /path and its BASE. To explicitly set the revision numbers use /startrev:xxx and /endrev:xxx. If /blame is set and /path2 is not set, then the diff is done by first blaming the files with the given revisions. The parameter /line:xxx specifies the line to jump to when the diff is shown.
:showcompare

比較する URL とリビジョンにより、unified diff (unified オプションを設定した場合) か、変更があるファイルのリストを示すダイアログ、もしくは URL がファイルを指している場合、その 2 つのファイルに対する diff ビューアを起動します。

オプションの url1, url2, revision1, revision2 を指定しなければなりません。オプションのpegrevision, ignoreancestry, blame, unified を指定することもできます。

:conflicteditor/path の競合ファイルを修正するため、TortoiseSVN 設定で指定した競合エディタを起動します。
:relocate再配置ダイアログを表示します。/path には、再配置する作業コピーのパスを指定します。
:helpヘルプファイルを開きます。
:repostatus変更をチェックダイアログを開きます。/path には作業コピーディレクトリを指定します。/remote を指定すると、ユーザが リポジトリをチェック ボタンを押したときのように、直ちにリポジトリにアクセスを開始します。
:repobrowser/path で指定した作業コピーの URL や、/path で直接指定した URL に対して、リポジトリブラウザダイアログを起動します。リポジトリブラウザが表示するリビジョンを、/rev:xxx 追加オプションで指定できます。/rev:xxx を省略すると、デフォルトは HEAD になります。/path が URL を示す場合、プロジェクト属性を使用して読み取るパスを、/projectpropertiespath:path/to/wc と指定します。
:ignore/path の全対象を無視リストに追加します。つまり svn:ignore 属性をそのファイルに追加します。
:blame

/path で指定したファイルの注釈ダイアログを開きます。

/startrev オプションや /endrev オプションをセットすると、注釈範囲を指定するダイアログを表示せず、オプションで指定したリビジョンの値を使用します。

/line:nnn オプションを指定すると、TortoiseBlame を開く際に指定した行番号を表示します。

/ignoreeol オプションや /ignorespaces オプション、/ignoreallspaces オプションもサポートしています。

:cat/path で与えたURL や作業コピーパスから、/savepath:path で与えた場所に保存します。/revision:xxx でリビジョンを指定します。指定したリビジョンのファイルを取得するのに使用できます。
:createpatch/path で与えたパスのパッチファイルを作成します。
:revisiongraph/path で指定したパスのリビジョングラフを表示します。
:lock/path で与えたファイルや、与えたディレクトリにあるすべてのファイルをロックします。ロック時のコメントを入力するよう「ロック」ダイアログを表示します。
:unlock/path で与えたファイルや、与えたディレクトリにあるすべてのファイルのロックを解除します。
:rebuildiconcacheWindows のアイコンキャッシュを再生成します。Windows のアイコンが破損したときのみ使用します。これの (避けられない) 副作用として、デスクトップのアイコンを再配置してしまうことがあります。メッセージボックスの表示を抑制するには、/noquestion を渡してください。
:properties/path で指定したパスの属性ダイアログを表示します。


サンプル (一行で入力してください):

TortoiseProc.exe /command:commit
                 /path:"c:\svn_wc\file1.txt*c:\svn_wc\file2.txt"
                 /logmsg:"test log message" /closeonend:0

TortoiseProc.exe /command:update /path:"c:\svn_wc\" /closeonend:0

TortoiseProc.exe /command:log /path:"c:\svn_wc\file1.txt"
                 /startrev:50 /endrev:60 /closeonend:0