summaryrefslogtreecommitdiffstats
path: root/newrepo.sh
blob: bb248ebdb5851d165998f277045de08f13d81e7a (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
#!/bin/bash

set -e

die() {
    echo "$@" >&2
    exit 1
}


trap '[[ -d "$tmp" ]] && rm -rf "$tmp"' EXIT

while :; do
    case $1 in
        --server)
            opt_server="$2"
            shift 2
            ;;
        --private)
            opt_private=yes
            shift
            ;;
        --name)
            opt_name="$2"
            shift 2
            ;;
        *)
            break
            ;;
    esac
done

top=$(git rev-parse --show-toplevel)

server=${opt_server:-git@the-compiler.org}
if [[ "$opt_name" ]]; then
    name="$opt_name"
else
    name=${top##*/}
fi

if [[ "$opt_private" ]]; then
    user="@private"
else
    user="@public"
fi

desc="$1"

[[ -z "$desc" ]] && die "Usage: $0 [--private] [--server <server>] [--name <name>] <description>"

tmp=$(mktemp -d)
cd "$tmp"
git clone "ssh://$server/gitolite-admin"
cd gitolite-admin/conf

cat >> gitolite.conf << EOF

repo $name
    R                 = $user
    config cgit.desc  = $desc
    config cgit.owner = $(git config --get user.name)
EOF
echo
git commit -am "Add new repository for $name"
echo
git push
cd "$top"
git remote rm origin 2>/dev/null || true
git remote add origin "ssh://$server/$name"
echo
git push -u --all origin
git push --tags origin