]> git.wh0rd.org - home.git/blobdiff - .bin/r
r: ignore Fast-forwarded lines
[home.git] / .bin / r
diff --git a/.bin/r b/.bin/r
index cc26b7b6af132286f6c04589e47ddc7979ae971f..641ed64216f64361682698934e69d155acb561f4 100755 (executable)
--- a/.bin/r
+++ b/.bin/r
@@ -17,6 +17,11 @@ s)
        cmd=sync
        shift
        ;;
+rb-all)
+       cmd=rebase
+       shift
+       set -- all "$@"
+       ;;
 *)
        cmd=$1
        shift
@@ -54,7 +59,7 @@ mj_finish() {
 
 repo_root() {
        local root=${PWD}
-       while [[ ! -d ${root}/.repo && ${root} != "/" ]] ; do
+       while [[ ! -d ${root}/.repo && ${root:-/} != "/" ]] ; do
                root=${root%/*}
        done
        echo "${root}"
@@ -87,6 +92,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
@@ -106,14 +151,18 @@ rebase)
                                out=$(env _proj=${proj} r rb all . 2>&1)
                                if [[ -n ${out} ]] ; then
                                        while read line ; do
-                                               if [[ ${line} == "# "* ]] ; then
+                                               case ${line} in
+                                               "Fast-forwarded "*) ;;
+                                               "# "*)
                                                        line="${line#[#] }"
                                                        printf '%s### %s%-40s%s: %s\n' \
                                                                "${BRACKET}" "${GOOD}" "${line%%:*}" "${NORMAL}" "${line#*:}"
-                                               else
+                                                       ;;
+                                               *)
                                                        printf '%s### %s%-40s%s: ERROR: %s\n' \
                                                                "${BRACKET}" "${BAD}" "${dir}" "${NORMAL}" "${line}"
-                                               fi
+                                                       ;;
+                                               esac
                                        done < <(echo "${out}")
                                fi
                                _mj_child
@@ -302,9 +351,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 repo ${acmd:-${cmd}} "$@"
+exec python2 $(find_repo) ${acmd:-${cmd}} "$@"