org.eclipse.jgit.api.Git.clean()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(193)

本文整理了Java中org.eclipse.jgit.api.Git.clean()方法的一些代码示例,展示了Git.clean()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Git.clean()方法的具体详情如下:
包路径:org.eclipse.jgit.api.Git
类名称:Git
方法名:clean

Git.clean介绍

[英]Return a command object to execute a clean command
[中]返回命令对象以执行清除命令

代码示例

代码示例来源:origin: jphp-group/jphp

  1. @Signature
  2. public Set<String> clean(Environment env, ArrayMemory settings) throws GitAPIException {
  3. CleanCommand cleanCommand = getWrappedObject().clean();
  4. if (settings != null && settings.isNotNull()) {
  5. if (settings.containsKey("cleanDirectories"))
  6. cleanCommand.setCleanDirectories(settings.valueOfIndex("cleanDirectories").toBoolean());
  7. if (settings.containsKey("dryRun"))
  8. cleanCommand.setDryRun(settings.valueOfIndex("dryRun").toBoolean());
  9. cleanCommand.setForce(settings.valueOfIndex("force").toBoolean());
  10. cleanCommand.setIgnore(settings.valueOfIndex("ignore").toBoolean());
  11. if (settings.containsKey("paths")) {
  12. Set<String> paths = new LinkedHashSet<>();
  13. ForeachIterator iterator = settings.valueOfIndex("paths").getNewIterator(env);
  14. if (iterator == null) {
  15. paths.add(settings.valueOfIndex("paths").toString());
  16. } else {
  17. while (iterator.next()) {
  18. paths.add(iterator.getValue().toString());
  19. }
  20. }
  21. cleanCommand.setPaths(paths);
  22. }
  23. }
  24. return cleanCommand.call();
  25. }

代码示例来源:origin: centic9/jgit-cookbook

  1. Set<String> removed = git.clean().setCleanDirectories(true).call();
  2. for(String item : removed) {
  3. System.out.println("Removed: " + item);

代码示例来源:origin: centic9/jgit-cookbook

  1. Set<String> removed = git.clean().setCleanDirectories(true).call();
  2. for(String item : removed) {
  3. System.out.println("Removed: " + item);

代码示例来源:origin: eclipse/winery

  1. private void clean() throws NoWorkTreeException, GitAPIException {
  2. // remove untracked files
  3. CleanCommand clean = this.git.clean();
  4. clean.setCleanDirectories(true);
  5. clean.call();
  6. }

代码示例来源:origin: com.societegenerale.ci-droid.tasks-consumer/ci-droid-tasks-consumer-infrastructure

  1. public Set<String> cleanDirectories(Git git) throws GitAPIException {
  2. return git.clean().setCleanDirectories(true).call();
  3. }

代码示例来源:origin: org.hudsonci.plugins/git

  1. public void clean() throws GitException {
  2. verifyGitRepository();
  3. try {
  4. jGitDelegate.clean()
  5. .setCleanDirectories(true)
  6. .call();
  7. } catch (Exception ex) {
  8. throw new GitException(ex);
  9. }
  10. }

代码示例来源:origin: com.centurylink.mdw/mdw-common

  1. public void hardReset() throws Exception {
  2. git.reset().setMode(ResetType.HARD).call();
  3. git.clean().call();
  4. }

代码示例来源:origin: alien4cloud/alien4cloud

  1. /**
  2. * Clean the current modifications of the repository
  3. *
  4. * @param repositoryDirectory
  5. */
  6. public static void clean(Path repositoryDirectory) {
  7. Git repository = null;
  8. try {
  9. repository = Git.open(repositoryDirectory.resolve(".git").toFile());
  10. CleanCommand cleanCommand = repository.clean();
  11. cleanCommand.setIgnore(true);
  12. cleanCommand.call();
  13. } catch (IOException e) {
  14. throw new GitException("Unable to open the git repository", e);
  15. } catch (GitAPIException e) {
  16. throw new GitException("Unable to clean the git repository", e);
  17. } finally {
  18. close(repository);
  19. }
  20. }

代码示例来源:origin: eclipse/winery

  1. protected void setRevisionTo(String ref) throws GitAPIException {
  2. git.clean().setForce(true).setCleanDirectories(true).call();
  3. git.reset()
  4. .setMode(ResetCommand.ResetType.HARD)
  5. .setRef(ref)
  6. .call();
  7. LOGGER.debug("Switched to commit {}", ref);
  8. }

代码示例来源:origin: org.eclipse.egit/ui

  1. public void run(IProgressMonitor monitor) throws InvocationTargetException,
  2. InterruptedException {
  3. monitor.beginTask(UIText.CleanRepositoryPage_findingItems, IProgressMonitor.UNKNOWN);
  4. Git git = Git.wrap(repository);
  5. CleanCommand command = git.clean().setDryRun(true);
  6. command.setCleanDirectories(cleanDirectories);
  7. command.setIgnore(!includeIgnored);
  8. try {
  9. final Set<String> paths = command.call();
  10. getShell().getDisplay().syncExec(new Runnable() {
  11. public void run() {
  12. cleanTable.setInput(paths);
  13. }
  14. });
  15. } catch (GitAPIException ex) {
  16. Activator.logError("cannot call clean command!", ex); //$NON-NLS-1$
  17. }
  18. monitor.done();
  19. }
  20. });

