org.eclipse.jgit.util.FileUtils Java Examples
The following examples show how to use
org.eclipse.jgit.util.FileUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitCloneTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testCloneNotGitRepository() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); String workspaceId = getWorkspaceId(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName().concat("Project"), null); IPath clonePath = new Path("file").append(workspaceId).append(project.getString(ProtocolConstants.KEY_NAME)).makeAbsolute(); // clone File notAGitRepository = createTempDir().toFile(); assertTrue(notAGitRepository.isDirectory()); assertTrue(notAGitRepository.list().length == 0); WebRequest request = getPostGitCloneRequest(notAGitRepository.toURI().toString(), clonePath); WebResponse response = webConversation.getResponse(request); ServerStatus status = waitForTask(response); assertFalse(status.toString(), status.isOK()); assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, status.getHttpCode()); assertEquals("Error cloning git repository", status.getMessage()); assertNotNull(status.getJsonData()); assertEquals(status.toString(), "Invalid remote: origin", status.getException().getMessage()); // cleanup the tempDir FileUtils.delete(notAGitRepository, FileUtils.RECURSIVE); }
Example #2
Source File: FilesWriteTest.java From ParallelGit with Apache License 2.0 | 6 votes |
@Test public void writeLargeFile_shouldWork() throws IOException { repoDir = FileUtils.createTempDir(getClass().getSimpleName(), null, null); repo = RepositoryUtils.createRepository(repoDir, true); DirCacheBuilder builder = CacheUtils.keepEverything(cache); byte[] largeData = new byte[50*1024*1024+1]; Random random = new Random(); random.nextBytes(largeData); AnyObjectId blobId = BlobUtils.insertBlob(largeData, repo); addFile("large.txt", REGULAR_FILE, blobId, builder); builder.finish(); commitToMaster(); initGitFileSystemForBranch(MASTER); byte[] data = someBytes(); Path file = gfs.getPath("/large.txt"); Files.write(file, data, APPEND); }
Example #3
Source File: FilesWriteTest.java From ParallelGit with Apache License 2.0 | 6 votes |
@Test public void writeLargeFile_shouldWork() throws IOException { repoDir = FileUtils.createTempDir(getClass().getSimpleName(), null, null); repo = RepositoryUtils.createRepository(repoDir, true); DirCacheBuilder builder = CacheUtils.keepEverything(cache); byte[] largeData = new byte[50*1024*1024+1]; Random random = new Random(); random.nextBytes(largeData); AnyObjectId blobId = BlobUtils.insertBlob(largeData, repo); addFile("large.txt", REGULAR_FILE, blobId, builder); builder.finish(); commitToMaster(); initGitFileSystemForBranch(MASTER); byte[] data = someBytes(); Path file = gfs.getPath("/large.txt"); Files.write(file, data, APPEND); }
Example #4
Source File: GitSubmoduleHandlerV1.java From orion.server with Eclipse Public License 1.0 | 6 votes |
public static void removeSubmodule(Repository db, Repository parentRepo, String pathToSubmodule) throws Exception { pathToSubmodule = pathToSubmodule.replace("\\", "/"); StoredConfig gitSubmodulesConfig = getGitSubmodulesConfig(parentRepo); gitSubmodulesConfig.unsetSection(CONFIG_SUBMODULE_SECTION, pathToSubmodule); gitSubmodulesConfig.save(); StoredConfig repositoryConfig = parentRepo.getConfig(); repositoryConfig.unsetSection(CONFIG_SUBMODULE_SECTION, pathToSubmodule); repositoryConfig.save(); Git git = Git.wrap(parentRepo); git.add().addFilepattern(DOT_GIT_MODULES).call(); RmCommand rm = git.rm().addFilepattern(pathToSubmodule); if (gitSubmodulesConfig.getSections().size() == 0) { rm.addFilepattern(DOT_GIT_MODULES); } rm.call(); FileUtils.delete(db.getWorkTree(), FileUtils.RECURSIVE); FileUtils.delete(db.getDirectory(), FileUtils.RECURSIVE); }
Example #5
Source File: UIGit.java From hop with Apache License 2.0 | 6 votes |
@Override public void add( String filepattern ) { try { if ( filepattern.endsWith( ".ours" ) || filepattern.endsWith( ".theirs" ) ) { FileUtils.rename( new File( directory, filepattern ), new File( directory, FilenameUtils.removeExtension( filepattern ) ), StandardCopyOption.REPLACE_EXISTING ); filepattern = FilenameUtils.removeExtension( filepattern ); org.apache.commons.io.FileUtils.deleteQuietly( new File( directory, filepattern + ".ours" ) ); org.apache.commons.io.FileUtils.deleteQuietly( new File( directory, filepattern + ".theirs" ) ); } git.add().addFilepattern( filepattern ).call(); } catch ( Exception e ) { showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), e.getMessage() ); } }
Example #6
Source File: UIGit.java From hop with Apache License 2.0 | 6 votes |
@Override public void revertPath( String path ) { try { // Delete added files Status status = git.status().addPath( path ).call(); if ( status.getUntracked().size() != 0 || status.getAdded().size() != 0 ) { resetPath( path ); org.apache.commons.io.FileUtils.deleteQuietly( new File( directory, path ) ); } /* * This is a work-around to discard changes of conflicting files * Git CLI `git checkout -- conflicted.txt` discards the changes, but jgit does not */ git.add().addFilepattern( path ).call(); git.checkout().setStartPoint( Constants.HEAD ).addPath( path ).call(); org.apache.commons.io.FileUtils.deleteQuietly( new File( directory, path + ".ours" ) ); org.apache.commons.io.FileUtils.deleteQuietly( new File( directory, path + ".theirs" ) ); } catch ( Exception e ) { showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), e.getMessage() ); } }
Example #7
Source File: JGitEnvironmentRepositoryTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Before public void init() throws Exception { String uri = ConfigServerTestUtils.prepareLocalRepo(); this.repository = new JGitEnvironmentRepository(this.environment, new JGitEnvironmentProperties()); this.repository.setUri(uri); if (this.basedir.exists()) { FileUtils.delete(this.basedir, FileUtils.RECURSIVE | FileUtils.RETRY); } }
Example #8
Source File: JGitEnvironmentRepositoryIntegrationTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Before public void init() throws Exception { if (this.basedir.exists()) { FileUtils.delete(this.basedir, FileUtils.RECURSIVE); } ConfigServerTestUtils.deleteLocalRepo(""); }
Example #9
Source File: SVNKitEnvironmentRepositoryTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { File basedir = new File("target/config"); String uri = ConfigServerTestUtils.prepareLocalSvnRepo( "src/test/resources/" + REPOSITORY_NAME, "target/repos/" + REPOSITORY_NAME); if (basedir.exists()) { FileUtils.delete(basedir, FileUtils.RECURSIVE | FileUtils.RETRY); } new SpringApplicationBuilder(TestApplication.class).profiles("subversion") .properties("server.port=8888", "spring.cloud.config.server.svn.uri:" + uri) .run(args); }
Example #10
Source File: SVNKitEnvironmentRepositoryTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Before public void init() throws Exception { String uri = ConfigServerTestUtils.prepareLocalSvnRepo( "src/test/resources/" + REPOSITORY_NAME, "target/repos/" + REPOSITORY_NAME); this.repository.setUri(uri); if (this.basedir.exists()) { FileUtils.delete(this.basedir, FileUtils.RECURSIVE | FileUtils.RETRY); } }
Example #11
Source File: ConfigServerTestUtils.java From spring-cloud-config with Apache License 2.0 | 5 votes |
public static String prepareLocalRepo(String baseDir, String buildDir, String repoPath, String checkoutDir) throws IOException { buildDir = baseDir + buildDir; new File(buildDir).mkdirs(); if (!repoPath.startsWith("/")) { repoPath = "/" + repoPath; } if (!repoPath.endsWith("/")) { repoPath = repoPath + "/"; } File source = new File(baseDir + "src/test/resources" + repoPath); File dest = new File(buildDir + repoPath); if (dest.exists()) { FileUtils.delete(dest, FileUtils.RECURSIVE | FileUtils.RETRY); } FileSystemUtils.copyRecursively(source, dest); File dotGit = new File(buildDir + repoPath + ".git"); File git = new File(buildDir + repoPath + "git"); if (git.exists()) { if (dotGit.exists()) { FileUtils.delete(dotGit, FileUtils.RECURSIVE); } } git.renameTo(dotGit); File local = new File(checkoutDir); if (local.exists()) { FileUtils.delete(local, FileUtils.RECURSIVE); } if (!buildDir.startsWith("/")) { buildDir = "./" + buildDir; } return "file:" + buildDir + repoPath; }
Example #12
Source File: ConfigServerTestUtils.java From spring-cloud-config with Apache License 2.0 | 5 votes |
public static String prepareLocalSvnRepo(String sourceDir, String checkoutDir) throws Exception { File sourceDirFile = new File(sourceDir); sourceDirFile.mkdirs(); File local = new File(checkoutDir); if (local.exists()) { FileUtils.delete(local, FileUtils.RECURSIVE); } local.mkdirs(); FileSystemUtils.copyRecursively(sourceDirFile, local); return StringUtils.cleanPath("file:///" + local.getAbsolutePath()); }
Example #13
Source File: MultipleJGitEnvironmentRepositoryIntegrationTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Before public void init() throws Exception { if (this.basedir.exists()) { FileUtils.delete(this.basedir, FileUtils.RECURSIVE); } ConfigServerTestUtils.deleteLocalRepo("config-copy"); }
Example #14
Source File: JGitEnvironmentRepositoryConcurrencyTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Before public void init() throws Exception { if (this.basedir.exists()) { FileUtils.delete(this.basedir, FileUtils.RECURSIVE); } ConfigServerTestUtils.deleteLocalRepo("config-copy"); }
Example #15
Source File: JGitEnvironmentRepository.java From spring-cloud-config with Apache License 2.0 | 5 votes |
private void deleteBaseDirIfExists() { if (getBasedir().exists()) { for (File file : getBasedir().listFiles()) { try { FileUtils.delete(file, FileUtils.RECURSIVE); } catch (IOException e) { throw new IllegalStateException("Failed to initialize base directory", e); } } } }
Example #16
Source File: GitPersistenceResourceTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@After public void deleteDirectoriesAndFiles() throws Exception { if (repository != null) { repository.close(); } FileUtils.delete(root.toFile(), FileUtils.RECURSIVE | FileUtils.RETRY); }
Example #17
Source File: AbstractGitRepositoryTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
protected void closeRepository() throws Exception{ if (repository != null) { repository.close(); } if (Files.exists(getDotGitDir())) { FileUtils.delete(getDotGitDir().toFile(), FileUtils.RECURSIVE | FileUtils.RETRY); } if(Files.exists(getDotGitIgnore())) { FileUtils.delete(getDotGitIgnore().toFile(), FileUtils.RECURSIVE | FileUtils.RETRY); } }
Example #18
Source File: AbstractParallelGitTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@After public void closeRepository() throws IOException { if(repo != null) repo.close(); if(repoDir != null && repoDir.exists()) FileUtils.delete(repoDir, FileUtils.RECURSIVE); }
Example #19
Source File: TestUtils.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
private static void prepareLocalRepo(String buildDir, String repoPath) throws IOException { File dotGit = new File(buildDir + repoPath + "/.git"); File git = new File(buildDir + repoPath + "/git"); if (git.exists()) { if (dotGit.exists()) { FileUtils.delete(dotGit, FileUtils.RECURSIVE); } } git.renameTo(dotGit); }
Example #20
Source File: UIGit.java From hop with Apache License 2.0 | 5 votes |
private void checkout( String path, String commitId, String postfix ) { InputStream stream = open( path, commitId ); File file = new File( directory + Const.FILE_SEPARATOR + path + postfix ); try { org.apache.commons.io.FileUtils.copyInputStreamToFile( stream, file ); stream.close(); } catch ( IOException e ) { e.printStackTrace(); } }
Example #21
Source File: TestUtils.java From spring-cloud-release-tools with Apache License 2.0 | 5 votes |
private static void prepareLocalRepo(String buildDir, String repoPath) throws IOException { File dotGit = new File(buildDir + repoPath + "/.git"); File git = new File(buildDir + repoPath + "/git"); if (git.exists()) { if (dotGit.exists()) { FileUtils.delete(dotGit, FileUtils.RECURSIVE); } } git.renameTo(dotGit); }
Example #22
Source File: TestUtils.java From spring-cloud-release-tools with Apache License 2.0 | 5 votes |
private static void prepareLocalRepo(String buildDir, String repoPath) throws IOException { File dotGit = new File(buildDir + repoPath + "/.git"); File git = new File(buildDir + repoPath + "/git"); if (git.exists()) { if (dotGit.exists()) { FileUtils.delete(dotGit, FileUtils.RECURSIVE); } } git.renameTo(dotGit); }
Example #23
Source File: TestUtils.java From spring-cloud-release-tools with Apache License 2.0 | 5 votes |
private static void prepareLocalRepo(String buildDir, String repoPath) throws IOException { File dotGit = new File(buildDir + repoPath + "/.git"); File git = new File(buildDir + repoPath + "/git"); if (git.exists()) { if (dotGit.exists()) { FileUtils.delete(dotGit, FileUtils.RECURSIVE); } } git.renameTo(dotGit); }
Example #24
Source File: GitRepo.java From spring-cloud-release-tools with Apache License 2.0 | 5 votes |
private void deleteBaseDirIfExists() { if (this.basedir.exists()) { try { FileUtils.delete(this.basedir, FileUtils.RECURSIVE); } catch (IOException e) { throw new IllegalStateException("Failed to initialize base directory", e); } } }
Example #25
Source File: TestUtils.java From spring-cloud-release-tools with Apache License 2.0 | 5 votes |
private static void prepareLocalRepo(String buildDir, String repoPath) throws IOException { File dotGit = new File(buildDir + repoPath + "/.git"); File git = new File(buildDir + repoPath + "/git"); if (git.exists()) { if (dotGit.exists()) { FileUtils.delete(dotGit, FileUtils.RECURSIVE); } } git.renameTo(dotGit); }
Example #26
Source File: GitUriTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testGitUrisForFile() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); File dir = createTempDir().toFile(); dir.mkdir(); File file = new File(dir, "test.txt"); file.createNewFile(); ServletTestingSupport.allowedPrefixes = dir.toString(); String projectName = getMethodName().concat("Project"); JSONObject project = createProjectOrLink(workspaceLocation, projectName, dir.toString()); String location = project.getString(ProtocolConstants.KEY_CONTENT_LOCATION); WebRequest request = getGetRequest(location); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject files = new JSONObject(response.getText()); assertNull(files.optString(GitConstants.KEY_STATUS, null)); assertNull(files.optString(GitConstants.KEY_DIFF, null)); assertNull(files.optString(GitConstants.KEY_DIFF, null)); assertNull(files.optString(GitConstants.KEY_COMMIT, null)); assertNull(files.optString(GitConstants.KEY_REMOTE, null)); assertNull(files.optString(GitConstants.KEY_TAG, null)); assertNull(files.optString(GitConstants.KEY_CLONE, null)); FileUtils.delete(dir, FileUtils.RECURSIVE); }
Example #27
Source File: GitTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@After public void tearDown() throws Exception { //close all repositories for (Repository repo : toClose) { repo.close(); } toClose.clear(); FileUtils.delete(gitDir, FileUtils.RECURSIVE); }
Example #28
Source File: GitRepo.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
private void deleteBaseDirIfExists() { if (this.basedir.exists()) { try { FileUtils.delete(this.basedir, FileUtils.RECURSIVE); } catch (IOException e) { throw new IllegalStateException("Failed to initialize base directory", e); } } }
Example #29
Source File: AbstractParallelGitTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@After public void closeRepository() throws IOException { if(repo != null) repo.close(); if(repoDir != null && repoDir.exists()) FileUtils.delete(repoDir, FileUtils.RECURSIVE); }
Example #30
Source File: RepositoryUtilsOpenRepositoryTest.java From ParallelGit with Apache License 2.0 | 4 votes |
@After public void tearDown() throws IOException { if(repo != null) repo.close(); FileUtils.delete(dir, FileUtils.RECURSIVE); }