]> git.wh0rd.org Git - home.git/commitdiff
add reference support, and initialize e-mail
authorMike Frysinger <vapier@gentoo.org>
Sat, 9 Jun 2012 02:54:36 +0000 (22:54 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sat, 9 Jun 2012 02:58:43 +0000 (22:58 -0400)
.bin/cros-repo

index 6f51357dca675a3a7fbd499479220d630a2a0e79..3da6b5cdcecbfb752f1292074ff2d4c114732a5e 100755 (executable)
@@ -2,37 +2,74 @@
 
 usage() {
        cat <<-EOF
-       Usage: repo-cros [dir] <command> [command opts]
+       Usage: repo-cros [options]
 
-       Commands:
+       Options:
           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/)
+
+       Operates on the repo in ${PWD}
        EOF
        exit ${1:-1}
 }
-[[ $# -eq 0 ]] && usage
 
 vexec() {
-       cd ${DIR:-~/chromiumos}
        printf '%s\n%s\n' "${PWD}" "$*"
        exec "$@"
 }
 
-DIR=
+email="vapier@chromium.org"
+REF=
+BRANCH=
+MANIFEST=
+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 ;;
+       int)
+               MANIFEST='ssh://gerrit-int.chromium.org:29419/chromeos/manifest-internal.git'
+               REPO_URL='http://git.chromium.org/external/repo.git'
+               ;;
+       ext)
+               MANIFEST='http://git.chromium.org/chromiumos/manifest.git'
+               REPO_URL='http://git.chromium.org/external/repo.git'
+               ;;
+       -b)
+               BRANCH=$2
+               shift
+               ;;
+       -r)
+               REF=$(realpath "$2")
+               shift
+               ;;
        *)
-               if [[ -z ${DIR} ]] ; then
-                       DIR=$1
-               else
-                       usage
-               fi
+               usage
                ;;
        esac
        shift
 done
-exit 0
+
+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
+
+vexec \
+       repo init \
+       ${MANIFEST:+-u "${MANIFEST}"} \
+       ${REPO_URL:+--repo-url="${REPO_URL}"} \
+       ${REF:+--reference "${REF}"} \
+       ${BRANCH:+-b "${BRANCH}"}