]> git.wh0rd.org - home.git/blob - .bin/cros-repo
8f8765ba23817979678c1945a27ed06f80d52664
[home.git] / .bin / cros-repo
1 #!/bin/bash
2
3 usage() {
4 cat <<-EOF
5 Usage: repo-cros [options]
6
7 Options:
8 depot_tools clone depot_tools tree
9 int switch to internal tree
10 ext switch to external tree
11 -b <branch> switch branches (use "master" to get to ToT)
12 -r <path> patch to reference repo (e.g. ~/chromiumos/)
13 -g <group>
14 -m <manifest>
15 -e <email>
16
17 Operates on the repo in ${PWD}
18 EOF
19 exit ${1:-1}
20 }
21
22 v() {
23 printf '%s\n%s\n' "${PWD}" "$*"
24 "$@"
25 }
26
27 email="vapier@chromium.org"
28 REF=
29 BRANCH=
30 MANIFEST=
31 MANIFEST_NAME=
32 RGROUPS=()
33 REPO_URL=
34 while [[ $# -gt 0 ]] ; do
35 case $1 in
36 depot_tools|dt)
37 exec git clone https://git.chromium.org/chromium/tools/depot_tools.git
38 ;;
39 int)
40 MANIFEST='https://chrome-internal.googlesource.com/chromeos/manifest-internal.git'
41 REPO_URL='https://chromium.googlesource.com/external/repo.git'
42 ;;
43 ext)
44 MANIFEST='https://chromium.googlesource.com/chromiumos/manifest.git'
45 REPO_URL='https://chromium.googlesource.com/external/repo.git'
46 ;;
47 -b)
48 BRANCH=$2
49 shift
50 ;;
51 -r)
52 REF=$(realpath "${2:-$(echo ~/chromiumos)}")
53 shift
54 ;;
55 -g)
56 RGROUPS+=( "$2" )
57 shift
58 ;;
59 -m)
60 MANIFEST_NAME="${2%.xml}.xml"
61 shift
62 ;;
63 -e)
64 email=$2
65 shift
66 ;;
67 *)
68 usage
69 ;;
70 esac
71 shift
72 done
73
74 if [[ ${#BRANCH} -eq 3 ]] && [[ -d ${REF} ]] ; then
75 BRANCH=$(git --git-dir="${REF}/.repo/manifests.git" branch -a | grep -o "release-${BRANCH}.*")
76 fi
77
78 v repo init \
79 ${MANIFEST:+-u "${MANIFEST}"} \
80 ${REPO_URL:+--repo-url="${REPO_URL}"} \
81 ${REF:+--reference "${REF}"} \
82 ${MANIFEST_NAME:+-m "${MANIFEST_NAME}"} \
83 ${RGROUPS:+-g "${RGROUPS[*]}"} \
84 ${BRANCH:+-b "${BRANCH}"}
85
86 rdir=$(realpath "`pwd`")
87 while [[ ! -d ${rdir}/.repo ]] ; do
88 rdir=${rdir%/*}
89 [[ ${rdir:-/} == "/" ]] && break
90 done
91 rdir+="/.repo"
92 if [[ -d ${rdir} ]] ; then
93 gcfg() { git --git-dir="$1" config user.email "${@:2}" ; }
94 if [[ $(gcfg "${rdir}/manifests.git") != "${email}" ]] ; then
95 echo "${rdir}: setting e-mail to ${email}"
96 find "${rdir}" -type d -name '*.git' | \
97 while read d ; do
98 gcfg "${d}" ${email}
99 done
100 fi
101 fi
102
103 exit 0