]> git.wh0rd.org - home.git/blobdiff - .bin/cros-repo
gitignore: update
[home.git] / .bin / cros-repo
index d6c6de1bea169a09d59169eb2cd3b224a1d09561..8f8765ba23817979678c1945a27ed06f80d52664 100755 (executable)
-#!/bin/sh
-cd ~/chromiumos
+#!/bin/bash
 
 usage() {
        cat <<-EOF
-       Usage: repo-cros <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() { echo "$@"; exec "$@"; }
+v() {
+       printf '%s\n%s\n' "${PWD}" "$*"
+       "$@"
+}
 
+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 ;;
-       *) usage ;;
+       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
+               ;;
+       *)
+               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