LoginSignup
18
19

More than 5 years have passed since last update.

subversionのpost-commitで更新されたファイルを取得する

Posted at

はじめに

subversionのpost-commitフックで更新されたファイルを取得する方法を記載します。

trunkにコミットされたときだけ、XXXしたいのような要望に対応できそうです。

環境

  • Amazon Linux AMI release 2014.03
  • subversion 1.8.8

subversionのインストール

$ sudo yum install subversion

リポジトリの作成

$ svnadmin create sample
$ svn mkdir file:///path/to/repository/trunk \
    file:///path/to/repository/branches      \
    file:///path/to/repository/tags          \
    -m 'create trunk,branches,tags'

post-commitフックを有効にする

$ cp -p /path/to/repository/hooks/post-commit.tmpl /path/to/repository/hooks/post-commit

※ post-commitに実行権限がついていることを確認しておきます。

$ ls -l /path/to/repository/hooks/post-commit
-rwxrwxr-x 1 ec2-user ec2-user 2062 Aug 25 21:57 /home/ec2-user/repos/svn/sample2/hooks/post-commit

更新されたファイルを取得する

svnlookコマンドで更新されたファイルを取得します。
post-commitフックの引数やsvnlookコマンドの出力をログファイルへ記録するようにしておきます。

post-commit
#!/bin/sh

REPOS="$1"
REV="$2"
TXN_NAME="$3"

echo "$REPOS $REV $TXN_NAME" >> path/to/logfile
svnlook changed -r $REV $REPOS >> /path/to/logfile

動作確認

リポジトリをチェックアウトする

$ svn checkout file:///path/to/repository/trunk sample-trunk

リポジトリへ変更をコミットする

$ cd sample-trunk
$ touch sample.txt sample2.txt sample3.txt
$ svn add *
A    sample2.txt
A    sample3.txt
A    sample.txt
$ svn commit -m 'add sample files.'
Adding sample.txt
Adding sample2.txt
Adding sample3.txt
Transmitting file data ...
Committed revision 3.

※ post-commitフックによる出力を確認します。

$ cat /path/to/logfile
/path/to/repository 3 2-2
A    trunk/sample.txt
A    trunk/sample2.txt
A    trunk/sample3.txt

※ branchからもコミットしてみます。

$ svn copy file:///path/to/repsitory/trunk file:///path/to/repository/branches/b1 -m 'create b1 branch'
$ cd ../
$ svn checkout file:///path/to/repository/branches/b1 sample-branches
$ cd sample-branches
$ hostname > sample.txt
$ touch sample4.txt
$ svn rm sample3.txt
$ svn add sample4.txt
$ svn commit -m 'modify sample.txt, delete sample3.txt and add sample4.txt'
Sending    sample.txt
Deleting   sample3.txt
Adding     sample4.txt
Transmitting file data ..
Committed revision 5.
$ cat /path/to/logfile
...(省略)...
/path/to/repository 5 4-4
U    branches/b1/sample.txt
D    branches/b1/sample3.txt
A    branches/b1/sample4.txt
18
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
19