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

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

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

Git.stashApply介绍

[英]Returs a command object used to apply a stashed commit
[中]Returs用于应用隐藏提交的命令对象

代码示例

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

@Signature
public Memory stashApply(ArrayMemory settings) throws GitAPIException {
  StashApplyCommand command = getWrappedObject().stashApply();
  if (settings != null) {
    command.setApplyIndex(settings.valueOfIndex("applyIndex").toBoolean());
    command.setApplyUntracked(settings.valueOfIndex("applyUntracked").toBoolean());
    Memory stashRef = settings.valueOfIndex("stashRef");
    if (stashRef.isNotNull()) {
      command.setStashRef(stashRef.toString());
    }
    Memory strategy = settings.valueOfIndex("strategy");
    if (strategy.isNotNull()) {
      command.setStrategy(MergeStrategy.get(strategy.toString()));
    }
  }
  return GitUtils.valueOf(command.call());
}

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

System.out.println("StashDrop returned: " + call);
ObjectId applied = git.stashApply().setStashRef(stash.getName()).call();
System.out.println("Applied 2nd stash as: " + applied);

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

System.out.println("StashDrop returned: " + call);
ObjectId applied = git.stashApply().setStashRef(stash.getName()).call();
System.out.println("Applied 2nd stash as: " + applied);

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

private boolean autoStashApply() throws IOException, GitAPIException {
  boolean conflicts = false;
  if (rebaseState.getFile(AUTOSTASH).exists()) {
    String stash = rebaseState.readFile(AUTOSTASH);
    try (Git git = Git.wrap(repo)) {
      git.stashApply().setStashRef(stash)
          .ignoreRepositoryState(true).setStrategy(strategy)
          .call();
    } catch (StashApplyFailureException e) {
      conflicts = true;
      try (RevWalk rw = new RevWalk(repo)) {
        ObjectId stashId = repo.resolve(stash);
        RevCommit commit = rw.parseCommit(stashId);
        updateStashRef(commit, commit.getAuthorIdent(),
            commit.getShortMessage());
      }
    }
  }
  return conflicts;
}

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

@Override
public void stashApply(final Git repo, String... stashRef) throws GitAPIException
{
 if (stashRef.length >= 1 && !Strings.isNullOrEmpty(stashRef[0]))
 {
   repo.stashApply().setStashRef(stashRef[0]).call();
 }
 else
 {
   repo.stashApply().call();
 }
}

代码示例来源:origin: Refactoring-Bot/Refactoring-Bot

/**
 * This method stashes all changes since the last commit.
 * 
 * @param gitConfig
 * @throws GitWorkflowException
 */
public void stashChanges(GitConfiguration gitConfig) throws GitWorkflowException {
  try (Git git = Git.open(new File(botConfig.getBotRefactoringDirectory() + gitConfig.getConfigurationId()))) {
    // Open git folder
    // Stash changes
    git.stashApply().call();
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
    throw new GitWorkflowException("Faild to stash changes!");
  }
}

代码示例来源:origin: org.apereo.cas/cas-mgmt-support-version-control

private Collection<String> applyStashIfNeeded() throws GitAPIException {
  if (!git.stashList().call().isEmpty()) {
    try {
      git.stashApply().call();
    } catch (final Exception e) {
      val conflicts = git.status().call().getConflicting();
      git.close();
      return conflicts;
    }
  }
  return new HashSet<>();
}

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

/**
 * Clean up if something went wrong
 *
 * @param path
 * @param moduleName
 * @throws IllegalStateException
 */
private void cleanUp(String path, String moduleName) throws IllegalStateException {
  try {
    Repository localRepo = gitHelper.getLocalRepository(path);
    Git git = new Git(localRepo);
    if(!localRepo.getBranch().equals(userBranch)){
      checkoutBranch(git, userBranch);
      if(stash != null){ git.stashApply().setStashRef(stash.getName()).call(); }
      deleteTempBranch(git, SDK_DASH + serverId);
    } else if(isTempBranchCreated(git)){
      if(stash != null){ git.stashApply().setStashRef(stash.getName()).call(); }
      deleteTempBranch(git, SDK_DASH + serverId);
    }
  } catch (Exception e) {
    throw new IllegalStateException(String.format(CLEAN_UP_ERROR_MESSAGE, userBranch, moduleName), e);
  }
}

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

