@Override public Path getPath( final String first, final String... more ) throws InvalidPathException { checkClose(); 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 ); }
@Before public void setup() { when(fs.getSeparator()).thenReturn("/"); when(fs.provider()).thenReturn(fsp); when(fsp.isDefault()).thenReturn(false); when(fsp.getScheme()).thenReturn("git"); }
@Test public void testSimpleBranchedGitRelative() { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, "home", "master@my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isFalse(); assertThat(path.toString()).isEqualTo("home"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/:home"); assertThat(path.getRoot().toString()).isEqualTo(""); assertThat(path.getNameCount()).isEqualTo(1); }
@Test public void testSimpleBranchedGitRoot() { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, "/", "master@my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/"); assertThat(path.getRoot().toString()).isEqualTo("/"); assertThat(path.getNameCount()).isEqualTo(0); }
@Test public void testSimpleBranchedGitRoot2() { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, "/path/to/some/place.txt", "master@my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/some/place.txt"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/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 testSimpleImplicitBranchGit() { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, "/path/to/some/place.txt", "my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/some/place.txt"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/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 testSimpleBranchedGitRoot2Spaced() throws URIException { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, URIUtil.decode("/path/to/some/some%20place.txt"), "master@my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/some/some place.txt"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/some%20place.txt"); assertThat(path.getNameCount()).isEqualTo(4); assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path"); assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/"); }
@Test public void testOnlyLocalRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final Git git = setupGit(); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); 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 testSimpleImplicitBranchGitRoot() { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, "/", "my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/"); assertThat(path.getRoot().toString()).isEqualTo("/"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/"); assertThat(path.getNameCount()).isEqualTo(0); assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/"); try { assertThat(path.getName(0).toString()).isNotNull().isEqualTo(""); failBecauseExceptionWasNotThrown(IllegalArgumentException.class); } catch (IllegalArgumentException ex) { } }
@Test public void testRemoteRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final File tempDir = createTempDirectory(); final Git git = Git.cloneRepository().setNoCheckout( false ).setBare( true ).setCloneAllBranches( true ).setURI( setupGit().getRepository().getDirectory().toString() ).setDirectory( tempDir ).call(); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); 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 testProvider() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final Git git = setupGit(); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); assertThat( fileSystem.getName() ).isEqualTo( "my-repo" ); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( "/" ); assertThat( fileSystem.provider() ).isEqualTo( fsProvider ); }
@Test public void testSupportedFileAttributeViews() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final Git git = setupGit(); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( "/" ); assertThat( fileSystem.getName() ).isEqualTo( "my-repo" ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 2 ).contains( "basic", "version" ); }
when(fs.provider()).thenReturn(fsprovider); when(fs.getSeparator()).thenReturn("/");
@Test(expected = IllegalStateException.class) public void testClose() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final Git git = setupGit(); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); 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(); }