summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Stocker <robin@nibor.org>2012-06-04 15:35:16 +0200
committerRobin Stocker <robin@nibor.org>2012-06-23 16:38:54 +0200
commit14ff22fd74e1720e9d8988c9d58653dd177f6fb6 (patch)
tree2380d7d4e66467ec62eb2b88dfb7a272cf63c886
parent3c29bf094111308da2cea79fc36af1eff2f4da7a (diff)
downloadjgit-14ff22fd74e1720e9d8988c9d58653dd177f6fb6.tar.gz
jgit-14ff22fd74e1720e9d8988c9d58653dd177f6fb6.zip
Ignore empty lines when parsing git-rebase-todo
When starting a rebase with C Git, there may be empty lines in the git-rebase-todo file. Before this change, JGit would fail to parse the file with e.g. the following exception: JGitInternalException: Unknown or unsupported command " #", only "pick" is allowed. This happened when there was an empty line just before the comments, because the nextSpace would be the one from the comment. Now the empty lines are ignored by checking for nextSpace < ptr outside of the loop. Change-Id: I94ad299f367c846e7729c74f49c6b8f93f75ae81 Signed-off-by: Robin Stocker <robin@nibor.org>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java27
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java5
2 files changed, 27 insertions, 5 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 cf2dead5a4..4a7a45e8f7 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
@@ -53,10 +53,12 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.util.List;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.RebaseCommand.Action;
import org.eclipse.jgit.api.RebaseCommand.Operation;
+import org.eclipse.jgit.api.RebaseCommand.Step;
import org.eclipse.jgit.api.RebaseResult.Status;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
@@ -1365,8 +1367,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
private int countPicks() throws IOException {
int count = 0;
- File todoFile = new File(db.getDirectory(),
- "rebase-merge/git-rebase-todo");
+ File todoFile = getTodoFile();
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(todoFile), "UTF-8"));
try {
@@ -1470,4 +1471,26 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, git.getRepository()
.getRepositoryState());
}
+
+ @Test
+ public void testRebaseShouldBeAbleToHandleEmptyLinesInRebaseTodoFile()
+ throws IOException {
+ String emptyLine = "\n";
+ String todo = "pick 1111111 Commit 1\n" + emptyLine
+ + "pick 2222222 Commit 2\n" + emptyLine
+ + "# Comment line at end\n";
+ write(getTodoFile(), todo);
+
+ RebaseCommand rebaseCommand = git.rebase();
+ List<Step> steps = rebaseCommand.loadSteps();
+ assertEquals(2, steps.size());
+ assertEquals("1111111", steps.get(0).commit.name());
+ assertEquals("2222222", steps.get(1).commit.name());
+ }
+
+ private File getTodoFile() {
+ File todoFile = new File(db.getDirectory(),
+ "rebase-merge/git-rebase-todo");
+ return todoFile;
+ }
}
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 645c9ff1fc..374db4c9ac 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
@@ -824,7 +824,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
return true;
}
- private List<Step> loadSteps() throws IOException {
+ List<Step> loadSteps() throws IOException {
byte[] buf = IO.readFully(new File(rebaseDir, GIT_REBASE_TODO));
int ptr = 0;
int tokenBegin = 0;
@@ -832,13 +832,12 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
while (ptr < buf.length) {
tokenBegin = ptr;
ptr = RawParseUtils.nextLF(buf, ptr);
- int nextSpace = 0;
+ int nextSpace = RawParseUtils.next(buf, tokenBegin, ' ');
int tokenCount = 0;
Step current = null;
while (tokenCount < 3 && nextSpace < ptr) {
switch (tokenCount) {
case 0:
- nextSpace = RawParseUtils.next(buf, tokenBegin, ' ');
String actionToken = new String(buf, tokenBegin, nextSpace
- tokenBegin - 1);
tokenBegin = nextSpace;