org.eclipse.jgit.api.RmCommand Java Examples
The following examples show how to use
org.eclipse.jgit.api.RmCommand.
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: 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 #2
Source File: GitContentRepository.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void removeContent(ContentReference reference) { final Path realFile = getDeploymentContentFile(reference.getHash()); super.removeContent(reference); if (!Files.exists(realFile)) { try (Git git = gitRepository.getGit()) { Set<String> deletedFiles = git.status().call().getMissing(); RmCommand rmCommand = git.rm(); for (String file : deletedFiles) { rmCommand.addFilepattern(file); } rmCommand.addFilepattern(gitRepository.getPattern(realFile)).call(); } catch (GitAPIException ex) { throw new RuntimeException(ex); } } }
Example #3
Source File: GitProctorTest.java From proctor with Apache License 2.0 | 5 votes |
/** * commit all changes in working tree. * <p> * This is equivalent to the following in git (written in C) * $ git add . * $ git commit -m $message */ private String commitAllWorkingTreeChanges(final String message) throws GitAPIException { final RmCommand rmCommand = git.rm(); git.status().call().getMissing().forEach(rmCommand::addFilepattern); rmCommand.call(); git.add().addFilepattern(".").call(); return git.commit().setMessage(message).call().getId().getName(); }
Example #4
Source File: GitStatusTest.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test public void testFileLogFromStatus() throws Exception { createWorkspace(SimpleMetaStore.DEFAULT_WORKSPACE_NAME); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo JSONObject clone = clone(clonePath); String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); // get project/folder metadata WebRequest request = getGetRequest(cloneContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject folder = new JSONObject(response.getText()); // add new files to the local repository so they can be deleted and removed in the test later on // missing String missingFileName = "missing.txt"; request = getPutFileRequest(folder.getString(ProtocolConstants.KEY_LOCATION) + missingFileName, "you'll miss me"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject missingTxt = getChild(folder, missingFileName); addFile(missingTxt); String removedFileName = "removed.txt"; request = getPutFileRequest(folder.getString(ProtocolConstants.KEY_LOCATION) + removedFileName, "I'll be removed"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject removedTxt = getChild(folder, removedFileName); addFile(removedTxt); // git section for the folder JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "committing all changes", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // make the file missing deleteFile(missingTxt); // remove the file Repository repository = getRepositoryForContentLocation(cloneContentLocation); Git git = Git.wrap(repository); RmCommand rm = git.rm(); rm.addFilepattern(removedFileName); rm.call(); // untracked file String untrackedFileName = "untracked.txt"; request = getPostFilesRequest(folder.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON(untrackedFileName).toString(), untrackedFileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); // added file String addedFileName = "added.txt"; request = getPostFilesRequest(folder.getString(ProtocolConstants.KEY_LOCATION), getNewFileJSON(addedFileName).toString(), addedFileName); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); JSONObject addedTxt = getChild(folder, addedFileName); addFile(addedTxt); // changed file JSONObject testTxt = getChild(folder, "test.txt"); modifyFile(testTxt, "change"); addFile(testTxt); // modified file modifyFile(testTxt, "second change, in working tree"); // get status assertStatus(new StatusResult().setAddedNames(addedFileName).setAddedLogLengths(0).setChangedNames("test.txt").setChangedLogLengths(1).setMissingNames(missingFileName).setMissingLogLengths(1).setModifiedNames("test.txt").setModifiedLogLengths(1).setRemovedNames(removedFileName).setRemovedLogLengths(1).setUntrackedNames(untrackedFileName).setUntrackedLogLengths(0), folder.getJSONObject(GitConstants.KEY_GIT).getString(GitConstants.KEY_STATUS)); } }