private void commitFile() throws IOException { final Path path = provider.getPath(URI.create(GIT + REPO_NAME + NEW_FILE_PATH)); final OutputStream outStream = provider.newOutputStream(path); assertThat(outStream).isNotNull(); outStream.write(("my content").getBytes()); outStream.close(); } }
private void commitFile() throws IOException { final Path path = provider.getPath(URI.create(GIT + REPO_NAME + NEW_FILE_PATH)); final OutputStream outStream = provider.newOutputStream(path); assertThat(outStream).isNotNull(); outStream.write(("my content").getBytes()); outStream.close(); } }
private RevCommit writeFile(final JGitFileSystem fs, final Path path, String branch) throws IOException, GitAPIException { final OutputStream stream = provider.newOutputStream(path); logger.info("Writing file: " + path.getFileName().toString()); stream.write("my cool content".getBytes()); stream.close(); return this.getCommitsFromBranch((GitImpl) fs.getGit(), branch).get(0); }
private RevCommit writeFile(final JGitFileSystem fs, final Path path, String branch) throws IOException, GitAPIException { final OutputStream stream = provider.newOutputStream(path); logger.info("Writing file: " + path.getFileName().toString()); stream.write("my cool content".getBytes()); stream.close(); return this.getCommitsFromBranch((GitImpl) fs.getGit(), branch).get(0); }
@Test public void testGetFileStore() throws Exception { final URI newRepo = URI.create("git://filestore-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = provider.getPath(URI.create("git://master@filestore-test-repo/path/to/myfile1.txt")); final OutputStream outStream = provider.newOutputStream(path); outStream.write("my cool content".getBytes()); outStream.close(); final FileStore fileStore = provider.getFileStore(path); assertThat(fileStore).isNotNull(); assertThat(fileStore.getAttribute("readOnly")).isEqualTo(Boolean.FALSE); }
@Test public void testGetFileStore() throws Exception { final URI newRepo = URI.create("git://filestore-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = provider.getPath(URI.create("git://master@filestore-test-repo/path/to/myfile1.txt")); final OutputStream outStream = provider.newOutputStream(path); outStream.write("my cool content".getBytes()); outStream.close(); final FileStore fileStore = provider.getFileStore(path); assertThat(fileStore).isNotNull(); assertThat(fileStore.getAttribute("readOnly")).isEqualTo(Boolean.FALSE); }
@Test public void testDeleteBranchIfExists() throws IOException { final URI newRepo = URI.create("git://deletebranchifexists1-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = provider.getPath(URI.create("git://user_branch@deletebranchifexists1-test-repo/path/to/myfile.txt")); final OutputStream outStream = provider.newOutputStream(path); assertThat(outStream).isNotNull(); outStream.write("my cool content".getBytes()); outStream.close(); provider.newInputStream(path).close(); assertThat(provider.deleteIfExists(provider.getPath(URI.create("git://user_branch@deletebranchifexists1-test-repo")))).isTrue(); assertThat(provider.deleteIfExists(provider.getPath(URI.create("git://not_user_branch@deletebranchifexists1-test-repo")))).isFalse(); assertThat(provider.deleteIfExists(provider.getPath(URI.create("git://user_branch@deletebranchifexists1-test-repo")))).isFalse(); }
@Test public void testDeleteBranchIfExists() throws IOException { final URI newRepo = URI.create("git://deletebranchifexists1-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = provider.getPath(URI.create("git://user_branch@deletebranchifexists1-test-repo/path/to/myfile.txt")); final OutputStream outStream = provider.newOutputStream(path); assertThat(outStream).isNotNull(); outStream.write("my cool content".getBytes()); outStream.close(); provider.newInputStream(path).close(); assertThat(provider.deleteIfExists(provider.getPath(URI.create("git://user_branch@deletebranchifexists1-test-repo")))).isTrue(); assertThat(provider.deleteIfExists(provider.getPath(URI.create("git://not_user_branch@deletebranchifexists1-test-repo")))).isFalse(); assertThat(provider.deleteIfExists(provider.getPath(URI.create("git://user_branch@deletebranchifexists1-test-repo")))).isFalse(); }
@Override public void createDirectory(final Path path, final FileAttribute<?>... attrs) throws UnsupportedOperationException, FileAlreadyExistsException, IOException, SecurityException { checkNotNull("path", path); final JGitPathImpl gPath = toPathImpl(path); final Pair<PathType, ObjectId> result = checkPath(gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath()); if (!result.getK1().equals(NOT_FOUND)) { throw new FileAlreadyExistsException(path.toString()); } try { final OutputStream outputStream = newOutputStream(path.resolve(".gitignore")); outputStream.write("# empty\n".getBytes()); outputStream.close(); } catch (final Exception e) { throw new IOException(e); } }
@Test public void moveBranchesNotAtTheSameFSShouldNotBeAllowedTest() throws IOException { final URI newRepo = URI.create("git://movebranch-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final URI anotherRepo = URI.create("git://another-repo"); provider.newFileSystem(anotherRepo, EMPTY_ENV); { final Path path = provider.getPath(URI.create("git://another-branch@movebranch-repo/dorinha.txt")); final OutputStream outStream = provider.newOutputStream(path); outStream.write("little baby another-branch".getBytes()); outStream.close(); } final Path source = provider.getPath(URI.create("git://another-branch@movebranch-repo/")); final Path target = provider.getPath(URI.create("git://another-branch-moved@another-repo/")); assertThatThrownBy(() -> provider.move(source, target)) .isInstanceOf(IllegalStateException.class); }
@Test public void copyBranchesNotAtTheSameFSShouldNotBeAllowedTest() throws IOException { final URI newRepo = URI.create("git://movebranch-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final URI anotherRepo = URI.create("git://another-repo"); provider.newFileSystem(anotherRepo, EMPTY_ENV); { final Path path = provider.getPath(URI.create("git://another-branch@movebranch-repo/dorinha.txt")); final OutputStream outStream = provider.newOutputStream(path); outStream.write("little baby another-branch".getBytes()); outStream.close(); } final Path source = provider.getPath(URI.create("git://another-branch@movebranch-repo/")); final Path target = provider.getPath(URI.create("git://another-branch-moved@another-repo/")); assertThatThrownBy(() -> provider.copy(source, target)) .isInstanceOf(IllegalStateException.class); }
@Test public void testDeleteIfExists() throws IOException { final URI newRepo = URI.create("git://deleteifexists1-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = provider.getPath(URI.create("git://user_branch@deleteifexists1-test-repo/path/to/myfile.txt")); final OutputStream outStream = provider.newOutputStream(path); assertThat(outStream).isNotNull(); outStream.write("my cool content".getBytes()); outStream.close(); provider.newInputStream(path).close(); assertThat(provider.deleteIfExists(provider.getPath(URI.create("git://user_branch@deleteifexists1-test-repo/non_existent_path")))).isFalse(); try { provider.deleteIfExists(provider.getPath(URI.create("git://user_branch@deleteifexists1-test-repo/path/to/"))); failBecauseExceptionWasNotThrown(DirectoryNotEmptyException.class); } catch (DirectoryNotEmptyException ignored) { } assertThat(provider.deleteIfExists(path)).isTrue(); }
@Test(expected = GitException.class) public void testTryToMergeNonexistentBranch() throws IOException { final URI newRepo = URI.create("git://merge-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); { final Path path = provider.getPath(URI.create("git://master@merge-test-repo/myfile1.txt")); final OutputStream outStream = provider.newOutputStream(path); outStream.write("my cool content".getBytes()); outStream.close(); } final Path master = provider.getPath(URI.create("git://master@merge-test-repo")); final Path develop = provider.getPath(URI.create("git://develop@merge-test-repo")); provider.copy(develop, master, new MergeCopyOption()); }
@Test public void testDeleteIfExists() throws IOException { final URI newRepo = URI.create("git://deleteifexists1-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = provider.getPath(URI.create("git://user_branch@deleteifexists1-test-repo/path/to/myfile.txt")); final OutputStream outStream = provider.newOutputStream(path); assertThat(outStream).isNotNull(); outStream.write("my cool content".getBytes()); outStream.close(); provider.newInputStream(path).close(); assertThat(provider.deleteIfExists(provider.getPath(URI.create("git://user_branch@deleteifexists1-test-repo/non_existent_path")))).isFalse(); try { provider.deleteIfExists(provider.getPath(URI.create("git://user_branch@deleteifexists1-test-repo/path/to/"))); failBecauseExceptionWasNotThrown(DirectoryNotEmptyException.class); } catch (DirectoryNotEmptyException ignored) { } assertThat(provider.deleteIfExists(path)).isTrue(); }
@Test(expected = GitException.class) public void testTryToMergeNonexistentBranch() throws IOException { final URI newRepo = URI.create("git://merge-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); { final Path path = provider.getPath(URI.create("git://master@merge-test-repo/myfile1.txt")); final OutputStream outStream = provider.newOutputStream(path); outStream.write("my cool content".getBytes()); outStream.close(); } final Path master = provider.getPath(URI.create("git://master@merge-test-repo")); final Path develop = provider.getPath(URI.create("git://develop@merge-test-repo")); provider.copy(develop, master, new MergeCopyOption()); }
@Test(expected = IllegalArgumentException.class) public void testMissingParemeter() throws IOException { final URI newRepo = URI.create("git://merge-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); { final Path path = provider.getPath(URI.create("git://master@merge-test-repo/myfile1.txt")); final OutputStream outStream = provider.newOutputStream(path); outStream.write("my cool content".getBytes()); outStream.close(); } final Path master = provider.getPath(URI.create("git://master@merge-test-repo")); final Path develop = provider.getPath(URI.create("git://develop@merge-test-repo")); provider.copy(develop, null, new MergeCopyOption()); } }
@Test(expected = IllegalArgumentException.class) public void testMissingParemeter() throws IOException { final URI newRepo = URI.create("git://merge-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); { final Path path = provider.getPath(URI.create("git://master@merge-test-repo/myfile1.txt")); final OutputStream outStream = provider.newOutputStream(path); outStream.write("my cool content".getBytes()); outStream.close(); } final Path master = provider.getPath(URI.create("git://master@merge-test-repo")); final Path develop = provider.getPath(URI.create("git://develop@merge-test-repo")); provider.copy(develop, null, new MergeCopyOption()); } }
@Test public void moveBranchesTest() throws IOException { final URI newRepo = URI.create("git://movebranch-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); { final Path path = provider.getPath(URI.create("git://another-branch@movebranch-repo/dorinha.txt")); final OutputStream outStream = provider.newOutputStream(path); outStream.write("little baby another-branch".getBytes()); outStream.close(); } final Path source = provider.getPath(URI.create("git://another-branch@movebranch-repo/")); final Path target = provider.getPath(URI.create("git://another-branch-moved@movebranch-repo/")); provider.move(source, target); Throwable extractContentCall = catchThrowable(() -> extractContent(provider.getPath(URI.create("git://another-branch@movebranch-repo/dorinha.txt")))); assertThat(extractContentCall).isInstanceOf(NoSuchFileException.class); final String contentMoved = extractContent(provider.getPath(URI.create("git://another-branch-moved@movebranch-repo/dorinha.txt"))); assertThat(contentMoved).isNotNull().isEqualTo("little baby another-branch"); }
@Test public void testCheckAccess() throws Exception { final URI newRepo = URI.create("git://checkaccess-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = provider.getPath(URI.create("git://master@checkaccess-test-repo/path/to/myfile1.txt")); final OutputStream outStream = provider.newOutputStream(path); outStream.write("my cool content".getBytes()); outStream.close(); provider.checkAccess(path); final Path path_to_dir = provider.getPath(URI.create("git://master@checkaccess-test-repo/path/to")); provider.checkAccess(path_to_dir); final Path path_not_exists = provider.getPath(URI.create("git://master@checkaccess-test-repo/path/to/some.txt")); try { provider.checkAccess(path_not_exists); failBecauseExceptionWasNotThrown(NoSuchFileException.class); } catch (NoSuchFileException ignored) { } }
@Test public void testCheckAccess() throws Exception { final URI newRepo = URI.create("git://checkaccess-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = provider.getPath(URI.create("git://master@checkaccess-test-repo/path/to/myfile1.txt")); final OutputStream outStream = provider.newOutputStream(path); outStream.write("my cool content".getBytes()); outStream.close(); provider.checkAccess(path); final Path path_to_dir = provider.getPath(URI.create("git://master@checkaccess-test-repo/path/to")); provider.checkAccess(path_to_dir); final Path path_not_exists = provider.getPath(URI.create("git://master@checkaccess-test-repo/path/to/some.txt")); try { provider.checkAccess(path_not_exists); failBecauseExceptionWasNotThrown(NoSuchFileException.class); } catch (NoSuchFileException ignored) { } }