X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-checkout-script;h=ea7fef54ab6e1a6e04b87aa749c19ae916190d26;hb=5db47c2bb3b7e77fd32aeef12b6f6de8d14cb43b;hp=5b49662e623a4f68f2796458daea3875911afb68;hpb=dc14841102bb364c2be200e8456146fc8df970b9;p=git.git diff --git a/git-checkout-script b/git-checkout-script index 5b49662e6..ea7fef54a 100755 --- a/git-checkout-script +++ b/git-checkout-script @@ -12,7 +12,7 @@ while [ "$#" != "0" ]; do force=1 ;; *) - rev=$(git-rev-parse "$arg") + rev=$(git-rev-parse --verify --revs-only "$arg") if [ -z "$rev" ]; then echo "unknown flag $arg" exit 1 @@ -22,7 +22,7 @@ while [ "$#" != "0" ]; do exit 1 fi new="$rev" - if [ -f "$GIT_DIR/revs/heads/$arg" ]; then + if [ -f "$GIT_DIR/refs/heads/$arg" ]; then branch="$arg" fi ;; @@ -37,4 +37,15 @@ then git-checkout-cache -q -f -u -a else git-read-tree -m -u $old $new -fi && [ "$branch" ] && ln -sf "refs/heads/$branch" "$GIT_DIR/HEAD" +fi + +# +# Switch the HEAD pointer to the new branch if it we +# checked out a branch head, and remove any potential +# old MERGE_HEAD's (subsequent commits will clearly not +# be based on them, since we re-set the index) +# +if [ "$?" -eq 0 ]; then + [ "$branch" ] && ln -sf "refs/heads/$branch" "$GIT_DIR/HEAD" + rm -f "$GIT_DIR/MERGE_HEAD" +fi