]> git.wh0rd.org - home.git/blobdiff - .bin/cros-repo
test.cc: new C++ test
[home.git] / .bin / cros-repo
index 6f51357dca675a3a7fbd499479220d630a2a0e79..8f8765ba23817979678c1945a27ed06f80d52664 100755 (executable)
-#!/bin/sh
+#!/bin/bash
 
 usage() {
        cat <<-EOF
-       Usage: repo-cros [dir] <command> [command opts]
+       Usage: repo-cros [options]
 
-       Commands:
+       Options:
+          depot_tools    clone depot_tools tree
           int            switch to internal tree
           ext            switch to external tree
-          -b <branch>    switch branches
+          -b <branch>    switch branches (use "master" to get to ToT)
+          -r <path>      patch to reference repo (e.g. ~/chromiumos/)
+          -g <group>
+          -m <manifest>
+          -e <email>
+
+       Operates on the repo in ${PWD}
        EOF
        exit ${1:-1}
 }
-[[ $# -eq 0 ]] && usage
 
-vexec() {
-       cd ${DIR:-~/chromiumos}
+v() {
        printf '%s\n%s\n' "${PWD}" "$*"
-       exec "$@"
+       "$@"
 }
 
-DIR=
+email="vapier@chromium.org"
+REF=
+BRANCH=
+MANIFEST=
+MANIFEST_NAME=
+RGROUPS=()
+REPO_URL=
 while [[ $# -gt 0 ]] ; do
        case $1 in
-       int) vexec repo init -u ssh://gerrit-int.chromium.org:29419/chromeos/manifest-internal.git --repo-url='http://git.chromium.org/external/repo.git' ;;
-       ext) vexec repo init -u http://git.chromium.org/chromiumos/manifest.git --repo-url http://git.chromium.org/external/repo.git ;;
-       -b)  vexec repo init -b $2 ;;
+       depot_tools|dt)
+               exec git clone https://git.chromium.org/chromium/tools/depot_tools.git
+               ;;
+       int)
+               MANIFEST='https://chrome-internal.googlesource.com/chromeos/manifest-internal.git'
+               REPO_URL='https://chromium.googlesource.com/external/repo.git'
+               ;;
+       ext)
+               MANIFEST='https://chromium.googlesource.com/chromiumos/manifest.git'
+               REPO_URL='https://chromium.googlesource.com/external/repo.git'
+               ;;
+       -b)
+               BRANCH=$2
+               shift
+               ;;
+       -r)
+               REF=$(realpath "${2:-$(echo ~/chromiumos)}")
+               shift
+               ;;
+       -g)
+               RGROUPS+=( "$2" )
+               shift
+               ;;
+       -m)
+               MANIFEST_NAME="${2%.xml}.xml"
+               shift
+               ;;
+       -e)
+               email=$2
+               shift
+               ;;
        *)
-               if [[ -z ${DIR} ]] ; then
-                       DIR=$1
-               else
-                       usage
-               fi
+               usage
                ;;
        esac
        shift
 done
+
+if [[ ${#BRANCH} -eq 3 ]] && [[ -d ${REF} ]] ; then
+       BRANCH=$(git --git-dir="${REF}/.repo/manifests.git" branch -a | grep -o "release-${BRANCH}.*")
+fi
+
+v repo init \
+       ${MANIFEST:+-u "${MANIFEST}"} \
+       ${REPO_URL:+--repo-url="${REPO_URL}"} \
+       ${REF:+--reference "${REF}"} \
+       ${MANIFEST_NAME:+-m "${MANIFEST_NAME}"} \
+       ${RGROUPS:+-g "${RGROUPS[*]}"} \
+       ${BRANCH:+-b "${BRANCH}"}
+
+rdir=$(realpath "`pwd`")
+while [[ ! -d ${rdir}/.repo ]] ; do
+       rdir=${rdir%/*}
+       [[ ${rdir:-/} == "/" ]] && break
+done
+rdir+="/.repo"
+if [[ -d ${rdir} ]] ; then
+       gcfg() { git --git-dir="$1" config user.email "${@:2}" ; }
+       if [[ $(gcfg "${rdir}/manifests.git") != "${email}" ]] ; then
+               echo "${rdir}: setting e-mail to ${email}"
+               find "${rdir}" -type d -name '*.git' | \
+               while read d ; do
+                       gcfg "${d}" ${email}
+               done
+       fi
+fi
+
 exit 0