@Before public void setUp() throws Exception { super.setUp(); final TestRepository<FileRepository> src = createTestRepository(); final String srcName = src.getRepository().getDirectory().getName(); ServletContextHandler app = server.addContext("/git"); GitServlet gs = new GitServlet(); gs.setRepositoryResolver( new RepositoryResolver<HttpServletRequest>() { public Repository open(HttpServletRequest req, String name) throws RepositoryNotFoundException, ServiceNotEnabledException { if (!name.equals(srcName)) throw new RepositoryNotFoundException(name); final Repository db = src.getRepository(); db.incrementOpen(); return db; } }); app.addServlet(new ServletHolder(gs), "/*"); server.setUp(); remoteRepository = src.getRepository(); remoteURI = toURIish(app, srcName); FileBasedConfig cfg = remoteRepository.getConfig(); cfg.setBoolean("http", null, "receivepack", true); cfg.save(); a_blob = src.blob("a"); }
@Test public void dontPackHEAD_bare() throws Exception { BranchBuilder bb = tr.branch("refs/heads/side"); bb.commit().add("A", "A").add("B", "B").create(); RevCommit second = bb.commit().add("A", "A2").add("B", "B2").create(); // Convert the repo to be bare FileBasedConfig cfg = repo.getConfig(); cfg.setBoolean( ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_BARE, true); cfg.save(); Git git = Git.open(repo.getDirectory()); repo = (FileRepository) git.getRepository(); // check for the unborn branch master. HEAD should point to master and // master doesn't exist. assertEquals(repo.exactRef("HEAD").getTarget().getName(), "refs/heads/master"); assertNull(repo.exactRef("HEAD").getTarget().getObjectId()); gc.packRefs(); assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE); assertEquals(repo.exactRef("HEAD").getTarget().getName(), "refs/heads/master"); assertNull(repo.exactRef("HEAD").getTarget().getObjectId()); // check for non-detached HEAD repo.updateRef(Constants.HEAD).link("refs/heads/side"); gc.packRefs(); assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE); assertEquals(repo.exactRef("HEAD").getTarget().getObjectId(), second.getId()); }
@Test public void testListRemote_Smart_UploadPackDisabled() throws Exception { FileRepository src = remoteRepository.getRepository(); final FileBasedConfig cfg = src.getConfig(); cfg.setBoolean("http", null, "uploadpack", false); cfg.save(); Repository dst = createBareRepository(); Transport t = Transport.open(dst, smartAuthNoneURI); try { try { t.openFetch(); fail("connection opened even though service disabled"); } catch (TransportException err) { String exp = smartAuthNoneURI + ": git-upload-pack not permitted"; assertEquals(exp, err.getMessage()); } } finally { t.close(); } }