From 9cb8e2f31035d265b83ba4e295aa3abb4c737ebf Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 17 Nov 2019 15:05:57 -0800 Subject: [PATCH] RepositoryCache: don't require HEAD in git repositories Reftable-enabled repositories don't have a file called HEAD. Check for reftable/ instead. This fixes repository creation on reftable in Gerrit. Signed-off-by: Han-Wen Nienhuys Change-Id: I778c2be01d96aaf135affae4b457b5fe5b483bee --- .../jgit/internal/storage/file/FileReftableTest.java | 6 ++++++ .../src/org/eclipse/jgit/lib/RepositoryCache.java | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java index e0e20fb4d..0e06d459a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java @@ -73,6 +73,7 @@ import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.lib.ReflogEntry; import org.eclipse.jgit.lib.ReflogReader; +import org.eclipse.jgit.lib.RepositoryCache; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase; import org.eclipse.jgit.transport.ReceiveCommand; @@ -507,6 +508,11 @@ public class FileReftableTest extends SampleDataRepositoryTestCase { } } + @Test + public void isGitRepository() { + assertTrue(RepositoryCache.FileKey.isGitRepository(db.getDirectory(), db.getFS())); + } + @Test public void testRenameDestExists() throws IOException { ObjectId rb = db.resolve("refs/heads/b"); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java index fa113bfc6..fc74f5324 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java @@ -476,7 +476,8 @@ public class RepositoryCache { public static boolean isGitRepository(File dir, FS fs) { return fs.resolve(dir, Constants.OBJECTS).exists() && fs.resolve(dir, "refs").exists() //$NON-NLS-1$ - && isValidHead(new File(dir, Constants.HEAD)); + && (fs.resolve(dir, Constants.REFTABLE).exists() + || isValidHead(new File(dir, Constants.HEAD))); } private static boolean isValidHead(File head) {