/** * Obtains the repository for the current directory or creates a new one and returns it if no * repository can be found on the current directory. * * @return the existing or newly created repository, never {@code null} * @throws RuntimeException if the repository cannot be created at the current directory * @see InitOp */ public Repository getOrCreateRepository() { if (repository == null) { repository = command(InitOp.class).call(); checkState(repository != null, "Repository shouldn't be null as we checked it didn't exist before calling init"); } return repository; }
final Platform platform = platform(); Optional<URI> resolvedURI = new ResolveGeogigURI(platform, hints).call(); if (!resolvedURI.isPresent()) { final boolean repoExisted = repoInitializer.repoExists(repoURI); repoInitializer.initialize(repoURI, context()); repository().blobStore().putBlob(Blobs.SPARSE_FILTER_BLOB_KEY, Files.toByteArray(oldFilterFile)); } catch (Exception e) { context)) { PluginDefaults defaults = context.pluginDefaults(); addDefaults(configDB, defaults, effectiveConfigBuilder); if (config != null) { effectiveConfigBuilder.putAll(config); configDB.put(key, value); repository = repository(); repository.configure(); } catch (RepositoryConnectionException e) { repository = repository(); createDefaultRefs();
.setConfig(Init.splitConfig(config)).setFilterFile(filterFile).call(); boolean succeeded = false; try {
@Test public void testReinitializeExistingRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).call(); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); Ref master = new Ref(Ref.MASTER, RevObjectTestSupport.hashString("hash me")); when(mockRefParse.call()).thenReturn(Optional.of(master)); Context injector = mock(Context.class); when(injector.command(eq(RefParse.class))).thenReturn(mockRefParse); when(injector.platform()).thenReturn(platform); when(injector.repository()).thenReturn(mockRepo); init.setContext(injector); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); assertNotNull(init.call()); verify(platform, atLeastOnce()).pwd(); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); verify(injector, never()).command(eq(UpdateRef.class)); verify(injector, never()).command(eq(UpdateSymRef.class)); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
Hints hints = new Hints(); hints.set(Hints.REPOSITORY_URL, workingDir.getAbsoluteFile().toURI()); init = new InitOp(hints); init.setContext(injector);
.setConfig(Init.splitConfig(config)).setFilterFile(filterFile).call(); boolean succeeded = false; try {
@Test public void testReinitializeExistingRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).call(); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); Ref master = new Ref(Ref.MASTER, RevObjectTestSupport.hashString("hash me")); when(mockRefParse.call()).thenReturn(Optional.of(master)); Context injector = mock(Context.class); when(injector.command(eq(RefParse.class))).thenReturn(mockRefParse); when(injector.platform()).thenReturn(platform); when(injector.repository()).thenReturn(mockRepo); init.setContext(injector); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); assertNotNull(init.call()); verify(platform, atLeastOnce()).pwd(); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); verify(injector, never()).command(eq(UpdateRef.class)); verify(injector, never()).command(eq(UpdateSymRef.class)); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
Hints hints = new Hints(); hints.set(Hints.REPOSITORY_URL, workingDir.getAbsoluteFile().toURI()); init = new InitOp(hints); init.setContext(injector);
/** * Obtains the repository for the current directory or creates a new one and returns it if no * repository can be found on the current directory. * * @return the existing or newly created repository, never {@code null} * @throws RuntimeException if the repository cannot be created at the current directory * @see InitOp */ public Repository getOrCreateRepository() { if (repository == null) { try { repository = command(InitOp.class).call(); checkState(repository != null, "Repository shouldn't be null as we checked it didn't exist before calling init"); } catch (Exception e) { throw Throwables.propagate(e); } } return repository; }
.setConfig(Init.splitConfig(config)).setFilterFile(filterFile).call(); boolean succeeded = false; try {
final Platform platform = platform(); Optional<URI> resolvedURI = new ResolveGeogigURI(platform, hints).call(); if (!resolvedURI.isPresent()) { final boolean repoExisted = repoInitializer.repoExists(repoURI); repoInitializer.initialize(repoURI, context()); repository().blobStore().putBlob(Blobs.SPARSE_FILTER_BLOB_KEY, Files.toByteArray(oldFilterFile)); } catch (Exception e) { context)) { PluginDefaults defaults = context.pluginDefaults(); addDefaults(configDB, defaults, effectiveConfigBuilder); if (config != null) { effectiveConfigBuilder.putAll(config); repository = repository(); repository.configure(); } catch (RepositoryConnectionException e) { repository = repository(); createDefaultRefs(); } catch (IllegalStateException e) { Throwables.propagate(e);
@Test public void testNullWorkingDir() { when(platform.pwd()).thenReturn(null); exception.expect(IllegalStateException.class); init.call(); when(platform.pwd()).thenReturn(workingDir); }
@Test public void testNullWorkingDir() { when(platform.pwd()).thenReturn(null); exception.expect(IllegalStateException.class); init.call(); when(platform.pwd()).thenReturn(workingDir); }
@Test public void testReinitializeExistingRepoFromInsideASubdirectory() throws Exception { testCreateNewRepo(); File subDir = new File(new File(workingDir, "subdir1"), "subdir2"); assertTrue(subDir.mkdirs()); when(platform.pwd()).thenReturn(subDir); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); assertNotNull(init.call()); verify(platform, atLeastOnce()).pwd(); } }
@Test public void testReinitializeExistingRepoFromInsideASubdirectory() throws Exception { testCreateNewRepo(); File subDir = new File(new File(workingDir, "subdir1"), "subdir2"); assertTrue(subDir.mkdirs()); when(platform.pwd()).thenReturn(subDir); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); assertNotNull(init.call()); verify(platform, atLeastOnce()).pwd(); } }
@Test public void testCreateNewRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); verify(injector, times(1)).repository(); verify(mockUpdateRef, times(1)).setName(eq(Ref.MASTER)); verify(mockUpdateRef, times(1)).setName(eq(Ref.WORK_HEAD)); verify(mockUpdateRef, times(1)).setName(eq(Ref.STAGE_HEAD)); verify(mockUpdateRef, times(1)).setNewValue(eq(ObjectId.NULL)); verify(mockUpdateRef, times(2)).setNewValue(eq(RevTree.EMPTY_TREE_ID)); verify(mockUpdateRef, times(3)).setReason(anyString()); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).setName(eq(Ref.HEAD)); verify(mockUpdateSymRef, times(1)).setNewValue(eq(Ref.MASTER)); verify(mockUpdateSymRef, times(1)).call(); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
@Test public void testCreateNewRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); verify(injector, times(1)).repository(); verify(mockUpdateRef, times(1)).setName(eq(Ref.MASTER)); verify(mockUpdateRef, times(1)).setName(eq(Ref.WORK_HEAD)); verify(mockUpdateRef, times(1)).setName(eq(Ref.STAGE_HEAD)); verify(mockUpdateRef, times(1)).setNewValue(eq(ObjectId.NULL)); verify(mockUpdateRef, times(2)).setNewValue(eq(RevTree.EMPTY_TREE_ID)); verify(mockUpdateRef, times(3)).setReason(anyString()); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).setName(eq(Ref.HEAD)); verify(mockUpdateSymRef, times(1)).setNewValue(eq(Ref.MASTER)); verify(mockUpdateSymRef, times(1)).call(); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }