diff --git a/git-checkout-script b/git-checkout-script
index a3bfae79dbf868c0a155dccb5d7b79fb3da2799e..ea7fef54ab6e1a6e04b87aa749c19ae916190d26 100755 (executable)
--- a/git-checkout-script
+++ b/git-checkout-script
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
exit 1
fi
new="$rev"
- if [ -f "$GIT_DIR/revs/heads/$arg" ]; then
+ if [ -f "$GIT_DIR/refs/heads/$arg" ]; then
branch="$arg"
fi
;;
esac
i=$(($i+1))
done
-: ${new=$old}
+[ -z "$new" ] && new=$old
if [ "$force" ]
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