diff --git a/git-lkgr b/git-lkgr index e0c7a332e..caba12e8c 100755 --- a/git-lkgr +++ b/git-lkgr @@ -4,6 +4,24 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +force_branch=no +quiet=no + +while [ $# -gt 0 ]; do + case "$1" in + --force-branch) + force_branch=yes + ;; + -q|--quiet) + quiet=yes + ;; + *) + echo "Unknown option: $1" + ;; + esac + shift +done + svn_lkgr=`curl -s http://chromium-status.appspot.com/lkgr` if [ $? != 0 -o -z "$svn_lkgr" ]; then echo 'Could not get svn lkgr from chromium-status.appspot.com/lkgr' @@ -52,13 +70,82 @@ EOF exit 1 fi +# Pick a name for the new branch. Use `git rev-parse` to make sure the branch +# doesn't already exist; if it does, iterate an integer suffix to uniquify it. +lkgr_branch="git_lkgr_r${svn_lkgr}" +digit=1 +git rev-parse --verify -q "${lkgr_branch}" >/dev/null +while [ $? -eq 0 ]; do + lkgr_branch="git_lkgr_r${svn_lkgr}_${digit}" + digit=`expr $digit + 1` + git rev-parse --verify -q "${lkgr_branch}" >/dev/null +done + if [ "${closest_svn_commit}" = "${git_lkgr}" ]; then echo "${closest_commit}" + if [ "$force_branch" = "yes" ]; then + git checkout -b "${lkgr_branch}" "${closest_commit}" + fi exit 0 -else - cat <&2 +elif [ "${quiet}" = "yes" ]; then + exit 1 +elif [ "${force_branch}" = "no" ]; then + cat <