X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-checkout.sh;h=92ec069a3acacc2d12c2c709311969f3d0aa4153;hb=6900679c2f6d937a5a6ef616869c8887690ad19d;hp=dd477245fb3703402b950cbc1378b35ce379d631;hpb=99692dc213482116f237ea58965b0ceef3827147;p=git.git diff --git a/git-checkout.sh b/git-checkout.sh index dd477245f..92ec069a3 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -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) @@ -76,6 +77,11 @@ while [ "$#" != "0" ]; do esac done +case "$force$merge" in +11) + die "git checkout: -f and -m are incompatible" +esac + # The behaviour of the command with and without explicit path # parameters is quite different. # @@ -106,7 +112,11 @@ Did you intend to checkout '$@' which can not be resolved as commit?" git-ls-tree --full-name -r "$new" "$@" | git-update-index --index-info || exit $? fi - git-checkout-index -f -u -- "$@" + + # Make sure the request is about existing paths. + git-ls-files --error-unmatch -- "$@" >/dev/null || exit + git-ls-files -- "$@" | + git-checkout-index -f -u --stdin exit $? else # Make sure we did not fall back on $arg^{tree} codepath @@ -136,8 +146,11 @@ fi [ -z "$branch$newbranch" ] && [ "$new" != "$old" ] && - die "git checkout: to checkout the requested commit you need to specify - a name for a new branch which is created and switched to" + die "git checkout: provided reference cannot be checked out directly + + You need -b to associate a new branch with the wanted checkout. Example: + git checkout -b $arg +" if [ "X$old" = X ] then @@ -151,7 +164,7 @@ then git-read-tree --reset -u $new else git-update-index --refresh >/dev/null - merge_error=$(git-read-tree -m -u $old $new 2>&1) || ( + merge_error=$(git-read-tree -m -u --exclude-per-directory=.gitignore $old $new 2>&1) || ( case "$merge" in '') echo >&2 "$merge_error" @@ -162,7 +175,8 @@ else git diff-files --name-only | git update-index --remove --stdin && work=`git write-tree` && git read-tree --reset -u $new && - git read-tree -m -u --aggressive $old $new $work || exit + git read-tree -m -u --aggressive --exclude-per-directory=.gitignore $old $new $work || + exit if result=`git write-tree 2>/dev/null` then