PageRenderTime 179ms CodeModel.GetById 174ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/etckeeper/init.d/50vcs-pre-commit-hook

http://github.com/brinkman83/bashrc
Shell | 49 lines | 44 code | 1 blank | 4 comment | 7 complexity | 16828750de6a26c18b1bee791d85e4d5 MD5 | raw file
 1#!/bin/sh
 2set -e
 3
 4case "$VCS" in
 5	git)
 6		if [ -x .git/hooks/pre-commit ]; then
 7			if ! grep -q "etckeeper pre-commit" .git/hooks/pre-commit; then
 8				echo "etckeeper warning: .git/hooks/pre-commit needs to be manually modified to run: etckeeper pre-commit -d `pwd`" >&2
 9			fi
10		else
11			cat >.git/hooks/pre-commit <<EOF
12#!/bin/sh
13# pre-commit hook for etckeeper, to store metadata and do sanity checks
14set -e
15etckeeper pre-commit -d `pwd`
16EOF
17		chmod +x .git/hooks/pre-commit
18		fi
19	;;
20	hg)
21		if [ -e .hg/hgrc ] && grep "^\[hooks\]" .hg/hgrc; then
22			if ! grep -q "etckeeper pre-commit" .hg/hgrc; then
23				echo "etckeeper warning: [hooks] section in .hg/hgrc needs to be manually modified to run: etckeeper pre-commit -d `pwd`" >&2
24			fi
25		else
26			touch .hg/hgrc
27			cat >>.hg/hgrc <<EOF
28[hooks]
29# pre-commit hook for etckeeper, to store metadata and do sanity checks
30precommit = etckeeper pre-commit -d `pwd`
31EOF
32		fi
33	;;
34	darcs)
35		if [ -e _darcs/prefs/defaults ]; then
36			if ! ( grep -q "record prehook etckeeper pre-commit" _darcs/prefs/defaults &&
37				grep -q "whatsnew prehook etckeeper pre-commit" _darcs/prefs/defaults ); then
38				echo "etckeeper warning: _darcs/prefs/defaults needs to be manually modified to run: etckeeper pre-commit -d `pwd`" >&2
39			fi
40		else
41			cat >_darcs/prefs/defaults <<EOF
42record prehook etckeeper pre-commit -d `pwd`
43record run-prehook
44whatsnew prehook etckeeper pre-commit -d `pwd`
45whatsnew run-prehook
46EOF
47		fi
48	;;
49esac