]> git.wh0rd.org Git - home.git/blob - .bin/cros-repo
c03020b35725f139e0835e183a27ca53e323594d
[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 v() {
19         printf '%s\n%s\n' "${PWD}" "$*"
20         "$@"
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='https://git.chromium.org/git/external/repo.git'
33                 ;;
34         ext)
35                 MANIFEST='https://git.chromium.org/git/chromiumos/manifest.git'
36                 REPO_URL='https://git.chromium.org/git/external/repo.git'
37                 ;;
38         -b)
39                 BRANCH=$2
40                 shift
41                 ;;
42         -r)
43
44                 REF=$(realpath "${2:-$(echo ~/chromiumos)}")
45                 shift
46                 ;;
47         *)
48                 usage
49                 ;;
50         esac
51         shift
52 done
53
54 if [[ ${#BRANCH} -eq 3 ]] && [[ -d ${REF} ]] ; then
55         BRANCH=$(git --git-dir="${REF}/.repo/manifests.git" branch -a | grep -o "release-${BRANCH}.*")
56 fi
57
58 v repo init \
59         ${MANIFEST:+-u "${MANIFEST}"} \
60         ${REPO_URL:+--repo-url="${REPO_URL}"} \
61         ${REF:+--reference "${REF}"} \
62         ${BRANCH:+-b "${BRANCH}"}
63
64 rdir=$(realpath "`pwd`")
65 while [[ ! -d ${rdir}/.repo ]] ; do
66         rdir=${rdir%/*}
67         [[ ${rdir:-/} == "/" ]] && break
68 done
69 rdir+="/.repo"
70 if [[ -d ${rdir} ]] ; then
71         gcfg() { git --git-dir="$1" config user.email "${@:2}" ; }
72         if [[ $(gcfg "${rdir}/manifests.git") != "${email}" ]] ; then
73                 echo "${rdir}: setting e-mail to ${email}"
74                 find "${rdir}" -type d -name '*.git' | \
75                 while read d ; do
76                         gcfg "${d}" ${email}
77                 done
78         fi
79 fi
80
81 exit 0