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

x33g5p2x  于2022-01-28 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(68)

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

ResetCommand.setRef介绍

[英]Set the name of the Ref to reset to
[中]设置要重置为的Ref的名称

代码示例

代码示例来源:origin: spring-cloud/spring-cloud-config

private Ref resetHard(Git git, String label, String ref) {
  ResetCommand reset = git.reset();
  reset.setRef(ref);
  reset.setMode(ResetType.HARD);
  try {
    Ref resetRef = reset.call();
    if (resetRef != null) {
      this.logger.info(
          "Reset label " + label + " to version " + resetRef.getObjectId());
    }
    return resetRef;
  }
  catch (Exception ex) {
    String message = "Could not reset to remote for " + label + " (current ref="
        + ref + "), remote: " + git.getRepository().getConfig()
            .getString("remote", "origin", "url");
    warn(message, ex);
    return null;
  }
}

代码示例来源:origin: apache/incubator-gobblin

this.gitForPush.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD~1").call();
this.gitForPush.push().setForce(true).setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD~4").call();
this.gitForPush.push().setForce(true).setRemote("origin").setRefSpecs(this.masterRefSpec).call();

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

@Signature
public Memory reset(Environment env, ArrayMemory settings) throws GitAPIException {
  ResetCommand reset = getWrappedObject().reset();
  Memory mode = settings.valueOfIndex("mode");
  if (mode.isNotNull()) {
    reset.setMode(ResetCommand.ResetType.valueOf(mode.toString()));
  }
  Memory ref = settings.valueOfIndex("ref");
  if (ref.isNotNull()) {
    reset.setRef(ref.toString());
  }
  reset.disableRefLog(settings.valueOfIndex("disableRefLog").toBoolean());
  Memory paths = settings.valueOfIndex("paths");
  if (paths.isNotNull()) {
    ForeachIterator iterator = paths.getNewIterator(env);
    if (iterator != null) {
      while (iterator.next()) {
        reset.addPath(iterator.getValue().toString());
      }
    } else {
      reset.addPath(paths.toString());
    }
  }
  Ref call = reset.call();
  return GitUtils.valueOf(call);
}

代码示例来源:origin: apache/incubator-gobblin

.call();
this.git.reset().setMode(ResetCommand.ResetType.HARD).setRef(REMOTE_NAME + "/" + this.branchName).call();

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

private void resetSoftToParent() throws IOException,
    GitAPIException, CheckoutConflictException {
  Ref ref = repo.exactRef(Constants.ORIG_HEAD);
  ObjectId orig_head = ref == null ? null : ref.getObjectId();
  try (Git git = Git.wrap(repo)) {
    // we have already committed the cherry-picked commit.
    // what we need is to have changes introduced by this
    // commit to be on the index
    // resetting is a workaround
    git.reset().setMode(ResetType.SOFT)
        .setRef("HEAD~1").call(); //$NON-NLS-1$
  } finally {
    // set ORIG_HEAD back to where we started because soft
    // reset moved it
    repo.writeOrigHead(orig_head);
  }
}

代码示例来源:origin: stackoverflow.com

ResetCommand reset = new Git(repository).reset();
reset.setRef(Constants.HEAD);
reset.addPath("foo.txt");
reset.call();

代码示例来源:origin: Verigreen/verigreen

public void reset(String refToResetTo) {
  
  ResetCommand command = _git.reset();
  command.setRef(refToResetTo);
  command.setMode(ResetType.HARD);
  try {
    command.call();
  } catch (Throwable e) {
    throw new RuntimeException(String.format("Failed to reset to [%s]", refToResetTo), e);
  }
}

代码示例来源:origin: com.meltmedia.cadmium/cadmium-core

public void resetToRev(String revision) throws Exception {
 if(revision != null) {
  log.info("Resetting to sha {}", revision);
  git.reset().setMode(ResetType.HARD).setRef(revision).call();
 }
}

