From da9db6b20c6203dae3f828adbd14218ea063ad91 Mon Sep 17 00:00:00 2001 From: Tobias Pfeifer Date: Thu, 11 Jul 2013 11:09:30 +0200 Subject: [PATCH] Enable to prepare interactive rebase and then start it explicitly Add Operation.PROCESS_STEPS to RebaseCommand to enable starting interactive rebase explicitly after rebase steps have been configured. Change-Id: I2d6f0de82010ea6523fbce6fb4501e847bdcdddc Signed-off-by: Tobias Pfeifer Signed-off-by: Matthias Sohn --- .../org/eclipse/jgit/api/RebaseCommand.java | 43 ++++++++++++++++++- .../org/eclipse/jgit/api/RebaseResult.java | 15 ++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index b8cbb9f04..e7c31da41 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -166,7 +166,11 @@ public class RebaseCommand extends GitCommand { /** * Aborts and resets the current rebase */ - ABORT; + ABORT, + /** + * Starts processing steps + */ + PROCESS_STEPS; } private Operation operation = Operation.BEGIN; @@ -183,6 +187,8 @@ public class RebaseCommand extends GitCommand { private InteractiveHandler interactiveHandler; + private boolean stopAfterInitialization = false; + /** * @param repo */ @@ -218,6 +224,8 @@ public class RebaseCommand extends GitCommand { } catch (IOException ioe) { throw new JGitInternalException(ioe.getMessage(), ioe); } + case PROCESS_STEPS: + // fall through case SKIP: // fall through case CONTINUE: @@ -234,6 +242,8 @@ public class RebaseCommand extends GitCommand { break; case BEGIN: RebaseResult res = initFilesAndRewind(); + if (stopAfterInitialization) + return RebaseResult.INTERACTIVE_PREPARED_RESULT; if (res != null) return res; } @@ -709,6 +719,12 @@ public class RebaseCommand extends GitCommand { } private void checkParameters() throws WrongRepositoryStateException { + if (this.operation == Operation.PROCESS_STEPS) { + if (rebaseState.getFile(DONE).exists()) + throw new WrongRepositoryStateException(MessageFormat.format( + JGitText.get().wrongRepositoryState, repo + .getRepositoryState().name())); + } if (this.operation != Operation.BEGIN) { // these operations are only possible while in a rebasing state switch (repo.getRepositoryState()) { @@ -923,11 +939,36 @@ public class RebaseCommand extends GitCommand { /** * Enables interactive rebase + *

+ * Does not stop after initialization of interactive rebase. This is + * equivalent to + * {@link RebaseCommand#runInteractively(InteractiveHandler, boolean) + * runInteractively(handler, false)}; + *

* * @param handler * @return this */ public RebaseCommand runInteractively(InteractiveHandler handler) { + return runInteractively(handler, false); + } + + /** + * Enables interactive rebase + *

+ * If stopAfterRebaseInteractiveInitialization is {@code true} the rebase + * stops after initialization of interactive rebase returning + * {@link RebaseResult#INTERACTIVE_PREPARED_RESULT} + *

+ * + * @param handler + * @param stopAfterRebaseInteractiveInitialization + * if {@code true} the rebase stops after initialization + * @return this instance + */ + public RebaseCommand runInteractively(InteractiveHandler handler, + final boolean stopAfterRebaseInteractiveInitialization) { + this.stopAfterInitialization = stopAfterRebaseInteractiveInitialization; this.interactiveHandler = handler; return this; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java index 59655570c..ff18adce4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, Mathias Kinzler + * Copyright (C) 2010, 2013, Mathias Kinzler * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -131,6 +131,16 @@ public class RebaseResult { public boolean isSuccessful() { return false; } + }, + + /** + * Interactive rebase has been prepared + */ + INTERACTIVE_PREPARED { + @Override + public boolean isSuccessful() { + return false; + } }; /** @@ -152,6 +162,9 @@ public class RebaseResult { static final RebaseResult NOTHING_TO_COMMIT_RESULT = new RebaseResult( Status.NOTHING_TO_COMMIT); + static final RebaseResult INTERACTIVE_PREPARED_RESULT = new RebaseResult( + Status.INTERACTIVE_PREPARED); + private final Status status; private final RevCommit currentCommit;