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>
This commit is contained in:
Mathias Kinzler 2010-12-10 09:44:51 +01:00
parent 93a7b2b24d
commit 9b039b42e0
2 changed files with 20 additions and 4 deletions

View File

@ -48,6 +48,7 @@
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 @@ private int countPicks() throws IOException {
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();
}

View File

@ -225,8 +225,6 @@ public RebaseResult call() throws NoHeadException, RefNotFoundException,
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 @@ private void popSteps(int numSteps) throws IOException {
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 @@ private List<Step> loadSteps() throws IOException {
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 String toToken() {
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));
}
}