Initial import.
[dcp.git] / dcp-update
CommitLineData
9f26b93f
FT
1#!/bin/sh
2
3set -e
4
5usage() {
6 echo "usage: dcp-update [-Nh] REPODIR"
7}
8
9rungit() {
10 (
11 cd "$td/repo"
12 git "$@"
13 ) || false
14}
15
16defdir=/srv/dcp
17push=y
18
19while [ "${1:0:1}" = - ]; do
20 opt="${1:1}"
21 shift
22 if [ "$opt" = N ]; then
23 push=n
24 shift
25 elif [ "$opt" = h ]; then
26 usage
27 exit 0
28 else
29 echo "dcp-update: unknown option '$opt'" >&2
30 exit 1
31 fi
32done
33
34if [ $# -lt 1 ]; then
35 usage >&2
36 exit 1
37fi
38
39repodir="$1"
40shift
41if [[ "$repodir" != */* ]]; then
42 repodir="$defdir/${repodir}.git"
43fi
44
45if [ ! -d "$repodir" ]; then
46 echo "dcp-build: could not find $repodir" >&2
47 exit 1
48fi
49
50td="$(mktemp -d /tmp/dcp-XXXXXX)"
51exec >"$td/log" 2>"$td/err"
52dcp-runenv "$repodir" "$td"
53
54lastrev="$(rungit rev-parse HEAD)"
55(cd "$td"; control/update) || false
56rungit checkout master
57newrev="$(rungit rev-parse HEAD)"
58
59echo "update: $lastrev -> $newrev"
60
61if [ "$push" = y ]; then rungit push; fi
62
63rm -rf "$td"