From 6a0cd93cf5983e8ab33c62093985de847e9d3358 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 4 Apr 2010 10:25:58 -0700 Subject: [PATCH] fix rev-parse when not on a local branch --- .../src/org/hyperic/jni/ArchNameTask.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bindings/java/hyperic_jni/src/org/hyperic/jni/ArchNameTask.java b/bindings/java/hyperic_jni/src/org/hyperic/jni/ArchNameTask.java index 4bbf2a65..5a991b99 100644 --- a/bindings/java/hyperic_jni/src/org/hyperic/jni/ArchNameTask.java +++ b/bindings/java/hyperic_jni/src/org/hyperic/jni/ArchNameTask.java @@ -177,8 +177,18 @@ public class ArchNameTask extends Task { String head = readLine(git + "/HEAD"); if (head != null) { - String ref = head.substring(5).trim(); //'ref: ' - return readLine(git + "/" + ref).substring(0, 7); + String sha1; + final String refp = "ref: "; + if (head.startsWith(refp)) { + //branch + String ref = head.substring(refp.length()).trim(); + sha1 = readLine(git + "/" + ref); + } + else { + //git checkout -f origin/branch-name (no branch) + sha1 = head; + } + return sha1.substring(0, 7); } } return null;