@Test public void lockShouldSupportMultipleInnerLocksForTheSameThreadTest() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); fileSystem.lock(); //inner locks fileSystem.lock(); fileSystem.lock(); fileSystem.unlock(); fileSystem.unlock(); fileSystem.unlock(); }
@Override public void dispose() { if (!isClosed) { close(); } provider.onDisposeFileSystem(this); }
@Override public Path getPath(final String first, final String... more) throws InvalidPathException { checkClosed(); if (first == null || first.trim().isEmpty()) { return new JGitFSPath(this); } if (more == null || more.length == 0) { return JGitPathImpl.create(this, first, JGitPathImpl.DEFAULT_REF_TREE + "@" + name, false); } final StringBuilder sb = new StringBuilder(); for (final String segment : more) { if (segment.length() > 0) { if (sb.length() > 0) { sb.append(getSeparator()); } sb.append(segment); } } return JGitPathImpl.create(this, sb.toString(), first + "@" + name, false); }
@Test(expected = IllegalStateException.class) public void testClose() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.isOpen()).isTrue(); assertThat(fileSystem.getFileStores()).isNotNull(); fileSystem.close(); assertThat(fileSystem.isOpen()).isFalse(); assertThat(fileSystem.getFileStores()).isNotNull(); }
@Test public void testOnlyLocalRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.getRootDirectories()).hasSize(1); final Path root = fileSystem.getRootDirectories().iterator().next(); assertThat(root.toString()).isEqualTo("/"); assertThat(root.getRoot().toString()).isEqualTo("/"); }
@Test public void testPathNonBranchRooted() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); when(fsProvider.isDefault()).thenReturn(false); when(fsProvider.getScheme()).thenReturn("git"); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); final Path path = fileSystem.getPath("/path/to/some/place.txt"); AssertionsForClassTypes.assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/some/place.txt"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-repo/path/to/some/place.txt"); assertThat(path.getNameCount()).isEqualTo(4); assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path"); assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/"); }
@Test public void testSupportedFileAttributeViews() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.supportedFileAttributeViews()).isNotEmpty().hasSize(2).contains("basic", "version"); }
@Test public void testProvider() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.provider()).isEqualTo(fsProvider); }
assertThat(realInstanceFs1.getName()).isEqualToIgnoringCase(anotherInstanceOfFs1.getName()); assertThat(realInstanceFs1.getLock()).isEqualTo(anotherInstanceOfFs1.getLock()); new Commit(realInstanceFs1.getGit(), "master", "user1", }}).execute(); InputStream stream = provider.newInputStream(anotherInstanceOfFs1.getPath("realInstanceFs1File.txt")); assertNotNull(stream); String content = new Scanner(stream).useDelimiter("\\A").next(); content); new Commit(anotherInstanceOfFs1.getGit(), "master", "user1", stream = provider.newInputStream(realInstanceFs1.getPath("anotherInstanceOfFs1File.txt")); assertNotNull(stream); content = new Scanner(stream).useDelimiter("\\A").next(); realInstanceFs1.lock(); assertThat(realInstanceFs1.hasBeenInUse()).isTrue(); assertThat(anotherInstanceOfFs1.hasBeenInUse()).isTrue();
@Test public void testInstalledHook() { final URI newRepo = URI.create("git://hook-repo-name"); final FileSystem fs = provider.newFileSystem(newRepo, EMPTY_ENV); assertThat(fs).isNotNull(); if (fs instanceof JGitFileSystemImpl) { File[] hooks = new File(((JGitFileSystemImpl) fs).getGit().getRepository().getDirectory(), "hooks").listFiles(); assertThat(hooks).isNotEmpty().isNotNull(); assertThat(hooks.length).isEqualTo(2); boolean foundPreCommitHook = false; boolean foundPostCommitHook = false; for (File hook : hooks) { if (hook.getName().equals("pre-commit")) { foundPreCommitHook = hook.canExecute(); } else if (hook.getName().equals("post-commit")) { foundPostCommitHook = hook.canExecute(); } } assertThat(foundPreCommitHook).isTrue(); assertThat(foundPostCommitHook).isTrue(); } }
@Test(expected = UnsupportedOperationException.class) public void testGetPathMatcher() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); fileSystem.getPathMatcher("*"); }
@Test(expected = UnsupportedOperationException.class) @Ignore public void testNewWatchService() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); fileSystem.newWatchService(); }
@Test(expected = UnsupportedOperationException.class) public void testGetUserPrincipalLookupService() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); fileSystem.getUserPrincipalLookupService(); }
@Test public void testFileStore() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final File tempDir = createTempDirectory(); final Git git = setupGit(tempDir); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.getFileStores()).hasSize(1); final FileStore fileStore = fileSystem.getFileStores().iterator().next(); assertThat(fileStore).isNotNull(); assertThat(fileStore.getTotalSpace()).isEqualTo(tempDir.getTotalSpace()); assertThat(fileStore.getUsableSpace()).isEqualTo(tempDir.getUsableSpace()); }
@Override public Set<String> supportedFileAttributeViews() { checkClosed(); return SUPPORTED_ATTR_VIEWS; }
private JGitFileSystem newFileSystem(Map<String, String> fullHostNames, Git git, String fsName, CredentialsProvider credential, JGitFileSystemsEventsManager fsEventsManager, Map<FileSystemHooks, ?> fsHooks) { fileSystemsLocks.putIfAbsent(fsName, createLock(git)); final JGitFileSystem fs = new JGitFileSystemImpl(jGitFileSystemProvider, fullHostNames, git, fileSystemsLocks.get(fsName), fsName, credential, fsEventsManager, fsHooks); fs.getGit().gc(); return fs; }
@Override public void setBatchCommitInfo(final String defaultMessage, final CommentedOption op) { this.batchCommitInfo = buildCommitInfo(defaultMessage, op); }
@Test(expected = IllegalStateException.class) public void testClose() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.isOpen()).isTrue(); assertThat(fileSystem.getFileStores()).isNotNull(); fileSystem.close(); assertThat(fileSystem.isOpen()).isFalse(); assertThat(fileSystem.getFileStores()).isNotNull(); }
@Test public void testOnlyLocalRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.getRootDirectories()).hasSize(1); final Path root = fileSystem.getRootDirectories().iterator().next(); assertThat(root.toString()).isEqualTo("/"); assertThat(root.getRoot().toString()).isEqualTo("/"); }
@Test public void testPathNonBranchNonRooted() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); when(fsProvider.isDefault()).thenReturn(false); when(fsProvider.getScheme()).thenReturn("git"); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); final Path path = fileSystem.getPath("path/to/some/place.txt"); AssertionsForClassTypes.assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isFalse(); assertThat(path.toString()).isEqualTo("path/to/some/place.txt"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-repo/:path/to/some/place.txt"); assertThat(path.getNameCount()).isEqualTo(4); assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path"); assertThat(path.getRoot().toString()).isNotNull().isEqualTo(""); }