Chromium Code Reviews| Index: git-lkgr |
| diff --git a/git-lkgr b/git-lkgr |
| index caba12e8c7b57ff6eef0180b27ae6c6676b952ef..492d2936624a6b8418098259d69c2c26e32b5c33 100755 |
| --- a/git-lkgr |
| +++ b/git-lkgr |
| @@ -4,19 +4,36 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| -force_branch=no |
| +branch_name="" |
| +checkout_branch=no |
| +create_branch=no |
| quiet=no |
| while [ $# -gt 0 ]; do |
| case "$1" in |
| - --force-branch) |
| - force_branch=yes |
| + --checkout|--force-branch) |
| + checkout_branch=yes |
| + ;; |
| + --create) |
| + create_branch=yes |
| + ;; |
| + -n|--name) |
| + branch_name=$2 |
| + create_branch=yes |
| + shift |
| ;; |
| -q|--quiet) |
| quiet=yes |
| ;; |
| *) |
| echo "Unknown option: $1" |
| + echo "Usage:" |
| + echo " --checkout Create a branch and check it out." |
| + echo " --create Create a branch." |
| + echo " -n, --name <name> Specify the name of branch to create or reset." |
| + echo " This will force the branch using 'git branch -f '." |
| + echo " -q, --quiet Quiet." |
| + exit 1 |
| ;; |
| esac |
| shift |
| @@ -70,26 +87,41 @@ 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` |
| +if [ "${branch_name}" != "" ]; then |
| + lkgr_branch="${branch_name}" |
| +else |
| + # 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="lkgr_r${svn_lkgr}" |
| + digit=1 |
| git rev-parse --verify -q "${lkgr_branch}" >/dev/null |
| -done |
| + while [ $? -eq 0 ]; do |
| + lkgr_branch="lkgr_r${svn_lkgr}_${digit}" |
| + digit=`expr $digit + 1` |
| + git rev-parse --verify -q "${lkgr_branch}" >/dev/null |
| + done |
| +fi |
| if [ "${closest_svn_commit}" = "${git_lkgr}" ]; then |
| echo "${closest_commit}" |
| - if [ "$force_branch" = "yes" ]; then |
| - git checkout -b "${lkgr_branch}" "${closest_commit}" |
| + if [ "$create_branch" = "yes" ] || [ "$checkout_branch" = "yes" ]; then |
| + # If the branch exists, update it, else create it |
| + git rev-parse --verify -q "${lkgr_branch}" >/dev/null |
| + if [ $? -eq 0 ]; then |
| + git branch -f "${lkgr_branch}" "${closest_commit}" |
| + echo "Updated branch ${lkgr_branch}" |
| + else |
| + git branch "${lkgr_branch}" "${closest_commit}" |
| + echo "Created branch ${lkgr_branch}" |
| + fi |
| + fi |
| + if [ "$checkout_branch" = "yes" ]; then |
| + git checkout "${lkgr_branch}" |
| fi |
| exit 0 |
| elif [ "${quiet}" = "yes" ]; then |
| exit 1 |
| -elif [ "${force_branch}" = "no" ]; then |
| +elif [ "${checkout_branch}" = "no" ]; then |
|
szager1
2013/01/16 00:46:05
elif [ "${checkout_branch}" = "no" -a "${create_br
scheib
2013/01/16 21:26:56
Done by asking the user to use --checkout if they
|
| cat <<EOF |
| There is no master commit which corresponds exactly to lkgr. |
| The closest commit is ${closest_commit}. |