make git_prompt_info aware of detached HEAD

This reopens an earlier pull requests (#1063), now rebased onto the master branch.

This patch updates the git_prompt_info function to first look at whether or not the repository is in a detached HEAD state and, if so, to attempt to determine if a tag is currently checked out.  This means that instead of getting something potentially less useful, like `HEAD~17` you can get something like `remotes/origin/v1.2.3`.

The rebaase was pretty clean, so I am confident this is working as well as before.  I would still really love to see this in upstream, so I can stop rebasing it every few months! :)  Thanks!