diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2015-11-14 00:59:36 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2015-11-14 00:59:36 +0100 |
commit | 070bf8d15f8659cb5f6a039b070b19909dd2f49f (patch) | |
tree | c735873ac272bdf4c9e55b754bd79d92b1400f15 | |
parent | 26451406782245ac6ee4cc976cf9d74ce6292592 (diff) | |
parent | 3e2aff196e4f20183c13fd0c219101b6604477e8 (diff) | |
download | jgit-070bf8d15f8659cb5f6a039b070b19909dd2f49f.tar.gz jgit-070bf8d15f8659cb5f6a039b070b19909dd2f49f.zip |
Merge branch 'stable-4.1'
* stable-4.1:
Prepare 4.1.2-SNAPSHOT builds
JGit v4.1.1.201511131810-r
Fallback exactRef: Do not ignore symrefs to unborn branch
RefDirectory.exactRef: Do not ignore symrefs to unborn branch
Change-Id: I66afb303f355aad8a7eaa7a6dff06de70ae9c490
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
3 files changed, 47 insertions, 13 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java index 0991598920..d66753da08 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java @@ -1025,6 +1025,25 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase { } @Test + public void testExactRef_EmptyDatabase() throws IOException { + Ref r; + + r = refdir.exactRef(HEAD); + assertTrue(r.isSymbolic()); + assertSame(LOOSE, r.getStorage()); + assertEquals("refs/heads/master", r.getTarget().getName()); + assertSame(NEW, r.getTarget().getStorage()); + assertNull(r.getTarget().getObjectId()); + + assertNull(refdir.exactRef("refs/heads/master")); + assertNull(refdir.exactRef("refs/tags/v1.0")); + assertNull(refdir.exactRef("FETCH_HEAD")); + assertNull(refdir.exactRef("NOT.A.REF.NAME")); + assertNull(refdir.exactRef("master")); + assertNull(refdir.exactRef("v1.0")); + } + + @Test public void testGetRef_FetchHead() throws IOException { // This is an odd special case where we need to make sure we read // exactly the first 40 bytes of the file and nothing further on diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index 731bbd3839..7851678a88 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -262,6 +262,30 @@ public class RefDirectory extends RefDatabase { } @Override + public Ref exactRef(String name) throws IOException { + RefList<Ref> packed = getPackedRefs(); + Ref ref; + try { + ref = readRef(name, packed); + if (ref != null) { + ref = resolve(ref, 0, null, null, packed); + } + } catch (IOException e) { + if (name.contains("/") //$NON-NLS-1$ + || !(e.getCause() instanceof InvalidObjectIdException)) { + throw e; + } + + // While looking for a ref outside of refs/ (e.g., 'config'), we + // found a non-ref file (e.g., a config file) instead. Treat this + // as a ref-not-found condition. + ref = null; + } + fireRefsChanged(); + return ref; + } + + @Override public Ref getRef(final String needle) throws IOException { final RefList<Ref> packed = getPackedRefs(); Ref ref = null; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java index ef22fb90fe..b62033cbd2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java @@ -239,20 +239,11 @@ public abstract class RefDatabase { * @since 4.1 */ public Ref exactRef(String name) throws IOException { - int slash = name.lastIndexOf('/'); - String prefix = name.substring(0, slash + 1); - String rest = name.substring(slash + 1); - Ref result = getRefs(prefix).get(rest); - if (result != null || slash != -1) { - return result; + Ref ref = getRef(name); + if (ref == null || !name.equals(ref.getName())) { + return null; } - - for (Ref ref : getAdditionalRefs()) { - if (name.equals(ref.getName())) { - return ref; - } - } - return null; + return ref; } /** |