summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Kinzler <mathias.kinzler@sap.com>2010-12-10 09:44:51 +0100
committerMathias Kinzler <mathias.kinzler@sap.com>2010-12-10 09:44:51 +0100
commit9b039b42e0ecf69640c5f1a34ee72a86dba3f1c2 (patch)
tree58eeb7353f0339158f89cb85f770d3ab4e47baa6
parent93a7b2b24d5486b2033ba4b692906c6c758f46ad (diff)
downloadjgit-9b039b42e0ecf69640c5f1a34ee72a86dba3f1c2.tar.gz
jgit-9b039b42e0ecf69640c5f1a34ee72a86dba3f1c2.zip
Rebase: abort on unknown/unsupported command in git-rebase-todo
This is needed to ensure interoperability with the command line: if the git-rebase-todo file was created manually (by git rebase -i in the command line), and any commands other than pick are used (reword, edit, fixup, squash) JGit must abort as it does not understand these commands yet. The same is true if an unknown command is found (e.g. due to a typo); this is the same behavior as shown by the command line. Change-Id: I2322014f69460361f7fc09da223e8a5c31f100dd Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java14
2 files changed, 20 insertions, 4 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
index dd812ee81a..9c8f4a7d10 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
@@ -48,6 +48,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import org.eclipse.jgit.api.RebaseCommand.Action;
import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.api.RebaseResult.Status;
import org.eclipse.jgit.api.errors.RefNotFoundException;
@@ -850,7 +851,14 @@ public class RebaseCommandTest extends RepositoryTestCase {
try {
String line = br.readLine();
while (line != null) {
- if (line.startsWith("pick "))
+ String actionToken = line.substring(0, line.indexOf(' '));
+ Action action = null;
+ try {
+ action = Action.parse(actionToken);
+ } catch (Exception e) {
+ // ignore
+ }
+ if (action != null)
count++;
line = br.readLine();
}
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 70cf702ec1..36c06702a9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
@@ -225,8 +225,6 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
List<Step> steps = loadSteps();
for (Step step : steps) {
- if (step.action != Action.PICK)
- continue;
popSteps(1);
Collection<ObjectId> ids = or.resolve(step.commit);
if (ids.size() != 1)
@@ -423,6 +421,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
String popCandidate = br.readLine();
if (popCandidate == null)
break;
+ if (popCandidate.charAt(0) == '#')
+ continue;
int spaceIndex = popCandidate.indexOf(' ');
boolean pop = false;
if (spaceIndex >= 0) {
@@ -686,6 +686,10 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
String actionToken = new String(buf, tokenBegin, nextSpace
- tokenBegin - 1);
tokenBegin = nextSpace;
+ if (actionToken.charAt(0) == '#') {
+ tokenCount = 3;
+ break;
+ }
Action action = Action.parse(actionToken);
if (action != null)
current = new Step(Action.parse(actionToken));
@@ -783,7 +787,11 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
static Action parse(String token) {
if (token.equals("pick") || token.equals("p"))
return PICK;
- return null;
+ throw new JGitInternalException(
+ MessageFormat
+ .format(
+ "Unknown or unsupported command \"{0}\", only \"pick\" is allowed",
+ token));
}
}