X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-checkout.sh;h=119bca1ffbfb8fb0dae404a8e7389f577aebc42c;hb=bd45fec8397f1f0804db1d18af7193be323b0326;hp=564117f0064aba32e190a49106eaecfdb422b31e;hpb=5ff6a3269085c5cd425bad9f470d421a8d62f338;p=git.git diff --git a/git-checkout.sh b/git-checkout.sh index 564117f00..119bca1ff 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -4,8 +4,8 @@ USAGE='[-f] [-b ] [-m] [] [...]' SUBDIRECTORY_OK=Sometimes . git-sh-setup -old=$(git-rev-parse HEAD) old_name=HEAD +old=$(git-rev-parse --verify $old_name 2>/dev/null) new= new_name= force= @@ -22,7 +22,7 @@ while [ "$#" != "0" ]; do shift [ -z "$newbranch" ] && die "git checkout: -b needs a branch name" - [ -e "$GIT_DIR/refs/heads/$newbranch" ] && + git-show-ref --verify --quiet -- "refs/heads/$newbranch" && die "git checkout: branch $newbranch already exists" git-check-ref-format "heads/$newbranch" || die "git checkout: we do not like '$newbranch' as a branch name." @@ -51,7 +51,8 @@ while [ "$#" != "0" ]; do fi new="$rev" new_name="$arg^0" - if [ -f "$GIT_DIR/refs/heads/$arg" ]; then + if git-show-ref --verify --quiet -- "refs/heads/$arg" + then branch="$arg" fi elif rev=$(git-rev-parse --verify "$arg^{tree}" 2>/dev/null) @@ -67,6 +68,10 @@ while [ "$#" != "0" ]; do set x "$arg" "$@" shift fi + case "$1" in + --) + shift ;; + esac break ;; esac @@ -135,10 +140,16 @@ fi die "git checkout: to checkout the requested commit you need to specify a name for a new branch which is created and switched to" +if [ "X$old" = X ] +then + echo "warning: You do not appear to currently be on a branch." >&2 + echo "warning: Forcing checkout of $new_name." >&2 + force=1 +fi + if [ "$force" ] then - git-read-tree --reset $new && - git-checkout-index -q -f -u -a + git-read-tree --reset -u $new else git-update-index --refresh >/dev/null merge_error=$(git-read-tree -m -u $old $new 2>&1) || ( @@ -151,8 +162,7 @@ else # Match the index to the working tree, and do a three-way. git diff-files --name-only | git update-index --remove --stdin && work=`git write-tree` && - git read-tree --reset $new && - git checkout-index -f -u -q -a && + git read-tree --reset -u $new && git read-tree -m -u --aggressive $old $new $work || exit if result=`git write-tree 2>/dev/null`