Example #1
0
 public Document undoLastChange(Document document) {
   try {
     final File docDir = getDirForDoc(document.getId());
     if (!docDir.exists()) {
       return null;
     } else {
       Git git = Git.open(docDir);
       Iterator<RevCommit> it = git.log().setMaxCount(2).call().iterator();
       if (it.hasNext()) {
         final RevCommit c = it.next(); // current version
       }
       if (it.hasNext()) {
         RevCommit c = it.next(); // previous version
         if (isUndo(git)) {
           git.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD~1").call();
         } else {
           git.branchCreate().setName("undo").setStartPoint(c).call();
           git.checkout().setName("undo").call();
         }
         return getDocument(document.getId());
       }
       return null;
     }
   } catch (IOException e) {
     throw new RuntimeException(e);
   } catch (NoHeadException e) {
     throw new RuntimeException(e);
   } catch (GitAPIException e) {
     throw new RuntimeException(e);
   }
 }
Example #2
0
 public static void resetRepoToCommit(File directory, String commitHash) throws GitException {
   try {
     Git git = openRepository(directory);
     git.reset().setMode(ResetCommand.ResetType.HARD).setRef(commitHash).call();
   } catch (GitAPIException e) {
     throw new GitException("Ref " + commitHash + " does not exist", e);
   }
 }
Example #3
0
  public void reset() {

    try {

      if (!git.status().call().isClean()) git.reset().setMode(ResetType.HARD).call();

      makeCheckout("master", false);
      git.branchDelete().setBranchNames(vmBranch).setForce(true).call();

    } catch (Exception e) {
      clean(e);
    }
  }
  public void reset(final int noOfCommitsToRevert, final String message) {
    final Repository repository = getRepository();
    final RevCommit commit =
        findCommit(Constants.HEAD + REVISION_STRING_DELIMITER + noOfCommitsToRevert, repository);
    if (commit == null) {
      return;
    }

    try {
      final Git git = new Git(repository);
      git.reset().setRef(commit.getName()).setMode(ResetType.HARD).call();
      // Commit changes
      commitAllChanges(message);
      LOGGER.info("Reset of last " + (noOfCommitsToRevert + 1) + " successful.");
    } catch (final Exception e) {
      throw new IllegalStateException("Reset did not succeed.", e);
    }
  }
Example #5
0
  private void reload(String botName) throws IOException, GitAPIException {
    log.info("Starting bot reload");
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository =
        builder.setGitDir(new File(arguments.getBasePath() + "/.git")).readEnvironment().build();
    log.info("Starting repository update");
    Git git = new Git(repository);
    git.reset().setMode(ResetCommand.ResetType.HARD).call();
    log.info("Reset complete");
    git.clean().call();
    log.info("Clean compete");
    git.fetch().call();
    log.info("Fetch complete");
    git.pull().call();
    log.info("Repository update finished");

    initBot(botName);
    log.info("Bot reloaded");
  }
Example #6
0
 public static void resetHard(final Git repo, String newBase) throws GitAPIException {
   repo.reset().setMode(ResetCommand.ResetType.HARD).setRef(newBase).call();
 }
 /**
  * Hard reset the repository. Makes the working directory and staging index content to exactly
  * match the Git repository.
  *
  * @throws CheckoutConflictException
  * @throws GitAPIException
  */
 public void hardReset() throws CheckoutConflictException, GitAPIException {
   ResetCommand resetCommand = git.reset();
   resetCommand.setMode(ResetType.HARD);
   resetCommand.call();
 }