]> git.wh0rd.org - home.git/blob - .bin/cros-repo
cros-repo: add depot_tools helper
[home.git] / .bin / cros-repo
1 #!/bin/sh
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
14 Operates on the repo in ${PWD}
15 EOF
16 exit ${1:-1}
17 }
18
19 v() {
20 printf '%s\n%s\n' "${PWD}" "$*"
21 "$@"
22 }
23
24 email="vapier@chromium.org"
25 REF=
26 BRANCH=
27 MANIFEST=
28 REPO_URL=
29 while [[ $# -gt 0 ]] ; do
30 case $1 in
31 depot_tools)
32 exec git clone https://git.chromium.org/chromium/tools/depot_tools.git
33 ;;
34 int)
35 MANIFEST='ssh://gerrit-int.chromium.org:29419/chromeos/manifest-internal.git'
36 REPO_URL='https://git.chromium.org/git/external/repo.git'
37 ;;
38 ext)
39 MANIFEST='https://git.chromium.org/git/chromiumos/manifest.git'
40 REPO_URL='https://git.chromium.org/git/external/repo.git'
41 ;;
42 -b)
43 BRANCH=$2
44 shift
45 ;;
46 -r)
47
48 REF=$(realpath "${2:-$(echo ~/chromiumos)}")
49 shift
50 ;;
51 *)
52 usage
53 ;;
54 esac
55 shift
56 done
57
58 if [[ ${#BRANCH} -eq 3 ]] && [[ -d ${REF} ]] ; then
59 BRANCH=$(git --git-dir="${REF}/.repo/manifests.git" branch -a | grep -o "release-${BRANCH}.*")
60 fi
61
62 v repo init \
63 ${MANIFEST:+-u "${MANIFEST}"} \
64 ${REPO_URL:+--repo-url="${REPO_URL}"} \
65 ${REF:+--reference "${REF}"} \
66 ${BRANCH:+-b "${BRANCH}"}
67
68 rdir=$(realpath "`pwd`")
69 while [[ ! -d ${rdir}/.repo ]] ; do
70 rdir=${rdir%/*}
71 [[ ${rdir:-/} == "/" ]] && break
72 done
73 rdir+="/.repo"
74 if [[ -d ${rdir} ]] ; then
75 gcfg() { git --git-dir="$1" config user.email "${@:2}" ; }
76 if [[ $(gcfg "${rdir}/manifests.git") != "${email}" ]] ; then
77 echo "${rdir}: setting e-mail to ${email}"
78 find "${rdir}" -type d -name '*.git' | \
79 while read d ; do
80 gcfg "${d}" ${email}
81 done
82 fi
83 fi
84
85 exit 0