Subversion pre-commit hook

| | Comments (0) | TrackBacks (0)

SubversionRepository Hook이라는 메커니즘을 가지고 있다.

pre-commit hook을 사용해, commit하는 내용이나 사용자에 따라, commit할지 말지 여부를 결정하거나, 내용을 수정할 수 있으며, post-commit hook을 사용하면, 모든 commit에 대해 메일을 보내거나 통계를 업데이트할 수 있다.

pre-commit hook을 등록 할 때는 다음 세 가지를 신경 쓰면 된다.

  1. 실행 가능: Subversion repository의 hooks/pre-commit 파일을 액세스하는 프로그램 (e.g. 웹 서버)이 실행 권한을 가질 수 있도록 해야 한다.
  2. exit code: exit code에 따라 commit 여부가 결정된다. 0이라면 commit 성공, 1이라면 commit 실패.
  3. stderr: 표준 에러로 출력한 메시지가 클라이언트의 에러 메시지로 출력된다.

예를 들어, 공백만 있는 commit log와, 특정 author에 의한 commit을 막으려면 다음과 같은 pre-commit hook 스크립트를 사용하면 된다

#!/bin/sh

REPOS="$1"
TXN="$2"

SVNLOOK=/usr/bin/svnlook

$SVNLOOK log -t "$TXN" "$REPOS" | grep "[^[:space:]]" > /dev/null
if [ $? -ne 0 ]; then
    echo -n 'EMPTY commit log is NOT ALLOWED' 1>&2
    exit 1
fi

$SVNLOOK author -t "$TXN" "$REPOS" | grep -v -e "^public$" > /dev/null
if [ $? -ne 0 ]; then
    echo -n 'USER public is NOT ALLOWED' 1>&2
    exit 1
fi

exit 0

이러한 hook들은 shell script로만 한정되는 것은 아니므로, python이나 외부 프로그램을 실행하는 스크립트 등의 방식을 활용할 수 있다.

Subversion repository에 강제하고 싶은 규칙이 있다면, Subversion의 pre-commit hook을 활용해 보자.

0 TrackBacks

Listed below are links to blogs that reference this entry: Subversion pre-commit hook.

TrackBack URL for this entry: http://lastmind.net/mt/mt-tb.cgi/494

Leave a comment

Author

Linko Apple Booth in the Coex Seoul Email address

About this Entry

This page contains a single entry by Joseph Jang published on November 23, 2008 8:07 PM.

NHN DeView 2008 was the previous entry in this blog.

Dreyfus Model is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.