X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-checkout.sh;h=33f1e87c0c209b89eb785381db62d826818b602d;hb=a2f8028d3d661b314d5a784764f2f5f9e4c2dde0;hp=a7390e808c76dd5c8dab04396974ee5a709497fd;hpb=53a58245863eff3d70aaa3ac75d7d57e843fc91d;p=git.git diff --git a/git-checkout.sh b/git-checkout.sh index a7390e808..33f1e87c0 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -17,6 +17,7 @@ newbranch= newbranch_log= merge= quiet= +v=-v LF=' ' while [ "$#" != "0" ]; do @@ -47,6 +48,7 @@ while [ "$#" != "0" ]; do ;; "-q") quiet=1 + v= ;; --) break @@ -61,12 +63,13 @@ while [ "$#" != "0" ]; do echo "unknown flag $arg" exit 1 fi - new="$rev" new_name="$arg" if git-show-ref --verify --quiet -- "refs/heads/$arg" then + rev=$(git-rev-parse --verify "refs/heads/$arg^0") branch="$arg" fi + new="$rev" elif rev=$(git-rev-parse --verify "$arg^{tree}" 2>/dev/null) then # checking out selected paths from a tree-ish. @@ -170,7 +173,7 @@ describe_detached_head () { } } -if test -z "$branch$newbranch" && test "$new" != "$old" +if test -z "$branch$newbranch" && test "$new_name" != "$old_name" then detached="$new" if test -n "$oldbranch" && test -z "$quiet" @@ -180,7 +183,7 @@ If you want to create a new branch from this checkout, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b " fi -elif test -z "$oldbranch" +elif test -z "$oldbranch" && test "$new" != "$old" then describe_detached_head 'Previous HEAD position was' "$old" fi @@ -197,7 +200,7 @@ fi if [ "$force" ] then - git-read-tree --reset -u $new + git-read-tree $v --reset -u $new else git-update-index --refresh >/dev/null merge_error=$(git-read-tree -m -u --exclude-per-directory=.gitignore $old $new 2>&1) || ( @@ -208,9 +211,9 @@ else esac # Match the index to the working tree, and do a three-way. - git diff-files --name-only | git update-index --remove --stdin && + git diff-files --name-only | git update-index --remove --stdin && work=`git write-tree` && - git read-tree --reset -u $new || exit + git read-tree $v --reset -u $new || exit eval GITHEAD_$new='${new_name:-${branch:-$new}}' && eval GITHEAD_$work=local && @@ -221,7 +224,7 @@ else # this is not a real merge before committing, but just carrying # the working tree changes along. unmerged=`git ls-files -u` - git read-tree --reset $new + git read-tree $v --reset $new case "$unmerged" in '') ;; *) @@ -243,7 +246,7 @@ else (exit $saved_err) fi -# +# # Switch the HEAD pointer to the new branch if we # checked out a branch head, and remove any potential # old MERGE_HEAD's (subsequent commits will clearly not @@ -268,15 +271,7 @@ if [ "$?" -eq 0 ]; then fi elif test -n "$detached" then - # NEEDSWORK: we would want a command to detach the HEAD - # atomically, instead of this handcrafted command sequence. - # Perhaps: - # git update-ref --detach HEAD $new - # or something like that... - # - git-rev-parse HEAD >"$GIT_DIR/HEAD.new" && - mv "$GIT_DIR/HEAD.new" "$GIT_DIR/HEAD" && - git-update-ref -m "checkout: moving to $arg" HEAD "$detached" || + git-update-ref --no-deref -m "checkout: moving to $arg" HEAD "$detached" || die "Cannot detach HEAD" if test -n "$detach_warn" then