private void deleteResource(final JGitPathImpl path, final DeleteOption... options) { delete(path, buildCommitInfo("delete {" + path.getPath() + "}", Arrays.asList(options))); }
public void deleteAsset(final JGitPathImpl path, final DeleteOption... options) { final PathInfo result = path.getFileSystem().getGit().getPathInfo(path.getRefTree(), path.getPath()); if (result.getPathType().equals(PathType.DIRECTORY)) { if (deleteNonEmptyDirectory(options)) { deleteResource(path, options); return; } final List<PathInfo> content = path.getFileSystem().getGit().listPathContent(path.getRefTree(), path.getPath()); if (content.size() == 1 && content.get(0).getPath().equals(path.getPath().substring(1) + "/.gitkeep")) { delete(path.resolve(".gitkeep")); deleteResource(path, options); return; } throw new DirectoryNotEmptyException(path.toString()); } if (result.getPathType().equals(NOT_FOUND)) { throw new NoSuchFileException(path.toString()); } deleteResource(path, options); }
@Test public void testDeleteBranch() throws IOException { final URI newRepo = URI.create("git://delete-branch-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = provider.getPath(URI.create("git://user_branch@delete-branch-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(); provider.delete(provider.getPath(URI.create("git://user_branch@delete-branch-test-repo"))); try { provider.delete(provider.getPath(URI.create("git://user_branch@delete-branch-test-repo"))); failBecauseExceptionWasNotThrown(NoSuchFileException.class); } catch (NoSuchFileException ignored) { } try { provider.delete(provider.getPath(URI.create("git://some_user_branch@delete-branch-test-repo"))); failBecauseExceptionWasNotThrown(NoSuchFileException.class); } catch (NoSuchFileException ignored) { } }
public boolean deleteAssetIfExists(final JGitPathImpl path, final DeleteOption... options) { final PathInfo result = path.getFileSystem().getGit().getPathInfo(path.getRefTree(), path.getPath()); if (result.getPathType().equals(PathType.DIRECTORY)) { if (deleteNonEmptyDirectory(options)) { deleteResource(path, options); return true; } final List<PathInfo> content = path.getFileSystem().getGit().listPathContent(path.getRefTree(), path.getPath()); if (content.size() == 1 && content.get(0).getPath().equals(path.getPath().substring(1) + "/.gitkeep")) { delete(path.resolve(".gitkeep")); return true; } throw new DirectoryNotEmptyException(path.toString()); } if (result.getPathType().equals(NOT_FOUND)) { return false; } deleteResource(path, options); return true; }
@Test public void testDeleteBranch() throws IOException { final URI newRepo = URI.create("git://delete-branch-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = provider.getPath(URI.create("git://user_branch@delete-branch-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(); provider.delete(provider.getPath(URI.create("git://user_branch@delete-branch-test-repo"))); try { provider.delete(provider.getPath(URI.create("git://user_branch@delete-branch-test-repo"))); failBecauseExceptionWasNotThrown(NoSuchFileException.class); } catch (NoSuchFileException ignored) { } try { provider.delete(provider.getPath(URI.create("git://some_user_branch@delete-branch-test-repo"))); failBecauseExceptionWasNotThrown(NoSuchFileException.class); } catch (NoSuchFileException ignored) { } }
provider.delete(provider.getPath(URI.create("git://user_branch@delete1-test-repo/non_existent_path"))); failBecauseExceptionWasNotThrown(NoSuchFileException.class); } catch (NoSuchFileException ignored) { provider.delete(provider.getPath(URI.create("git://user_branch@delete1-test-repo/path/to/"))); failBecauseExceptionWasNotThrown(DirectoryNotEmptyException.class); } catch (DirectoryNotEmptyException ignored) { provider.delete(path); provider.delete(fsPath); assertThat(fsPath.getFileSystem().isOpen()).isEqualTo(false);
provider.delete(provider.getPath(URI.create("git://user_branch@delete1-test-repo/non_existent_path"))); failBecauseExceptionWasNotThrown(NoSuchFileException.class); } catch (NoSuchFileException ignored) { provider.delete(provider.getPath(URI.create("git://user_branch@delete1-test-repo/path/to/"))); failBecauseExceptionWasNotThrown(DirectoryNotEmptyException.class); } catch (DirectoryNotEmptyException ignored) { provider.delete(path); provider.delete(fsPath); assertThat(fsPath.getFileSystem().isOpen()).isEqualTo(false);
@Test public void testDeleteShouldRemoveEmptyParentDir() throws IOException { final URI doraRepo = URI.create("git://parentDir/dora-repo"); FileSystem doraFS = provider.newFileSystem(doraRepo, EMPTY_ENV); final File doraRepoDir = ((JGitFileSystemProxy) doraFS).getGit().getRepository().getDirectory(); final File parentDir = doraRepoDir.getParentFile(); final File gitProviderDir = provider.getGitRepoContainerDir(); final URI doraRepo1 = URI.create("git://parentDir/dora-repo1"); FileSystem doraFS1 = provider.newFileSystem(doraRepo1, EMPTY_ENV); final File dora1RepoDir = ((JGitFileSystemProxy) doraFS1).getGit().getRepository().getDirectory(); final File parentDir1 = doraRepoDir.getParentFile(); assertEquals(parentDir, parentDir1); provider.delete(doraFS.getPath(null)); assertFalse(doraRepoDir.exists()); assertTrue(parentDir.exists()); assertTrue(gitProviderDir.exists()); provider.delete(doraFS1.getPath(null)); assertFalse(dora1RepoDir.exists()); assertFalse(parentDir1.exists()); assertTrue(gitProviderDir.exists()); }
@Test public void testDeleteShouldRemoveEmptyParentDir() throws IOException { final URI doraRepo = URI.create("git://parentDir/dora-repo"); FileSystem doraFS = provider.newFileSystem(doraRepo, EMPTY_ENV); final File doraRepoDir = ((JGitFileSystemProxy) doraFS).getGit().getRepository().getDirectory(); final File parentDir = doraRepoDir.getParentFile(); final File gitProviderDir = provider.getGitRepoContainerDir(); final URI doraRepo1 = URI.create("git://parentDir/dora-repo1"); FileSystem doraFS1 = provider.newFileSystem(doraRepo1, EMPTY_ENV); final File dora1RepoDir = ((JGitFileSystemProxy) doraFS1).getGit().getRepository().getDirectory(); final File parentDir1 = doraRepoDir.getParentFile(); assertEquals(parentDir, parentDir1); provider.delete(doraFS.getPath(null)); assertFalse(doraRepoDir.exists()); assertTrue(parentDir.exists()); assertTrue(gitProviderDir.exists()); provider.delete(doraFS1.getPath(null)); assertFalse(dora1RepoDir.exists()); assertFalse(parentDir1.exists()); assertTrue(gitProviderDir.exists()); }
target, options); delete(source); } else { final Map<JGitPathImpl, JGitPathImpl> fromTo = new HashMap<>();
provider.delete(source.getPath().resolve("users-new").resolve("demo.iml"));