]> source.dussan.org Git - jgit.git/commitdiff
Support branches with name 'config' 68/7268/3
authorChristian Halstrick <christian.halstrick@sap.com>
Tue, 21 Aug 2012 13:10:02 +0000 (15:10 +0200)
committerStefan Lay <stefan.lay@sap.com>
Tue, 21 Aug 2012 13:10:02 +0000 (15:10 +0200)
JGit was not able to lookup refs which had the name of files which exist
in the .git folder. When JGit was looking up a ref named X it has a
fixed set of directories where it searched for files named X
(ignore packed refs for now). First directory to search for is .git. In
case of the ref named 'config' it searched there for this file, found it
(it's the .git/config file with the repo configuration in it), parsed
it, found it is an invalid ref and stopped searching. It never looked
for a file .git/refs/heads/config.

I changed JGit in a way that when it finds a file in GIT_DIR which
corresponds to a ref name and if this file doesn't contain a valid ref
then it will ignore the InvalidObjectIdException and continue searching.

Change-Id: Ic26a329fb1624a5b2b2494c78bac4bd76817c100
Bug: 381574
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java

index 153f7b791c9ac889115a2c6fb782b8ef5b05e173..a602f7c7d5c8d80ac49a45d6d2231454882e0ef1 100644 (file)
@@ -359,6 +359,19 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
                assertTrue("empty objects/", refdir.getRefs("objects/").isEmpty());
        }
 
+       @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;
index 3d082fb4af1b55f42476be0d3b9a11df6c4a6b98..6ae3f8cc8b89115dfc56d0e699fca253a652e8ca 100644 (file)
@@ -73,6 +73,7 @@ import java.util.Map;
 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 class RefDirectory extends RefDatabase {
                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 @@ public class RefDirectory extends RefDatabase {
                        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);
        }