Skip to content

Instantly share code, notes, and snippets.

@14kw
Last active December 22, 2015 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 14kw/6533180 to your computer and use it in GitHub Desktop.
Save 14kw/6533180 to your computer and use it in GitHub Desktop.
【本家のpost-receiveを使うこと推奨!http://trac-hacks.org/wiki/GitPlugin#post-receivehookscripts】 GitにpushしたときコミットコメントにTracのチケット番号が指定されていた場合、Tracのコメントに付きするHookスクリプト。複数コミットをプッシュする際に、プッシュ前の最終リビジョン値を知っておく必要があるので、プッシュ後lastcommitっていうテキストに書き残す運用にしている。雑だけどまぁいいか。
#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".
TRAC_ENV="/var/repos/trac/hogehoge"
GIT_NAME="fugafuga.git"
GITPATH="/var/repos/git/hogehoge/fugafuga.git"
# 全リビジョンから最新のリビジョンを取得
newrev=`git log --all | grep '^commit' | head -1 | sed -e 's/commit //g'`
# どのリポジトリのコミットが検索
revname=`git name-rev $newrev | awk {' print $2 '} | sed -e "s/~.*$//g"`
# リポジトリ毎に最終リビジョンメモ用のファイルを用意
LASTCOMMIT=$GITPATH"/hooks/lastcommit_"$revname
if [ -e $LASTCOMMIT ]; then
lastrev=`cat $LASTCOMMIT`
commitlist=`git log ${lastrev}...${newrev} --reverse | grep '^commit' | sed -e 's/commit //g'`
for i in $commitlist
do
trac-admin $TRAC_ENV changeset added $GIT_NAME $i
done
else
trac-admin $TRAC_ENV changeset added $GIT_NAME $newrev
fi
echo $newrev > $LASTCOMMIT
cd $GITPATH
exec git update-server-info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment