Merge "Support branches with name 'config'"
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java
index 153f7b7..a602f7c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java
@@ -360,6 +360,19 @@ public void testGetRefs_InvalidName() throws IOException {
 	}
 
 	@Test
+	public void testReadNotExistingBranchConfig() throws IOException {
+		assertNull("find branch config", refdir.getRef("config"));
+		assertNull("find branch config", refdir.getRef("refs/heads/config"));
+	}
+
+	@Test
+	public void testReadBranchConfig() throws IOException {
+		writeLooseRef("refs/heads/config", A);
+
+		assertNotNull("find branch config", refdir.getRef("config"));
+	}
+
+	@Test
 	public void testGetRefs_HeadsOnly_AllLoose() throws IOException {
 		Map<String, Ref> heads;
 		Ref a, b;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java
index 3d082fb..6ae3f8c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java
@@ -73,6 +73,7 @@
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.eclipse.jgit.errors.InvalidObjectIdException;
 import org.eclipse.jgit.errors.LockFailedException;
 import org.eclipse.jgit.errors.MissingObjectException;
 import org.eclipse.jgit.errors.ObjectWritingException;
@@ -260,10 +261,17 @@ public Ref getRef(final String needle) throws IOException {
 		final RefList<Ref> packed = getPackedRefs();
 		Ref ref = null;
 		for (String prefix : SEARCH_PATH) {
-			ref = readRef(prefix + needle, packed);
-			if (ref != null) {
-				ref = resolve(ref, 0, null, null, packed);
-				break;
+			try {
+				ref = readRef(prefix + needle, packed);
+				if (ref != null) {
+					ref = resolve(ref, 0, null, null, packed);
+					break;
+				}
+			} catch (IOException e) {
+				if (!(!needle.contains("/") && "".equals(prefix) && e
+						.getCause() instanceof InvalidObjectIdException)) {
+					throw e;
+				}
 			}
 		}
 		fireRefsChanged();
@@ -937,7 +945,11 @@ private LooseRef scanRef(LooseRef ref, String name) throws IOException {
 			while (0 < n && Character.isWhitespace(buf[n - 1]))
 				n--;
 			String content = RawParseUtils.decode(buf, 0, n);
-			throw new IOException(MessageFormat.format(JGitText.get().notARef, name, content));
+
+			IOException ioException = new IOException(MessageFormat.format(JGitText.get().notARef,
+					name, content));
+			ioException.initCause(notRef);
+			throw ioException;
 		}
 		return new LooseUnpeeled(otherSnapshot, name, id);
 	}