public static void applyStashThenDrop(Path repositoryDirectory, String stashId) {
  Git git = null;
  try {
    git = Git.open(repositoryDirectory.toFile());
    int stashIndex = 0;
    Collection<RevCommit> stashes = git.stashList().call();
    for (RevCommit stash : stashes) {
      if (stash.getFullMessage().equals(stashId)) {
        git.stashApply().setStashRef(stash.getName()).call();
        git.stashDrop().setStashRef(stashIndex).call();
        log.debug("Stash <" + stashId + ">  applied/dropped on <" + repositoryDirectory + ">");
        break;
      }
      stashIndex++;
    }
  } catch (IOException | GitAPIException e) {
    throw new GitException("Failed to apply then drop stash", e);
  } finally {
    close(git);
  }
}

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

/**
 * Pull from upstream
 *
 * @param git
 * @param stash
 * @param newBranch
 * @param previousBranch
 * @throws Exception
 */
private void pullFromRemoteUpstream(Git git, RevCommit stash, String newBranch, String previousBranch) throws Exception {
  try {
    PullCommand pull = git.pull()
      .setRebase(true)
      .setRemote(UPSTREAM)
      .setRemoteBranchName(branch);
    PullResult pullResult = pull.call();
    if(!pullResult.isSuccessful()){
      rebaseAbort(git);
      checkoutBranch(git, previousBranch);
      if (stash != null) { git.stashApply().setStashRef(stash.getName()).call(); }
      deleteTempBranch(git, newBranch);
      throw new Exception(CONFLICT_MESSAGE_REASON);
    }
  } catch (GitAPIException e) {
    throw new Exception(PULL_COMMAND_PROBLEM_REASON, e);
  }
}

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

private boolean autoStashApply() throws IOException, GitAPIException {
  boolean conflicts = false;
  if (rebaseState.getFile(AUTOSTASH).exists()) {
    String stash = rebaseState.readFile(AUTOSTASH);
    try {
      Git.wrap(repo).stashApply().setStashRef(stash)
          .ignoreRepositoryState(true).setStrategy(strategy)
          .call();
    } catch (StashApplyFailureException e) {
      conflicts = true;
      try (RevWalk rw = new RevWalk(repo)) {
        ObjectId stashId = repo.resolve(stash);
        RevCommit commit = rw.parseCommit(stashId);
        updateStashRef(commit, commit.getAuthorIdent(),
            commit.getShortMessage());
      }
    }
  }
  return conflicts;
}

代码示例来源:origin: berlam/github-bucket

private boolean autoStashApply() throws IOException, GitAPIException {
  boolean conflicts = false;
  if (rebaseState.getFile(AUTOSTASH).exists()) {
    String stash = rebaseState.readFile(AUTOSTASH);
    try (Git git = Git.wrap(repo)) {
      git.stashApply().setStashRef(stash)
          .ignoreRepositoryState(true).setStrategy(strategy)
          .call();
    } catch (StashApplyFailureException e) {
      conflicts = true;
      try (RevWalk rw = new RevWalk(repo)) {
        ObjectId stashId = repo.resolve(stash);
        RevCommit commit = rw.parseCommit(stashId);
        updateStashRef(commit, commit.getAuthorIdent(),
            commit.getShortMessage());
      }
    }
  }
  return conflicts;
}

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

if (stash != null) {
  try {
    git.stashApply().setStashRef(stash.getName()).call();
    checkoutBranch(git, userBranch);
    mergeWithNewBranch(git, newBranchFull);
    git.reset().setMode(ResetCommand.ResetType.HARD).setRef(userBranch).call();
    checkoutBranch(git, userBranch);
    git.stashApply().setStashRef(stash.getName()).call();
    deleteTempBranch(git, newBranch);
    throw new Exception(CONFLICT_MESSAGE_REASON);

相关文章