List of usage examples for org.eclipse.jgit.api Git rm
public RmCommand rm()
From source file:org.obiba.opal.core.cfg.OpalViewPersistenceStrategy.java
License:Open Source License
private void doWriteGitViews(@Nonnull String datasourceName, @Nonnull Iterable<View> views, @Nullable String comment) { File localRepo = null;//w w w. j av a 2s. c o m try { // Fetch or clone a tmp working directory localRepo = cloneDatasourceViewsGit(datasourceName); // Serialize all view files in the repo List<String> varFilesToRemove = Lists.newArrayList(); StringBuilder message = new StringBuilder(); for (View view : views) { doWriteGitView(localRepo, view, varFilesToRemove); if (message.length() > 0) { message.append(", "); } message.append(view.getName()); } // Push changes Git git = new Git(new FileRepository(new File(localRepo, ".git"))); for (String toRemove : varFilesToRemove) { git.rm().addFilepattern(toRemove).call(); } git.add().addFilepattern(".").call(); doCommitPush(git, Strings.isNullOrEmpty(comment) ? "Update " + message : comment); } catch (Exception e) { throw new RuntimeException("Failed writing views in git for datasource: " + datasourceName, e); } finally { if (localRepo != null) localRepo.delete(); } }
From source file:org.obiba.opal.core.cfg.OpalViewPersistenceStrategy.java
License:Open Source License
private void doRemoveGitView(@Nonnull String datasourceName, @Nonnull String viewName) { File localRepo = null;/*from w w w .j a v a 2 s .c om*/ try { localRepo = cloneDatasourceViewsGit(datasourceName); Git git = new Git(new FileRepository(new File(localRepo, ".git"))); git.rm().addFilepattern(viewName); doCommitPush(git, "Remove " + viewName); } catch (Exception e) { throw new RuntimeException( "Failed removing view '" + viewName + "' from git for datasource: " + datasourceName, e); } finally { if (localRepo != null) localRepo.delete(); } }
From source file:org.obiba.opal.core.vcs.command.OpalWriteViewsCommand.java
License:Open Source License
@Override public Iterable<PushResult> execute(Git git) { try {/*w w w . j a v a2 s. c o m*/ File localRepo = git.getRepository().getWorkTree(); List<String> varFilesToRemove = Lists.newArrayList(); StringBuilder message = new StringBuilder(); serializeAllViewFiles(localRepo, varFilesToRemove, message); String currentMessage = getCommitMessage(); setCommitMessage((Strings.isNullOrEmpty(currentMessage) ? "Update " : currentMessage + " ") + message); for (String toRemove : varFilesToRemove) { git.rm().addFilepattern(toRemove).call(); } git.add().addFilepattern(".").call(); return commitAndPush(git); } catch (IOException | GitAPIException e) { throw new GitException(e); } }
From source file:org.openengsb.connector.git.internal.GitServiceImpl.java
License:Apache License
@Override public CommitRef remove(String comment, File... file) { if (file.length == 0) { LOGGER.debug("No files to add in list"); return null; }/*from w w w .j a v a2 s .c o m*/ if (repository == null) { prepareWorkspace(); try { initRepository(); } catch (IOException e) { if (repository != null) { repository.close(); repository = null; } throw new ScmException(e); } } Git git = new Git(repository); RmCommand rm = git.rm(); try { for (File toCommit : file) { if (!toCommit.exists()) { throw new ScmException("File " + toCommit + " is not a valid file to commit."); } String filepattern = getRelativePath(toCommit.getAbsolutePath()); LOGGER.debug("Removing file {} in working directory from repository", filepattern); rm.addFilepattern(filepattern); } rm.call(); LOGGER.debug("Committing removed files with comment '{}'", comment); return new GitCommitRef(git.commit().setMessage(comment).call()); } catch (Exception e) { throw new ScmException(e); } }
From source file:org.wandora.application.tools.git.Commit.java
License:Open Source License
@Override public void execute(Wandora wandora, Context context) { try {//from www .j a v a 2 s.c om Git git = getGit(); if (git != null) { if (commitUI == null) { commitUI = new CommitUI(); } commitUI.openInDialog(); if (commitUI.wasAccepted()) { setDefaultLogger(); setLogTitle("Git commit"); log("Saving project."); saveWandoraProject(); log("Removing deleted files from local repository."); org.eclipse.jgit.api.Status status = git.status().call(); Set<String> missing = status.getMissing(); if (missing != null && !missing.isEmpty()) { for (String missingFile : missing) { git.rm().addFilepattern(missingFile).call(); } } log("Adding new files to local repository."); git.add().addFilepattern(".").call(); log("Committing changes to local repository."); String commitMessage = commitUI.getMessage(); if (commitMessage == null || commitMessage.length() == 0) { commitMessage = getDefaultCommitMessage(); log("No commit message provided. Using default message."); } git.commit().setMessage(commitMessage).call(); log("Ready."); } } else { logAboutMissingGitRepository(); } } catch (GitAPIException gae) { log(gae.toString()); } catch (NoWorkTreeException nwte) { log(nwte.toString()); } catch (IOException ioe) { log(ioe.toString()); } catch (TopicMapException tme) { log(tme.toString()); } catch (Exception e) { log(e); } setState(WAIT); }
From source file:org.wandora.application.tools.git.CommitPush.java
License:Open Source License
@Override public void execute(Wandora wandora, Context context) { try {/*from w w w . java 2 s . c om*/ Git git = getGit(); if (git != null) { if (isNotEmpty(getGitRemoteUrl())) { if (commitPushUI == null) { commitPushUI = new CommitPushUI(); } commitPushUI.setPassword(getPassword()); commitPushUI.setUsername(getUsername()); commitPushUI.openInDialog(); if (commitPushUI.wasAccepted()) { setDefaultLogger(); setLogTitle("Git commit and push"); saveWandoraProject(); log("Removing deleted files from local repository."); org.eclipse.jgit.api.Status status = git.status().call(); Set<String> missing = status.getMissing(); if (missing != null && !missing.isEmpty()) { for (String missingFile : missing) { git.rm().addFilepattern(missingFile).call(); } } log("Adding new files to the local repository."); git.add().addFilepattern(".").call(); log("Committing changes to the local repository."); String commitMessage = commitPushUI.getMessage(); if (commitMessage == null || commitMessage.length() == 0) { commitMessage = getDefaultCommitMessage(); log("No commit message provided. Using default message."); } git.commit().setMessage(commitMessage).call(); String username = commitPushUI.getUsername(); String password = commitPushUI.getPassword(); setUsername(username); setPassword(password); PushCommand push = git.push(); if (isNotEmpty(username)) { log("Setting push credentials."); CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider( username, password); push.setCredentialsProvider(credentialsProvider); } log("Pushing upstream."); push.call(); log("Ready."); } } else { log("Repository has no remote origin and can't be pushed. " + "Commit changes to the local repository using Commit to local... " + "To push changes to a remote repository initialize repository by cloning."); } } else { logAboutMissingGitRepository(); } } catch (GitAPIException gae) { log(gae.toString()); } catch (NoWorkTreeException nwte) { log(nwte.toString()); } catch (IOException ioe) { log(ioe.toString()); } catch (TopicMapException tme) { log(tme.toString()); } catch (Exception e) { log(e); } setState(WAIT); }
From source file:org.wso2.carbon.appfactory.repository.mgt.git.JGitAgent.java
License:Apache License
/** * Remove files from the working tree and from the index. If the deletion of the file had done by using other direct * file operation such as {@link org.apache.commons.io.FileUtils#deleteDirectory(java.io.File)}, use {@link * #add(String, boolean, java.io.File)} by passing the argument {@code update} as true * * @param filePattern repository-relative path of file to remove (with <code>/</code> as separator) * @param repositoryDirectory repository directory where .git exists. * @return success/*www . ja v a2s.c om*/ * @throws RepositoryMgtException if error while branching */ public boolean remove(String filePattern, File repositoryDirectory) throws RepositoryMgtException { try { Repository repository = getLocalRepository(repositoryDirectory); Git git = new Git(repository); git.rm().addFilepattern(filePattern).call(); return true; } catch (IOException e) { String msg = "Error while removing files due to " + e.getMessage() + " from IOException"; log.error(msg, e); throw new RepositoryMgtException(msg, e); } catch (GitAPIException e) { String msg = "Error while removing files due to " + e.getMessage() + " from IOException"; log.error(msg, e); throw new RepositoryMgtException(msg, e); } }