代码示例来源:origin: org.apache.camel/camel-git

  1. protected void doClean(Exchange exchange, String operation) throws Exception {
  2. Set<String> result = null;
  3. try {
  4. if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
  5. git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
  6. }
  7. result = git.clean().setCleanDirectories(true).call();
  8. } catch (Exception e) {
  9. LOG.error("There was an error in Git {} operation", operation);
  10. throw e;
  11. }
  12. updateExchange(exchange, result);
  13. }

代码示例来源:origin: org.eclipse.egit/ui

  1. public void run(IProgressMonitor monitor) throws InvocationTargetException,
  2. InterruptedException {
  3. monitor.beginTask(UIText.CleanRepositoryPage_cleaningItems, IProgressMonitor.UNKNOWN);
  4. Git git = Git.wrap(repository);
  5. CleanCommand command = git.clean().setDryRun(false);
  6. command.setCleanDirectories(cleanDirectories);
  7. command.setIgnore(!includeIgnored);
  8. command.setPaths(itemsToClean);
  9. try {
  10. command.call();
  11. } catch (GitAPIException ex) {
  12. Activator.logError("cannot call clean command!", ex); //$NON-NLS-1$
  13. }
  14. try {
  15. IProject[] projects = ProjectUtil.getProjectsContaining(repository, itemsToClean);
  16. ProjectUtil.refreshResources(projects, new SubProgressMonitor(monitor, 1));
  17. } catch (CoreException e) {
  18. // could not refresh... not a "real" problem
  19. }
  20. monitor.done();
  21. }
  22. });

代码示例来源:origin: com.indeed/proctor-store-git

  1. @Override
  2. public Void call() {
  3. try {
  4. LOGGER.info("Undo local changes due to failure of git operations");
  5. try {
  6. git.rebase().setOperation(RebaseCommand.Operation.ABORT).call();
  7. } catch (WrongRepositoryStateException e) {
  8. // ignore rebasing exception when in wrong state
  9. }
  10. final String remoteBranch = Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + '/' + git.getRepository().getBranch();
  11. git.reset().setMode(ResetType.HARD).setRef(remoteBranch).call();
  12. git.clean().setCleanDirectories(true).call();
  13. try {
  14. final ObjectId head = git.getRepository().resolve(Constants.HEAD);
  15. LOGGER.info("Undo local changes completed. HEAD is " + head.getName());
  16. } catch (final Exception e) {
  17. LOGGER.warn("Failed to fetch HEAD", e);
  18. }
  19. } catch (final Exception e) {
  20. LOGGER.error("Unable to undo changes", e);
  21. }
  22. return null;
  23. }
  24. });

