HTRACE-292. "htracedTool version" should display the git hash, and -Dgit.version option should be available for build (cmccabe)
diff --git a/htrace-htraced/go/gobuild.sh b/htrace-htraced/go/gobuild.sh
index 3e9b30a..de9e687 100755
--- a/htrace-htraced/go/gobuild.sh
+++ b/htrace-htraced/go/gobuild.sh
@@ -49,7 +49,7 @@
     ACTION="${1}"
     shift
 fi
-RELEASE_VERSION=${RELEASE_VERSION:-unknown}
+RELEASE_VERSION=${RELEASE_VERSION:-unknown_release}
 
 # Set up directories.  The build/ directory is where build dependencies and
 # build binaries should go.
@@ -122,10 +122,15 @@
     popd &> /dev/null
 
     # Discover the git version
-    GIT_VERSION=$(git rev-parse HEAD)
-    [ $? -eq 0 ] || GIT_VERSION="unknown"
+    if [ "x${GIT_VERSION}" == "x" ]; then
+        pushd "${SCRIPT_DIR}" &> /dev/null || die "failed to cd to ${SCRIPT_DIR}"
+        GIT_VERSION=$(git rev-parse HEAD)
+        [ $? -eq 0 ] || GIT_VERSION="unknown_git"
+        popd &> /dev/null
+    fi
 
     # Inject the release and git version into the htraced ldflags.
+    echo "Building ${RELEASE_VERSION} [${GIT_VERSION}]"
     FLAGS="-X main.RELEASE_VERSION ${RELEASE_VERSION} -X main.GIT_VERSION ${GIT_VERSION}"
     go install ${TAGS} -ldflags "${FLAGS}" -v org/apache/htrace/... "$@" \
         || die "go install failed."
diff --git a/htrace-htraced/go/src/org/apache/htrace/htracedTool/cmd.go b/htrace-htraced/go/src/org/apache/htrace/htracedTool/cmd.go
index 98b1646..04dc269 100644
--- a/htrace-htraced/go/src/org/apache/htrace/htracedTool/cmd.go
+++ b/htrace-htraced/go/src/org/apache/htrace/htracedTool/cmd.go
@@ -182,7 +182,7 @@
 
 // Print the version of the htrace binary.
 func printVersion() int {
-	fmt.Printf("Running htrace command version %s.\n", RELEASE_VERSION)
+	fmt.Printf("Running htracedTool %s [%s].\n", RELEASE_VERSION, GIT_VERSION)
 	return EXIT_SUCCESS
 }
 
diff --git a/htrace-htraced/pom.xml b/htrace-htraced/pom.xml
index 28cf929..b67af6d 100644
--- a/htrace-htraced/pom.xml
+++ b/htrace-htraced/pom.xml
@@ -28,6 +28,7 @@
 
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <git.version></git.version>
     <leveldb.prefix></leveldb.prefix>
   </properties>
   <build>
@@ -111,6 +112,7 @@
                 <exec executable="./gobuild.sh"
                       dir="${basedir}//go/"
                       failonerror="true">
+                  <env key="GIT_VERSION" value="${git.version}"/>
                   <env key="RELEASE_VERSION" value="${project.version}"/>
                   <env key="LEVELDB_PREFIX" value="${leveldb.prefix}"/>
                 </exec>