BUILD: scripts: make publish-release support bare repositories

First we must not report an error when "git diff HEAD" fails. Second, we
don't want to "cd" to the home dir when "git rev-parse --show-toplevel"
returns an empty string. Third, we definitely want to check that a master
branch really exists in the current directory to avoid mistakes.
diff --git a/scripts/publish-release b/scripts/publish-release
index d8f7661..8a1645e 100755
--- a/scripts/publish-release
+++ b/scripts/publish-release
@@ -64,13 +64,21 @@
 fi
 
 # we want to go to the git top dir
-cd $(git rev-parse --show-toplevel)
+toplvl=$(git rev-parse --show-toplevel)
+if [ -n "$toplvl" ]; then
+	cd "$toplvl"
+fi
+
+# ensure that a master branch exists here
+if [ -z "$(git rev-parse --verify -q master 2>/dev/null)" ]; then
+	die "Current directory doesn't seem to be a valid git directory (no master branch)."
+fi
 
 if [ "$(git rev-parse --verify -q HEAD)" != "$(git rev-parse --verify -q master)" ]; then
 	die "git HEAD doesn't match master branch."
 fi
 
-if [ "$(git diff HEAD|wc -c)" != 0 ]; then
+if [ "$(git diff HEAD 2>/dev/null |wc -c)" != 0 ]; then
 	err "You appear to have uncommitted local changes, please commit them first :"
 	git status -s -uno >&2
 	die