3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

push したタイミングで Trac のチケットへコミットコメントを反映するフックスクリプト

Last updated at Posted at 2013-02-05

前提

Trac のプラグイン CommitTicketReferenceMacro、CommitTicketUpdater を有効にしておく。

Git のフックスクリプト

post-receive
# !/bin/sh
#
# An example hook script for the "post-receive" event.
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated.  It is passed arguments in through
# stdin in the form
#  <oldrev> <newrev> <refname>
# For example:
#  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
#
# see contrib/hooks/ for a sample, or uncomment the next line and
# rename the file to "post-receive".

# . /usr/local/share/git-core/contrib/hooks/post-receive-email

GIT_APP="/usr/local/bin/git"
TRAC_ADMIN="/usr/local/bin/trac-admin"
TRAC_ENV="【Tracのenvへのパス】"
REPO_NAME="【Tracに登録したGITリポジトリ名】"
LOG="/dev/null"

while read oldrev newrev refname; do

    echo "oldrev=${oldrev}, newrev=${newrev}, refname=${refname}" >> "${LOG}"

    from_rev=`git log -n 1 --reverse --pretty=format:%h ${oldrev}`
    to_rev=`git log -n 1 --reverse --pretty=format:%h ${newrev}`

    echo "from_rev=${from_rev}, to_rev=${to_rev}" >> "${LOG}"

    added_flag="0"
    for rev in `${GIT_APP} log --reverse --pretty=format:%h`; do

        if [ "${added_flag}" = "1" -o "${from_rev}" = "" ]; then
            echo "rev=${rev}" >> "${LOG}"
            ${TRAC_ADMIN} "${TRAC_ENV}" changeset added "${REPO_NAME}" "${rev}"
        elif [ "${from_rev}" = "${rev}" ]; then
            added_flag="1"
        fi
    done
done

${TRAC_ADMIN} "${TRAC_ENV}" repository resync "${REPO_NAME}"

心配事

ブランチをマージした後 push すると、チケットがコメントだらけになってしまうかも?

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?