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

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

本文整理了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

@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();
}

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

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

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

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

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

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

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

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

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

public void clean() throws GitException {
  verifyGitRepository();
  try {
    jGitDelegate.clean()
      .setCleanDirectories(true)
      .call();
  } catch (Exception ex) {
    throw new GitException(ex);
  }  
}

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

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

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

/**
 * 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);
  }
}

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

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);
}

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

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();
  }
});

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

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);
}

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

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();
  }
});

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

@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;
  }
});

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

@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;
  }
});

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

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();

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

/**
 * 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);
  }
}

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

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

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

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

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

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);

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

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);

相关文章