Debian Codegraph @

tools/pre-commit

raw
1 #!/bin/bash
2
3 # Exit with status 1 if any command below fails
4 set -e
5
6 # Exit if it's not a branch we're interested in being thorough about
7 if echo $(git rev-parse --symbolic-full-name HEAD) | \
8 egrep -q '^refs/heads/(t/)'; then
9 exit 0
10 fi
11
12 # These are the locations I keep my temporary source and build trees in
13 PRODUCTS=$(./acprep products) # generates a build directory name such as
14 # ~/Products/ledger
15 if echo $PRODUCTS | grep -qv ledger; then
16 PRODUCTS=$PRODUCTS/ledger
17 fi
18 TMPDIR=$PRODUCTS/pre-commit
19 MIRROR=$PRODUCTS/pre-commit-mirror
20
21 # Checkout a copy of the current index into MIRROR
22 git checkout-index --prefix=$MIRROR/ -af
23
24 # Remove files from MIRROR which are no longer present in the index
25 git diff-index --cached --name-only --diff-filter=D -z HEAD | \
26 (cd $MIRROR && xargs -0 rm -f --)
27
28 # Copy only _changed files_ from MIRROR to TMPDIR, without copying
29 # timestamps. This includes copying over new files, and deleting
30 # removed ones. This way, "make check" will only rebuild what is
31 # necessary to validate the commit.
32 rsync -rlpgoDOc --delete --exclude-from=tools/excludes $MIRROR/ $TMPDIR/
33
34 # Everything else happens in the temporary build tree
35 if [ ! -f $TMPDIR/lib/utfcpp/source/utf8.h ]; then
36 rsync -a --delete lib/utfcpp/ $TMPDIR/lib/utfcpp/
37 fi
38 cd $TMPDIR
39
40 # Make sure there is a current Makefile. Regeneration of Makefile
41 # happens automatically, but if myacprep or acprep changes, we want to
42 # regenerate everything manually. If the user doesn't have acprep, look
43 # for other common autoconf-related script files.
44 if [ ! -f Makefile -o \
45 Makefile.in -nt Makefile -o \
46 configure -nt Makefile -o \
47 tools/Makefile.am -nt Makefile.in -o \
48 tools/configure.ac -nt configure -o \
49 \( -f acprep -a acprep -nt Makefile \) ]
50 then
51 if [ -f acprep ]; then
52 echo Will run acprep in a moment
53 elif [ -f autogen.sh ]; then
54 sh autogen.sh && ./configure
55 else
56 autoreconf && ./configure
57 fi
58 fi
59
60 # Finally, (re)build this proposed source tree and see if it passes
61 # muster.
62
63 if [ -f acprep ]; then
64 nice -n 20 ./acprep default --warn make check
65 else
66 nice -n 20 make check
67 fi
68
69 exit 0