Browse Source

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>
stable-0.10
Mathias Kinzler 14 years ago
parent
commit
9b039b42e0
  1. 10
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
  2. 14
      org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java

10
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.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import org.eclipse.jgit.api.RebaseCommand.Action;
import org.eclipse.jgit.api.RebaseCommand.Operation; import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.api.RebaseResult.Status; import org.eclipse.jgit.api.RebaseResult.Status;
import org.eclipse.jgit.api.errors.RefNotFoundException; import org.eclipse.jgit.api.errors.RefNotFoundException;
@ -850,7 +851,14 @@ public class RebaseCommandTest extends RepositoryTestCase {
try { try {
String line = br.readLine(); String line = br.readLine();
while (line != null) { 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++; count++;
line = br.readLine(); line = br.readLine();
} }

14
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java

@ -225,8 +225,6 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
List<Step> steps = loadSteps(); List<Step> steps = loadSteps();
for (Step step : steps) { for (Step step : steps) {
if (step.action != Action.PICK)
continue;
popSteps(1); popSteps(1);
Collection<ObjectId> ids = or.resolve(step.commit); Collection<ObjectId> ids = or.resolve(step.commit);
if (ids.size() != 1) if (ids.size() != 1)
@ -423,6 +421,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
String popCandidate = br.readLine(); String popCandidate = br.readLine();
if (popCandidate == null) if (popCandidate == null)
break; break;
if (popCandidate.charAt(0) == '#')
continue;
int spaceIndex = popCandidate.indexOf(' '); int spaceIndex = popCandidate.indexOf(' ');
boolean pop = false; boolean pop = false;
if (spaceIndex >= 0) { if (spaceIndex >= 0) {
@ -686,6 +686,10 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
String actionToken = new String(buf, tokenBegin, nextSpace String actionToken = new String(buf, tokenBegin, nextSpace
- tokenBegin - 1); - tokenBegin - 1);
tokenBegin = nextSpace; tokenBegin = nextSpace;
if (actionToken.charAt(0) == '#') {
tokenCount = 3;
break;
}
Action action = Action.parse(actionToken); Action action = Action.parse(actionToken);
if (action != null) if (action != null)
current = new Step(Action.parse(actionToken)); current = new Step(Action.parse(actionToken));
@ -783,7 +787,11 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
static Action parse(String token) { static Action parse(String token) {
if (token.equals("pick") || token.equals("p")) if (token.equals("pick") || token.equals("p"))
return PICK; return PICK;
return null; throw new JGitInternalException(
MessageFormat
.format(
"Unknown or unsupported command \"{0}\", only \"pick\" is allowed",
token));
} }
} }

Loading…
Cancel
Save