]> git.wh0rd.org Git - home.git/blob - .bin/cros-repo
add reference support, and initialize e-mail
[home.git] / .bin / cros-repo
1 #!/bin/sh
2
3 usage() {
4         cat <<-EOF
5         Usage: repo-cros [options]
6
7         Options:
8            int            switch to internal tree
9            ext            switch to external tree
10            -b <branch>    switch branches (use "master" to get to ToT)
11            -r <path>      patch to reference repo (e.g. ~/chromiumos/)
12
13         Operates on the repo in ${PWD}
14         EOF
15         exit ${1:-1}
16 }
17
18 vexec() {
19         printf '%s\n%s\n' "${PWD}" "$*"
20         exec "$@"
21 }
22
23 email="vapier@chromium.org"
24 REF=
25 BRANCH=
26 MANIFEST=
27 REPO_URL=
28 while [[ $# -gt 0 ]] ; do
29         case $1 in
30         int)
31                 MANIFEST='ssh://gerrit-int.chromium.org:29419/chromeos/manifest-internal.git'
32                 REPO_URL='http://git.chromium.org/external/repo.git'
33                 ;;
34         ext)
35                 MANIFEST='http://git.chromium.org/chromiumos/manifest.git'
36                 REPO_URL='http://git.chromium.org/external/repo.git'
37                 ;;
38         -b)
39                 BRANCH=$2
40                 shift
41                 ;;
42         -r)
43                 REF=$(realpath "$2")
44                 shift
45                 ;;
46         *)
47                 usage
48                 ;;
49         esac
50         shift
51 done
52
53 rdir=$(realpath "`pwd`")
54 while [[ ! -d ${rdir}/.repo ]] ; do
55         rdir=${rdir%/*}
56         [[ ${rdir:-/} == "/" ]] && break
57 done
58 rdir+="/.repo"
59 if [[ -d ${rdir} ]] ; then
60         gcfg() { git --git-dir="$1" config user.email "${@:2}" ; }
61         if [[ $(gcfg "${rdir}/manifests.git") != "${email}" ]] ; then
62                 echo "${rdir}: setting e-mail to ${email}"
63                 find "${rdir}" -type d -name '*.git' | \
64                 while read d ; do
65                         gcfg "${d}" ${email}
66                 done
67         fi
68 fi
69
70 vexec \
71         repo init \
72         ${MANIFEST:+-u "${MANIFEST}"} \
73         ${REPO_URL:+--repo-url="${REPO_URL}"} \
74         ${REF:+--reference "${REF}"} \
75         ${BRANCH:+-b "${BRANCH}"}