Detect the current environment without using the upstream.

Developers should have the freedom to set other upstreams on their Git
branches.

Plus, there are other bugs e.g. issue #109 which mean that the upstream is not
set properly.
Try the remote first, and fall back to the branch name.
Merge pull request #117 from pjcdawkins/better-current-env-test

Detect the current environment without using the upstream.