]> git.wh0rd.org Git - home.git/commitdiff
repo: make `repo` search more flexible
authorMike Frysinger <vapier@gentoo.org>
Tue, 7 Feb 2017 17:12:34 +0000 (12:12 -0500)
committerMike Frysinger <vapier@gentoo.org>
Tue, 7 Feb 2017 17:12:34 +0000 (12:12 -0500)
.bin/r

diff --git a/.bin/r b/.bin/r
index 22628b4211e0c29c995befac6fbedd0cf02a6ac4..24fc5e4090645fdbb32d926cbfecef8fa8544e90 100755 (executable)
--- a/.bin/r
+++ b/.bin/r
@@ -87,6 +87,46 @@ process_reviewers() {
        reviewers=${reviewers%,}
 }
 
+find_repo() {
+       # Diff projects have diff versions of repo.  Find a compatible one.
+       local root=$(repo_root)
+
+       # Use the manifest repo URL.
+       local manifest_dir="${root}/.repo/manifests.git"
+       local d
+
+       # Default to the local repo if it's there.
+       local search=(
+               "${root}/.repo/repo"
+       )
+
+       case $(g --git-dir="${manifest_dir}" config remote.origin.url) in
+       *android*)
+               search+=(
+                       /usr/local/src/repo
+                       ~/src/repo
+               )
+               ;;
+       *chromium*|*chrome*)
+               search+=(
+                       ~/depot_tools
+                       ~/chromiumos/depot_tools
+                       /usr/local/src/depot_tools
+                       ~/src/depot_tools
+               )
+               ;;
+       esac
+       for d in "${search[@]}" ; do
+               if [[ -x ${d}/repo ]] ; then
+                       echo "${d}"/repo
+                       return
+               fi
+       done
+
+       # Fallback: use $PATH.
+       type -P repo
+}
+
 case ${acmd:-${cmd}} in
 rebase)
        if [[ $1 == "all" ]] ; then
@@ -302,9 +342,14 @@ upload)
        ;;
 email)
        email=${1:-${USER}@chromium.org}
+
+       root=$(repo_root)
+       git --git-dir="${root}/.repo/manifests.git" cfg user.email "${email}"
+       git --git-dir="${root}/.repo/repo/.git" cfg user.email "${email}"
+
        cmd='forall'
-       set -- -c "git cfg user.email ${email}"
+       set -- -c "git cfg user.email '${email}'"
        ;;
 esac
 
-exec python2 $(type -P repo) ${acmd:-${cmd}} "$@"
+exec python2 $(find_repo) ${acmd:-${cmd}} "$@"