summaryrefslogtreecommitdiffstats
path: root/contrib/utils/testconf
blob: 03580f9592734e7851ce9addd343ada62d3013ea (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash

# this is meant to be run on your *client* (where you edit and commit files
# in a gitolite-admin *working* repo), not on the gitolite server.
#
# TO USE
# ======

# To use this, first upgrade gitolite to the latest on the server; you need at
# least v3.6.7.
#
# Then, on the client:
#
#   1.  copy this file (contrib/utils/testconf in the latest gitolite) to
#       somewhere in your $PATH
#   2.  modify the following lines if you wish (default should be fine for
#       most people):

    # a semi-permanent area to play in (please delete it manually if you want to start afresh).
    testconf=$HOME/GITOLITE-TESTCONF
    # the gitolite source code
    gitolite_url=https://github.com/sitaramc/gitolite

#   3.  go to your gitolite-admin clone and make suitable changes; see example
#       below.  No need to push to the server, yet.
#   4.  run 'testconf`
#
# CAVEAT: include files are not handled the same way gitolite parsing handles
# them -- we just cat all the conf files together, in sorted order.
#
# If the tests ran OK, push your changes to the server as usual.

# EXAMPLE changes to gitolite.conf
# ================================
# Say you have these rules in the conf file:
#
#     repo foo
#         R       =   u1
#         RW      =   u2
#         RW+     =   u3
#
# To create test code for this, add the following lines to the conf file.
#
#     =begin testconf
#     # you can put arbitrary bash code here, but a simple example follows
#
#     ok() { "$@" && echo ok || echo "not ok ($*)"; }
#     nok() { ! "$@" && echo ok || echo "not ok ($*)"; }
#
#     ok gitolite access -q foo u1 R
#     nok gitolite access -q foo u1 W
#
#     ok gitolite access -q foo u2 W
#     nok gitolite access -q foo u2 +
#
#     ok gitolite access -q foo u3 +
#     =end
#
# Note that you can actually put in any bash code between the 'begin' and
# 'end' lines; the above is just a useful sample/template.
#
# Because of the 'begin' and 'end' lines, gitolite will ignore those lines
# when processing the conf file ON THE SERVER.
#
# (optional) TAP compliance
# =========================
# if you add a line 'echo 1..5' (in this case, since there are 5 ok/nok lines;
# you will certainly have more) to the top the file, you can run
#
#   prove `which testconf`
#
# which will give you a much nicer output.  The only issue is if you have
# include files, you will need to put that in the file whose name is sorted
# first!
#
# Using a non-default ".gitolite.rc"
# ==================================
#
# If your conf needs a non-default `~/.gitolite.rc`, copy the file you need as
# "testconf.gitolite.rc" in the root directory of the gitolite-admin clone
# where you are running "testconf".  (Whether you commit this file to the
# gitolite-admin repo, or keep it local/untracked, is your call).

# ----------------------------------------------------------------------
od=$PWD

# prep

mkdir -p $testconf
cd $testconf

export HOME=$PWD
export PATH=$PWD/gitolite/src:$PATH

[ -d gitolite ] || {

    echo getting gitolite source...
    git clone $gitolite_url gitolite
    echo

    echo installing gitolite...
    gitolite/install >/dev/null
    echo

    echo setting up gitolite...
    gitolite setup -a admin
    echo

}

# copy conf from $od

rm -rf           $testconf/.gitolite/conf
mkdir -p         $testconf/.gitolite/conf
cp -a $od/conf/* $testconf/.gitolite/conf/

# copy rc from $od, if it exists
[ -f $od/testconf.gitolite.rc ] && cp $od/testconf.gitolite.rc $testconf/.gitolite.rc

# compile+

gitolite compile
gitolite trigger POST_COMPILE

# snarf bits of code from conf files and run them

cat `find $testconf/.gitolite/conf -type f -name "*.conf" | sort` |
    perl -ne '
        print if /^=begin testconf$/ .. /^=end$/ and not /^=(begin|end)/;
    ' | /bin/bash