summaryrefslogtreecommitdiffstats
path: root/contrib/utils/gitolite-local
blob: 903b868e87cd43ee198c0f8165c2a903147534d3 (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
131
132
133
134
135
136
#!/bin/bash

# ----------------------------------------------------------------------
# change these lines to suit
testconf=$HOME/GITOLITE-TESTCONF
gitolite_url=https://github.com/sitaramc/gitolite
    # change it to something local for frequent use
    # gitolite_url=file:///tmp/gitolite.git

# ----------------------------------------------------------------------
# Usage: gitolite-local <options>
#
# Test your gitolite.conf rule lists on your LOCAL machine (without even
# pushing to the server!)
#
# (one-time)
#
#   1.  put this code somewhere in your $PATH if you wish
#   2.  edit the line near the top of the script if you want to use some other
#       directory than the default, for "testconf".
#   2.  prepare the "testconf" directory by running:
#           gitolite-local prep
#
# (lather, rinse, repeat)
#
#   1.  edit the conf (see notes below for more)
#           gitolite-local edit
#   2.  compile the conf
#           gitolite-local compile
#   3.  check permissions using "info" command:
#           gitolite-local info USERNAME
#   4.  check permissions using "access" command:
#           gitolite-local access <options for gitolite access command>
#   5.  clone, fetch, and push if you like!
#           gitolite-local clone <username> <reponame> <other options for clone>
#           gitolite-local fetch <username> <options for fetch>
#           gitolite-local push  <username> <options for push>
#
# note on editing the conf: you don't have to use the edit command; you can
# also directly edit '.gitolite/conf/gitolite.conf' in the 'testconf'
# directory.  You'll need to do that if your gitolite conf consists of more
# than just one file (like if you have includes, etc.)
#
# note on the clone command: most of the options won't work for clone, unless
# git is ok with them being placed *after* the repo name.

# ----------------------------------------------------------------------
die() { echo "$@" >&2; exit 1; }
usage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; }
[ -z "$1" ] && usage

# ----------------------------------------------------------------------
if [ $1 == prep ]
then
    set -e

    [ -d $testconf ] && die "directory '$testconf' already exists"

    mkdir $testconf
    cd $testconf

    export HOME=$PWD

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

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

    echo setting up gitolite...
    export PATH=$PWD/gitolite/src:$PATH
    gitolite setup -a admin
    echo

    exit 0
fi

od=$PWD
cd $testconf
export HOME=$PWD
export PATH=$PWD/gitolite/src:$PATH

if [ $1 = edit ]
then
    editor=${EDITOR:-vim}
    $editor .gitolite/conf/gitolite.conf
elif [ $1 = compile ]
then
    gitolite compile
elif [ $1 = compile+ ]
then
    gitolite compile\; gitolite trigger POST_COMPILE
elif [ $1 = info ]
then
    shift
    user=$1
    shift

    GL_USER=$user gitolite info "$@"
elif [ $1 = access ]
then
    shift

    gitolite access "$@"
elif [ $1 = clone ]
then
    shift
    export G3T_USER=$1
    shift

    cd $od
    export GL_BINDIR=$HOME/gitolite/t
        # or you could do it the long way, using 'gitolite query-rc GL_BINDIR'
    repo=$1; shift
    git clone --upload-pack=$GL_BINDIR/gitolite-upload-pack file:///$repo "$@"
elif [ $1 = fetch ]
then
    shift
    export G3T_USER=$1
    shift

    cd $od
    export GL_BINDIR=$HOME/gitolite/t
    git fetch --upload-pack=$GL_BINDIR/gitolite-upload-pack "$@"
elif [ $1 = push ]
then
    shift
    export G3T_USER=$1
    shift

    cd $od
    export GL_BINDIR=$HOME/gitolite/t
    git push --receive-pack=$GL_BINDIR/gitolite-receive-pack "$@"
fi