@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 ); }
final Path oldPath; if ( !diffEntry.getOldPath().equals( DiffEntry.DEV_NULL ) ) { oldPath = JGitPathImpl.create( fs, "/" + diffEntry.getOldPath(), host, null, false ); } else { oldPath = null; if ( !diffEntry.getNewPath().equals( DiffEntry.DEV_NULL ) ) { JGitPathInfo pathInfo = resolvePath( fs.gitRepo(), tree, diffEntry.getNewPath() ); newPath = JGitPathImpl.create( fs, "/" + pathInfo.getPath(), host, pathInfo.getObjectId(), false ); } else { newPath = null;
@Override public Path getPath( final URI uri ) throws IllegalArgumentException, FileSystemNotFoundException, SecurityException { checkNotNull( "uri", uri ); checkCondition( "uri scheme not supported", uri.getScheme().equals( getScheme() ) || uri.getScheme().equals( "default" ) ); checkURI( "uri", uri ); final JGitFileSystem fileSystem = fileSystems.get( extractRepoName( uri ) ); if ( fileSystem == null ) { throw new FileSystemNotFoundException(); } try { return JGitPathImpl.create( fileSystem, URIUtil.decode( extractPath( uri ) ), extractHost( uri ), false ); } catch ( final URIException e ) { return null; } }
@Test public void testNewFileSystemUnsupportedOp() { final URI newRepo = URI.create("git://someunsup-repo-name"); final FileSystem fs = PROVIDER.newFileSystem(newRepo, EMPTY_ENV); final Path path = JGitPathImpl.create( (JGitFileSystem) fs, "", "repo2-name", false ); try { PROVIDER.newFileSystem(path, EMPTY_ENV); failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); } catch (Exception e) { } }
final Path path = JGitPathImpl.create(fs, "/path/to", "master@my-host", false); final Path other = JGitPathImpl.create(fs, "/path/to/some/place", "master@my-host", false); final Path path2 = JGitPathImpl.create(fs, "/path/to/some/place", "master@my-host", false); final Path other2 = JGitPathImpl.create(fs, "/path/to", "master@my-host", false); final Path path3 = JGitPathImpl.create(fs, "/path/to", "master@my-host", false); final Path other3 = JGitPathImpl.create(fs, "/path/to", "master@my-host", false); final Path path4 = JGitPathImpl.create(fs, "path/to", "master@my-host", false); final Path other4 = JGitPathImpl.create(fs, "path/to/some/place", "master@my-host", false); final Path path5 = JGitPathImpl.create(fs, "path/to", "master@my-host", false); final Path other5 = JGitPathImpl.create(fs, "some/place", "master@my-host", false); final Path path6 = JGitPathImpl.create(fs, "some/place", "master@my-host", false); final Path other6 = JGitPathImpl.create(fs, "path/to", "master@my-host", false); final Path path7 = JGitPathImpl.create(fs, "path/to/some/thing/here", "master@my-host", false); final Path other7 = JGitPathImpl.create(fs, "some/place", "master@my-host", false); final Path path8 = JGitPathImpl.create(fs, "some/place", "master@my-host", false); final Path other8 = JGitPathImpl.create( fs, "path/to/some/thing/here", "master@my-host", false ); final Path path9 = JGitPathImpl.create(fs, "/path/to", "master@my-host", false); final Path other9 = JGitPathImpl.create(fs, "/path/to", "master@my-host", false); final Path path10 = JGitPathImpl.create(fs, "path/to", "master@my-host", false); final Path other10 = JGitPathImpl.create(fs, "path/to", "master@my-host", false);
@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 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 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 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 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 testSimpleBranchedGit() { 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()).isEqualTo(path); assertThat(path.getNameCount()).isEqualTo(0); assertThat(path.getRoot()).isNotNull().isEqualTo(path); }