summaryrefslogtreecommitdiff
path: root/tools/pre-commit
blob: db47cc45e01855573ab9aa7134b94b856e338b27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash

# Exit with status 1 if any command below fails
set -e

# Exit if it's not a branch we're interested in being thorough about
if echo $(git rev-parse --symbolic-full-name HEAD) | \
    egrep -q '^refs/heads/(t/)'; then
    exit 0
fi

# These are the locations I keep my temporary source and build trees in
PRODUCTS=$(./acprep products)	# generates a build directory name such as
                                # ~/Products/ledger
if echo $PRODUCTS | grep -qv ledger; then
    PRODUCTS=$PRODUCTS/ledger
fi
TMPDIR=$PRODUCTS/pre-commit
MIRROR=$PRODUCTS/pre-commit-mirror

# Checkout a copy of the current index into MIRROR
git checkout-index --prefix=$MIRROR/ -af

# Remove files from MIRROR which are no longer present in the index
git diff-index --cached --name-only --diff-filter=D -z HEAD | \
    (cd $MIRROR && xargs -0 rm -f --)

# Copy only _changed files_ from MIRROR to TMPDIR, without copying
# timestamps.  This includes copying over new files, and deleting
# removed ones.  This way, "make check" will only rebuild what is
# necessary to validate the commit.
rsync -rlpgoDOc --delete --exclude-from=tools/excludes $MIRROR/ $TMPDIR/

# Everything else happens in the temporary build tree
if [ ! -f $TMPDIR/lib/utfcpp/source/utf8.h ]; then
    rsync -a --delete lib/utfcpp/ $TMPDIR/lib/utfcpp/
fi
cd $TMPDIR

# Make sure there is a current Makefile.  Regeneration of Makefile
# happens automatically, but if myacprep or acprep changes, we want to
# regenerate everything manually.  If the user doesn't have acprep, look
# for other common autoconf-related script files.
if [ ! -f Makefile -o \
     Makefile.in -nt Makefile -o \
     configure -nt Makefile -o \
     tools/Makefile.am -nt Makefile.in -o \
     tools/configure.ac -nt configure -o \
     \( -f acprep -a acprep -nt Makefile \) ]
then
    if [ -f acprep ]; then
	echo Will run acprep in a moment
    elif [ -f autogen.sh ]; then
	sh autogen.sh && ./configure
    else
	autoreconf && ./configure
    fi
fi

# Finally, (re)build this proposed source tree and see if it passes
# muster.

if [ -f acprep ]; then
    nice -n 20 ./acprep default --warn make check
else
    nice -n 20 make check
fi

exit 0