代码示例来源:origin: org.jboss.forge.addon/git-impl

@Override
public void resetHard(final Git repo, String newBase) throws GitAPIException
{
 repo.reset().setMode(ResetCommand.ResetType.HARD).setRef(newBase).call();
}

代码示例来源:origin: org.openmrs.maven.plugins/openmrs-sdk-maven-plugin

/**
 * @inheritDoc
 */
@Override
public void resetHard(Git git, RevCommit commit){
  try {
    git.reset().setMode(ResetCommand.ResetType.HARD).setRef(commit.getName()).call();
  } catch (GitAPIException e) {
    throw new RuntimeException("Failed to hard reset to commit "+commit.getShortMessage(), e);
  }
}

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

/**
 * Reset hard on HEAD.
 *
 * @throws GitAPIException
 */
public void rollback() throws GitAPIException {
  try (Git git = getGit()) {
    git.reset().setMode(ResetCommand.ResetType.HARD).setRef(HEAD).call();
  }
}

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

/**
 * Reset hard on HEAD.
 *
 * @throws GitAPIException
 */
public void rollback() throws GitAPIException {
  try (Git git = getGit()) {
    git.reset().setMode(ResetCommand.ResetType.HARD).setRef(HEAD).call();
  }
}

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

@Override
public void rollback() {
  super.rollback();
  try (Git git = repository.getGit()) {
    git.reset().setMode(ResetCommand.ResetType.HARD).setRef(Constants.HEAD).call();
  } catch (GitAPIException ex) {
    MGMT_OP_LOGGER.failedToStoreConfiguration(ex, file.getName());
  }
}

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

public void setRevisionTo(String ref) throws GitAPIException {
  this.clean();
  // reset repository to the desired reference
  ResetCommand reset = this.git.reset();
  reset.setMode(ResetType.HARD);
  reset.setRef(ref);
  reset.call();
}

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

@Override
public void rollback() {
  super.rollback();
  try (Git git = repository.getGit()) {
    git.reset().setMode(ResetCommand.ResetType.HARD).setRef(Constants.HEAD).call();
  } catch (GitAPIException ex) {
    MGMT_OP_LOGGER.failedToStoreConfiguration(ex, file.getName());
  }
}

代码示例来源: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: com.atlassian.labs/speakeasy-plugin

public File operateOn(Repository repo) throws Exception
  {
    Git git = new Git(repo);
    if (repo.getAllRefs().containsKey("refs/heads/master"))
    {
      git.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD").call();
      for (String path : git.status().call().getUntracked())
      {
        new File(repo.getWorkTree(), path).delete();
      }
    }
    return ZipWriter.addDirectoryContentsToJar(repo.getWorkTree(), ".git");
  }
});

代码示例来源:origin: org.jenkins-ci.plugins/scriptler

public String hardReset() throws IOException {
  final Repository repo = this.openRepository();
  final Git git = new Git(repo);
  if (repo.getRepositoryState().canResetHead()) {
    try {
      return git.reset().setMode(ResetType.HARD).setRef("master").call().getObjectId().name();
    } catch (CheckoutConflictException e) {
      throw new IOException("not able to perform a hard reset", e);
    } catch (GitAPIException e) {
      throw new IOException("problem executing reset command", e);
    }
  }
  return "";
}

代码示例来源:origin: robinst/git-merge-repos

private void resetToBranch() throws IOException, GitAPIException {
  Ref master = repository.getRef(Constants.R_HEADS + "master");
  if (master != null) {
    Git git = new Git(repository);
    git.reset().setMode(ResetType.HARD).setRef(master.getName()).call();
  }
}

代码示例来源:origin: danielflower/app-runner

private void gitUpdateFromOrigin() throws GitAPIException {
  git.fetch().setRemote("origin").call();
  git.reset().setMode(ResetCommand.ResetType.HARD).setRef("origin/master").call();
  this.contributors = getContributorsFromRepo();
}

相关文章