@Signature public Set<String> clean(Environment env, ArrayMemory settings) throws GitAPIException { CleanCommand cleanCommand = getWrappedObject().clean(); if (settings != null && settings.isNotNull()) { if (settings.containsKey("cleanDirectories")) cleanCommand.setCleanDirectories(settings.valueOfIndex("cleanDirectories").toBoolean()); if (settings.containsKey("dryRun")) cleanCommand.setDryRun(settings.valueOfIndex("dryRun").toBoolean()); cleanCommand.setForce(settings.valueOfIndex("force").toBoolean()); cleanCommand.setIgnore(settings.valueOfIndex("ignore").toBoolean()); if (settings.containsKey("paths")) { Set<String> paths = new LinkedHashSet<>(); ForeachIterator iterator = settings.valueOfIndex("paths").getNewIterator(env); if (iterator == null) { paths.add(settings.valueOfIndex("paths").toString()); } else { while (iterator.next()) { paths.add(iterator.getValue().toString()); } } cleanCommand.setPaths(paths); } } return cleanCommand.call(); }
Set<String> removed = git.clean().setCleanDirectories(true).call(); for(String item : removed) { System.out.println("Removed: " + item);
Set<String> removed = git.clean().setCleanDirectories(true).call(); for(String item : removed) { System.out.println("Removed: " + item);
private void clean() throws NoWorkTreeException, GitAPIException { // remove untracked files CleanCommand clean = this.git.clean(); clean.setCleanDirectories(true); clean.call(); }
public Set<String> cleanDirectories(Git git) throws GitAPIException { return git.clean().setCleanDirectories(true).call(); }
public void clean() throws GitException { verifyGitRepository(); try { jGitDelegate.clean() .setCleanDirectories(true) .call(); } catch (Exception ex) { throw new GitException(ex); } }
public void hardReset() throws Exception { git.reset().setMode(ResetType.HARD).call(); git.clean().call(); }
/** * Clean the current modifications of the repository * * @param repositoryDirectory */ public static void clean(Path repositoryDirectory) { Git repository = null; try { repository = Git.open(repositoryDirectory.resolve(".git").toFile()); CleanCommand cleanCommand = repository.clean(); cleanCommand.setIgnore(true); cleanCommand.call(); } catch (IOException e) { throw new GitException("Unable to open the git repository", e); } catch (GitAPIException e) { throw new GitException("Unable to clean the git repository", e); } finally { close(repository); } }
protected void setRevisionTo(String ref) throws GitAPIException { git.clean().setForce(true).setCleanDirectories(true).call(); git.reset() .setMode(ResetCommand.ResetType.HARD) .setRef(ref) .call(); LOGGER.debug("Switched to commit {}", ref); }
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(UIText.CleanRepositoryPage_findingItems, IProgressMonitor.UNKNOWN); Git git = Git.wrap(repository); CleanCommand command = git.clean().setDryRun(true); command.setCleanDirectories(cleanDirectories); command.setIgnore(!includeIgnored); try { final Set<String> paths = command.call(); getShell().getDisplay().syncExec(new Runnable() { public void run() { cleanTable.setInput(paths); } }); } catch (GitAPIException ex) { Activator.logError("cannot call clean command!", ex); //$NON-NLS-1$ } monitor.done(); } });
protected void doClean(Exchange exchange, String operation) throws Exception { Set<String> result = null; try { if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) { git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call(); } result = git.clean().setCleanDirectories(true).call(); } catch (Exception e) { LOG.error("There was an error in Git {} operation", operation); throw e; } updateExchange(exchange, result); }
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(UIText.CleanRepositoryPage_cleaningItems, IProgressMonitor.UNKNOWN); Git git = Git.wrap(repository); CleanCommand command = git.clean().setDryRun(false); command.setCleanDirectories(cleanDirectories); command.setIgnore(!includeIgnored); command.setPaths(itemsToClean); try { command.call(); } catch (GitAPIException ex) { Activator.logError("cannot call clean command!", ex); //$NON-NLS-1$ } try { IProject[] projects = ProjectUtil.getProjectsContaining(repository, itemsToClean); ProjectUtil.refreshResources(projects, new SubProgressMonitor(monitor, 1)); } catch (CoreException e) { // could not refresh... not a "real" problem } monitor.done(); } });
@Override public Void call() { try { LOGGER.info("Undo local changes due to failure of git operations"); try { git.rebase().setOperation(RebaseCommand.Operation.ABORT).call(); } catch (WrongRepositoryStateException e) { // ignore rebasing exception when in wrong state } final String remoteBranch = Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + '/' + git.getRepository().getBranch(); git.reset().setMode(ResetType.HARD).setRef(remoteBranch).call(); git.clean().setCleanDirectories(true).call(); try { final ObjectId head = git.getRepository().resolve(Constants.HEAD); LOGGER.info("Undo local changes completed. HEAD is " + head.getName()); } catch (final Exception e) { LOGGER.warn("Failed to fetch HEAD", e); } } catch (final Exception e) { LOGGER.error("Unable to undo changes", e); } return null; } });
@Override public Void call() { try { LOGGER.info("Undo local changes due to failure of git operations"); try { git.rebase().setOperation(RebaseCommand.Operation.ABORT).call(); } catch (WrongRepositoryStateException e) { // ignore rebasing exception when in wrong state } final String remoteBranch = Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + '/' + git.getRepository().getBranch(); git.reset().setMode(ResetType.HARD).setRef(remoteBranch).call(); git.clean().setCleanDirectories(true).call(); try { final ObjectId head = git.getRepository().resolve(Constants.HEAD); LOGGER.info("Undo local changes completed. HEAD is " + head.getName()); } catch (final Exception e) { LOGGER.warn("Failed to fetch HEAD", e); } } catch (final Exception e) { LOGGER.error("Unable to undo changes", e); } return null; } });
String remoteCommit = remoteObjectId.getName(); if (!localCommit.equals(remoteCommit)) { git.clean().setCleanDirectories(true).call(); git.checkout().setName("HEAD").setForce(true).call(); git.checkout().setName(branch).setForce(true).call();
/** * clean. * * @param cleanSubmodule flag to add extra -f * @throws hudson.plugins.git.GitException if underlying git operation fails. */ @Override public void clean(boolean cleanSubmodule) throws GitException { try (Repository repo = getRepository()) { Git git = git(repo); git.reset().setMode(HARD).call(); git.clean().setCleanDirectories(true).setIgnore(false).setForce(cleanSubmodule).call(); } catch (GitAPIException e) { throw new GitException(e); } }
try { git.clean().setCleanDirectories(true).call(); // to remove not-tracked files
Set<String> removedFiles = git.clean().setCleanDirectories(true).call(); for (String removedFile : removedFiles) { log.debug("srcdeps: Removed an unstaged file [{}]", removedFile);
git.clean(); if (!isLocalGitRepository(gitConfig.getRepository())) { String remote = getRemoteName(gitConfig.getRepository()); config.setString("remote", remoteName, "fetch", "+" + R_HEADS + "*:" + R_REMOTES + remoteName + "/*"); config.save(); git.clean(); git.pull().setRemote(remoteName).setRemoteBranchName(branch).setStrategy(MergeStrategy.RESOLVE).call(); checkoutToSelectedBranch(git);
git.clean(); if (!isLocalGitRepository(gitConfig.getRepository())) { String remote = getRemoteName(gitConfig.getRepository()); config.setString("remote", remoteName, "fetch", "+" + R_HEADS + "*:" + R_REMOTES + remoteName + "/*"); config.save(); git.clean(); git.pull().setRemote(remoteName).setRemoteBranchName(branch).setStrategy(MergeStrategy.RESOLVE).call(); checkoutToSelectedBranch(git);