代码示例来源:origin: indeedeng/proctor

  1. @Override
  2. public Void call() {
  3. try {
  4. LOGGER.info("Undo local changes due to failure of git operations");
  5. try {
  6. git.rebase().setOperation(RebaseCommand.Operation.ABORT).call();
  7. } catch (WrongRepositoryStateException e) {
  8. // ignore rebasing exception when in wrong state
  9. }
  10. final String remoteBranch = Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + '/' + git.getRepository().getBranch();
  11. git.reset().setMode(ResetType.HARD).setRef(remoteBranch).call();
  12. git.clean().setCleanDirectories(true).call();
  13. try {
  14. final ObjectId head = git.getRepository().resolve(Constants.HEAD);
  15. LOGGER.info("Undo local changes completed. HEAD is " + head.getName());
  16. } catch (final Exception e) {
  17. LOGGER.warn("Failed to fetch HEAD", e);
  18. }
  19. } catch (final Exception e) {
  20. LOGGER.error("Unable to undo changes", e);
  21. }
  22. return null;
  23. }
  24. });

代码示例来源:origin: io.fabric8/fabric-git

  1. String remoteCommit = remoteObjectId.getName();
  2. if (!localCommit.equals(remoteCommit)) {
  3. git.clean().setCleanDirectories(true).call();
  4. git.checkout().setName("HEAD").setForce(true).call();
  5. git.checkout().setName(branch).setForce(true).call();

代码示例来源:origin: jenkinsci/git-client-plugin

  1. /**
  2. * clean.
  3. *
  4. * @param cleanSubmodule flag to add extra -f
  5. * @throws hudson.plugins.git.GitException if underlying git operation fails.
  6. */
  7. @Override
  8. public void clean(boolean cleanSubmodule) throws GitException {
  9. try (Repository repo = getRepository()) {
  10. Git git = git(repo);
  11. git.reset().setMode(HARD).call();
  12. git.clean().setCleanDirectories(true).setIgnore(false).setForce(cleanSubmodule).call();
  13. } catch (GitAPIException e) {
  14. throw new GitException(e);
  15. }
  16. }

代码示例来源:origin: jboss-fuse/fabric8

  1. try {
  2. git.clean().setCleanDirectories(true).call(); // to remove not-tracked files

代码示例来源:origin: org.srcdeps.core/srcdeps-core

  1. Set<String> removedFiles = git.clean().setCleanDirectories(true).call();
  2. for (String removedFile : removedFiles) {
  3. log.debug("srcdeps: Removed an unstaged file [{}]", removedFile);

代码示例来源:origin: org.wildfly.core/wildfly-server

  1. git.clean();
  2. if (!isLocalGitRepository(gitConfig.getRepository())) {
  3. String remote = getRemoteName(gitConfig.getRepository());
  4. config.setString("remote", remoteName, "fetch", "+" + R_HEADS + "*:" + R_REMOTES + remoteName + "/*");
  5. config.save();
  6. git.clean();
  7. git.pull().setRemote(remoteName).setRemoteBranchName(branch).setStrategy(MergeStrategy.RESOLVE).call();
  8. checkoutToSelectedBranch(git);

代码示例来源:origin: wildfly/wildfly-core

  1. git.clean();
  2. if (!isLocalGitRepository(gitConfig.getRepository())) {
  3. String remote = getRemoteName(gitConfig.getRepository());
  4. config.setString("remote", remoteName, "fetch", "+" + R_HEADS + "*:" + R_REMOTES + remoteName + "/*");
  5. config.save();
  6. git.clean();
  7. git.pull().setRemote(remoteName).setRemoteBranchName(branch).setStrategy(MergeStrategy.RESOLVE).call();
  8. checkoutToSelectedBranch(git);

相关文章